當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ts-simple-ast.TypeGuards類代碼示例

本文整理匯總了TypeScript中ts-simple-ast.TypeGuards的典型用法代碼示例。如果您正苦於以下問題:TypeScript TypeGuards類的具體用法?TypeScript TypeGuards怎麽用?TypeScript TypeGuards使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TypeGuards類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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:

 currentSourceFile.forEachChild(node => {
   if (TypeGuards.isAmbientableNode(node)) {
     node.setHasDeclareKeyword(false);
   }
   if (TypeGuards.isExportableNode(node)) {
     const nodeSymbol = node.getSymbol();
     if (
       nodeSymbol &&
       !exportedSymbols.has(nodeSymbol.getFullyQualifiedName())
     ) {
       node.setIsExported(false);
     }
   }
 });
開發者ID:F001,項目名稱:deno,代碼行數:14,代碼來源:ast_util.ts

示例3: 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

示例4:

 sourceFile.forEachChild(node => {
   if (TypeGuards.isExpressionStatement(node)) {
     const firstChild = node.getFirstChild();
     if (!firstChild) {
       return;
     }
     if (TypeGuards.isBinaryExpression(firstChild)) {
       const leftExpression = firstChild.getLeft();
       if (
         TypeGuards.isPropertyAccessExpression(leftExpression) &&
         leftExpression.getExpression().getText() === globalVarName
       ) {
         const globalVarProperty = leftExpression.getName();
         if (globalVarProperty !== globalVarName) {
           globalVariables.set(globalVarProperty, {
             type: firstChild.getType(),
             node
           });
         }
       }
     }
   }
 });
開發者ID:F001,項目名稱:deno,代碼行數:23,代碼來源:build_library.ts

示例5: createDeclarationFile

export function createDeclarationFile(project: Project) {
    const globalFile = project.addExistingSourceFile("../../shared/lib/global.d.ts");
    const declarationFile = project.createSourceFile("ts-nameof.macro.d.ts", "", { overwrite: true });
    const namespaceDec = declarationFile.addNamespace({
        name: `"ts-nameof.macro"`,
        declarationKind: NamespaceDeclarationKind.Module,
        hasDeclareKeyword: true
    });

    namespaceDec.setBodyText(globalFile.getFullText());

    for (const statement of namespaceDec.getStatements()) {
        if (TypeGuards.isAmbientableNode(statement))
            statement.setHasDeclareKeyword(false);
    }

    namespaceDec.addExportAssignment({
        expression: "nameof",
        isExportEquals: false
    });
}
開發者ID:dsherret,項目名稱:ts-nameof,代碼行數:21,代碼來源:createDeclarationFile.ts


注:本文中的ts-simple-ast.TypeGuards類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。