MCPcopy Index your code
hub / github.com/nodejs/node / collectModuleReferences

Function collectModuleReferences

test/fixtures/snapshot/typescript.js:118006–118052  ·  view source on GitHub ↗
(node, inAmbientModule)

Source from the content-addressed store, hash-verified

118004 file.ambientModuleNames = ambientModules || ts.emptyArray;
118005 return;
118006 function collectModuleReferences(node, inAmbientModule) {
118007 if (ts.isAnyImportOrReExport(node)) {
118008 var moduleNameExpr = ts.getExternalModuleName(node);
118009 // TypeScript 1.0 spec (April 2014): 12.1.6
118010 // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference other external modules
118011 // only through top - level external module names. Relative external module names are not permitted.
118012 if (moduleNameExpr && ts.isStringLiteral(moduleNameExpr) && moduleNameExpr.text && (!inAmbientModule || !ts.isExternalModuleNameRelative(moduleNameExpr.text))) {
118013 ts.setParentRecursive(node, /*incremental*/ false); // we need parent data on imports before the program is fully bound, so we ensure it's set here
118014 imports = ts.append(imports, moduleNameExpr);
118015 if (!usesUriStyleNodeCoreModules && currentNodeModulesDepth === 0 && !file.isDeclarationFile) {
118016 usesUriStyleNodeCoreModules = ts.startsWith(moduleNameExpr.text, "node:");
118017 }
118018 }
118019 }
118020 else if (ts.isModuleDeclaration(node)) {
118021 if (ts.isAmbientModule(node) && (inAmbientModule || ts.hasSyntacticModifier(node, 2 /* ModifierFlags.Ambient */) || file.isDeclarationFile)) {
118022 node.name.parent = node;
118023 var nameText = ts.getTextOfIdentifierOrLiteral(node.name);
118024 // Ambient module declarations can be interpreted as augmentations for some existing external modules.
118025 // This will happen in two cases:
118026 // - if current file is external module then module augmentation is a ambient module declaration defined in the top level scope
118027 // - if current file is not external module then module augmentation is an ambient module declaration with non-relative module name
118028 // immediately nested in top level ambient module declaration .
118029 if (isExternalModuleFile || (inAmbientModule && !ts.isExternalModuleNameRelative(nameText))) {
118030 (moduleAugmentations || (moduleAugmentations = [])).push(node.name);
118031 }
118032 else if (!inAmbientModule) {
118033 if (file.isDeclarationFile) {
118034 // for global .d.ts files record name of ambient module
118035 (ambientModules || (ambientModules = [])).push(nameText);
118036 }
118037 // An AmbientExternalModuleDeclaration declares an external module.
118038 // This type of declaration is permitted only in the global module.
118039 // The StringLiteral must specify a top - level external module name.
118040 // Relative external module names are not permitted
118041 // NOTE: body of ambient module is always a module block, if it exists
118042 var body = node.body;
118043 if (body) {
118044 for (var _i = 0, _a = body.statements; _i < _a.length; _i++) {
118045 var statement = _a[_i];
118046 collectModuleReferences(statement, /*inAmbientModule*/ true);
118047 }
118048 }
118049 }
118050 }
118051 }
118052 }
118053 function collectDynamicImportOrRequireCalls(file) {
118054 var r = /import|require/g;
118055 while (r.exec(file.text) !== null) { // eslint-disable-line no-null/no-null

Callers 1

Calls 2

appendMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…