本文整理汇总了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
}