本文整理匯總了TypeScript中ts-simple-ast.Node.getStart方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Node.getStart方法的具體用法?TypeScript Node.getStart怎麽用?TypeScript Node.getStart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ts-simple-ast.Node
的用法示例。
在下文中一共展示了Node.getStart方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: buildJsxAstNode
function buildJsxAstNode(n: tsNode, config: CodeWorkerRequestJsxAst): CodeWorkerResponseJsxAsNode {
let text = n.getText().trim()
const children = config.mode === 'forEachChild' ? getChildrenForEachChild(n) : n.getChildren()
text = text.substring(0, Math.max(config.nodeTextLength || 20, text.length))
const type = tryTo(() => n.getType().getApparentType().getText() || n.getType().getText()) || 'TODO'
const node: CodeWorkerResponseJsxAsNode = {
kind: n.getKindName(),
type,
text,
start: n.getStart(),
end: n.getEnd(),
startColumn: ts.getLineAndCharacterOfPosition(n.getSourceFile().compilerNode, n.compilerNode.getStart()).character + 1,
startLineNumber: ts.getLineAndCharacterOfPosition(n.getSourceFile().compilerNode, n.compilerNode.getStart()).line + 1,
endColumn: ts.getLineAndCharacterOfPosition(n.getSourceFile().compilerNode, n.compilerNode.getEnd()).character + 1,
endLineNumber: ts.getLineAndCharacterOfPosition(n.getSourceFile().compilerNode, n.compilerNode.getEnd()).line + 1,
children: children.map(c => buildJsxAstNode(c, config))
}
return node
}
示例2: getParentRanges
function getParentRanges(node: Node) {
const ranges = []
const [start, end] = [node.getStart(), node.getEnd()]
let lastEnd = start
node.forEachChild(child => {
const [start, end] = [child.getStart(), child.getEnd()]
ranges.push({
start: lastEnd,
end: start
})
lastEnd = end
})
if (lastEnd !== end) {
ranges.push({
start: lastEnd,
end
})
}
return ranges
}