本文整理匯總了TypeScript中ts-simple-ast.Node.getKindName方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Node.getKindName方法的具體用法?TypeScript Node.getKindName怎麽用?TypeScript Node.getKindName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ts-simple-ast.Node
的用法示例。
在下文中一共展示了Node.getKindName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: filterNonJsxRelatedNodes
function filterNonJsxRelatedNodes(n: Node) {
// this is faster - we just dont want syntax list since they pollute a lot the JSX.
return n.getKindName() !== 'SyntaxList'
// But these are other more elegant ways:
// // only pass those with ancestors or with first-level children which are JSX :
// if (n.getKindName()!.toLowerCase().includes('jsx')) {
// return true
// }
// else if(n.getFirstAncestor(a=>a.getKindName()!.toLowerCase().includes('jsx'))){
// return true
// }
// else {
// return n.getFirstChild(a=>a.getKindName()!.toLowerCase().includes('jsx')))
// }
}
示例2: 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
}