當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。