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


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

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


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

示例1: addSourceComment

export function addSourceComment(
  node: StatementedNode,
  sourceFile: SourceFile,
  rootPath: string
): void {
  node.insertStatements(
    0,
    `// @url ${relative(rootPath, sourceFile.getFilePath())}\n\n`
  );
}
開發者ID:F001,項目名稱:deno,代碼行數:10,代碼來源:ast_util.ts

示例2: processSourceFile

  function processSourceFile(currentSourceFile: SourceFile) {
    if (sourceFiles.has(currentSourceFile)) {
      return;
    }
    sourceFiles.add(currentSourceFile);

    const currentSourceFilePath = currentSourceFile.getFilePath();
    if (customSources && currentSourceFilePath in customSources) {
      output += customSources[currentSourceFilePath];
      return;
    }

    currentSourceFile.getImportDeclarations().forEach(flattenDeclarations);
    currentSourceFile.getExportDeclarations().forEach(flattenDeclarations);

    rectifyNodes(currentSourceFile);

    output +=
      (debug ? getSourceComment(currentSourceFile, rootPath) : "") +
      currentSourceFile.print();
  }
開發者ID:F001,項目名稱:deno,代碼行數:21,代碼來源:ast_util.ts

示例3: extract

/** Extracts enums from a source file */
function extract(sourceFile: SourceFile, enumNames: string[]): string {
  // Copy specified enums from msg_generated
  let output = "";
  for (const enumName of enumNames) {
    const enumDeclaration = sourceFile.getEnumOrThrow(enumName);
    enumDeclaration.setHasDeclareKeyword(false);
    // we are not copying JSDocs or other trivia here because msg_generated only
    // contains some non-useful JSDocs and comments that are not ideal to copy
    // over
    output += enumDeclaration.getText();
  }
  return output;
}
開發者ID:F001,項目名稱:deno,代碼行數:14,代碼來源:build_library.ts

示例4: getExportedSymbols

/** Return a set of fully qualified symbol names for the files exports */
function getExportedSymbols(sourceFile: SourceFile): Set<string> {
  const exportedSymbols = new Set<string>();
  const exportDeclarations = sourceFile.getExportDeclarations();
  for (const exportDeclaration of exportDeclarations) {
    const exportSpecifiers = exportDeclaration.getNamedExports();
    for (const exportSpecifier of exportSpecifiers) {
      const aliasedSymbol = exportSpecifier
        .getSymbolOrThrow()
        .getAliasedSymbol();
      if (aliasedSymbol) {
        exportedSymbols.add(aliasedSymbol.getFullyQualifiedName());
      }
    }
  }
  return exportedSymbols;
}
開發者ID:F001,項目名稱:deno,代碼行數:17,代碼來源:ast_util.ts

示例5: rectifyNodes

 function rectifyNodes(currentSourceFile: SourceFile) {
   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,代碼行數:16,代碼來源:ast_util.ts

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

示例7: appendSourceFile

export function appendSourceFile(
  sourceFile: SourceFile,
  targetSourceFile: SourceFile
): void {
  targetSourceFile.addStatements(`\n${sourceFile.print()}`);
}
開發者ID:F001,項目名稱:deno,代碼行數:6,代碼來源:ast_util.ts

示例8: namespaceSourceFile

export function namespaceSourceFile(
  sourceFile: SourceFile,
  {
    debug,
    namespace,
    namespaces,
    rootPath,
    sourceFileMap
  }: NamespaceSourceFileOptions
): string {
  if (sourceFileMap.has(sourceFile)) {
    return "";
  }
  if (!namespace) {
    namespace = sourceFile.getBaseNameWithoutExtension();
  }
  sourceFileMap.set(sourceFile, namespace);

  sourceFile.forEachChild(node => {
    if (TypeGuards.isAmbientableNode(node)) {
      node.setHasDeclareKeyword(false);
    }
  });

  // TODO need to properly unwrap this
  const globalNamespace = sourceFile.getNamespace("global");
  let globalNamespaceText = "";
  if (globalNamespace) {
    const structure = globalNamespace.getStructure();
    if (structure.bodyText && typeof structure.bodyText === "string") {
      globalNamespaceText = structure.bodyText;
    } else {
      throw new TypeError("Unexpected global declaration structure.");
    }
  }
  if (globalNamespace) {
    globalNamespace.remove();
  }

  const output = sourceFile
    .getImportDeclarations()
    .filter(declaration => {
      const dsf = declaration.getModuleSpecifierSourceFile();
      if (dsf == null) {
        try {
          const namespaceName = declaration
            .getNamespaceImportOrThrow()
            .getText();
          if (!namespaces.has(namespaceName)) {
            throw createDeclarationError(
              "Already defined source file under different namespace.",
              declaration
            );
          }
        } catch (e) {
          throw createDeclarationError(
            "Unsupported import clause.",
            declaration
          );
        }
        declaration.remove();
      }
      return dsf;
    })
    .map(declaration => {
      if (
        declaration.getNamedImports().length ||
        !declaration.getNamespaceImport()
      ) {
        throw createDeclarationError("Unsupported import clause.", declaration);
      }
      const text = namespaceSourceFile(
        declaration.getModuleSpecifierSourceFileOrThrow(),
        {
          debug,
          namespace: declaration.getNamespaceImportOrThrow().getText(),
          namespaces,
          rootPath,
          sourceFileMap
        }
      );
      declaration.remove();
      return text;
    })
    .join("\n");
  sourceFile
    .getExportDeclarations()
    .forEach(declaration => declaration.remove());

  namespaces.add(namespace);

  return `${output}
    ${globalNamespaceText || ""}

    declare namespace ${namespace} {
      ${debug ? getSourceComment(sourceFile, rootPath) : ""}
      ${sourceFile.getText()}
    }`;
}
開發者ID:F001,項目名稱:deno,代碼行數:99,代碼來源:ast_util.ts

示例9: getSourceComment

export function getSourceComment(
  sourceFile: SourceFile,
  rootPath: string
): string {
  return `\n// @url ${relative(rootPath, sourceFile.getFilePath())}\n\n`;
}
開發者ID:F001,項目名稱:deno,代碼行數:6,代碼來源:ast_util.ts


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