当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ts-simple-ast.Node类代码示例

本文整理汇总了TypeScript中ts-simple-ast.Node的典型用法代码示例。如果您正苦于以下问题:TypeScript Node类的具体用法?TypeScript Node怎么用?TypeScript Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Node类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getExtra

function getExtra(node: Node) {
  const extras = []
  if (TypeGuards.isJsxTagNamedNode(node)) {
    extras.push(node.getTagNameNode().getText().match(/^[a-z]/) ? 'JSXIntrinsicElement' : 'JSXNonIntrinsicElement')
  }
  const parent = node.getParent()
  if (parent && TypeGuards.isJsxTagNamedNode(parent)) {
    extras.push(parent.getTagNameNode().getText().match(/^[a-z]/) ? 'JSXIntrinsicElementChild' : 'JSXNonIntrinsicElementChild')
  }
  return extras.length ? extras : undefined
}
开发者ID:cancerberoSgx,项目名称:javascript-sample-projects,代码行数:11,代码来源:extractCodeDecorations.ts

示例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
}
开发者ID:cancerberoSgx,项目名称:javascript-sample-projects,代码行数:20,代码来源:extractCodeDecorations.ts

示例3: 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
}
开发者ID:cancerberoSgx,项目名称:javascript-sample-projects,代码行数:19,代码来源:jsxAstCompilation.ts

示例4: 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')))
  // }

}
开发者ID:cancerberoSgx,项目名称:javascript-sample-projects,代码行数:18,代码来源:extractCodeDecorations.ts

示例5: addChildNodes

function addChildNodes(node: Node, classifications: Classification[], sourceFile: SourceFile, project: Project) {
  const lines = sourceFile.getFullText().split('\n').map(line => line.length)
  node.getDescendants()
    .filter(filterNonJsxRelatedNodes)
    .forEach(node => {
      const parent = node.getParent()
      const parentKind = parent && parent.getKindName()
      // const type = tryTo(() => buildParentShipKind({ node: node, project })[0]) || undefined
      const kind = node.getKindName()
      const extra = getExtra(node)
      getNodeRangesForMonaco(node, lines).forEach(r => {
        classifications.push(
          {
            ...r,
            kind,
            parentKind,
            // type,
            extra,
          }
        )
      })
    })
}
开发者ID:cancerberoSgx,项目名称:javascript-sample-projects,代码行数:23,代码来源:extractCodeDecorations.ts

示例6: getChildrenForEachChild

export function getChildrenForEachChild(n: Node): Node[] {
  const result: Node[] = []
  n.forEachChild(n => result.push(n))
  return result
}
开发者ID:cancerberoSgx,项目名称:javascript-sample-projects,代码行数:5,代码来源:ts-simple-ast.ts

示例7: getLineNumberAndOffset

 .map(({ start, end }) => {
   const { offset, line: startLineNumber } = getLineNumberAndOffset(start, lines, node)
   const { line: endLineNumber } = getLineNumberAndOffset(end, lines, node)
   return {
     startLineNumber,
     // Heads up : following sum fixes an error of original implementation when JSXText has multiple lines:
     endLineNumber: endLineNumber + (TypeGuards.isJsxText(node) && node.getText().includes('\n') ? -1 : 0),
     startColumn: start + 1 - offset,
     endColumn: end + 1 - offset,
   }
 })
开发者ID:cancerberoSgx,项目名称:javascript-sample-projects,代码行数:11,代码来源:extractCodeDecorations.ts

示例8: tryTo

 const type = tryTo(() => n.getType().getApparentType().getText() || n.getType().getText()) || 'TODO'
开发者ID:cancerberoSgx,项目名称:javascript-sample-projects,代码行数:1,代码来源:jsxAstCompilation.ts


注:本文中的ts-simple-ast.Node类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。