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

Function mergeModuleAugmentation

test/fixtures/snapshot/typescript.js:49272–49330  ·  view source on GitHub ↗
(moduleName)

Source from the content-addressed store, hash-verified

49270 });
49271 }
49272 function mergeModuleAugmentation(moduleName) {
49273 var _a, _b, _c;
49274 var moduleAugmentation = moduleName.parent;
49275 if (((_a = moduleAugmentation.symbol.declarations) === null || _a === void 0 ? void 0 : _a[0]) !== moduleAugmentation) {
49276 // this is a combined symbol for multiple augmentations within the same file.
49277 // its symbol already has accumulated information for all declarations
49278 // so we need to add it just once - do the work only for first declaration
49279 ts.Debug.assert(moduleAugmentation.symbol.declarations.length > 1);
49280 return;
49281 }
49282 if (ts.isGlobalScopeAugmentation(moduleAugmentation)) {
49283 mergeSymbolTable(globals, moduleAugmentation.symbol.exports);
49284 }
49285 else {
49286 // find a module that about to be augmented
49287 // do not validate names of augmentations that are defined in ambient context
49288 var moduleNotFoundError = !(moduleName.parent.parent.flags & 16777216 /* NodeFlags.Ambient */)
49289 ? ts.Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found
49290 : undefined;
49291 var mainModule_1 = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError, /*isForAugmentation*/ true);
49292 if (!mainModule_1) {
49293 return;
49294 }
49295 // obtain item referenced by 'export='
49296 mainModule_1 = resolveExternalModuleSymbol(mainModule_1);
49297 if (mainModule_1.flags & 1920 /* SymbolFlags.Namespace */) {
49298 // If we're merging an augmentation to a pattern ambient module, we want to
49299 // perform the merge unidirectionally from the augmentation ('a.foo') to
49300 // the pattern ('*.foo'), so that 'getMergedSymbol()' on a.foo gives you
49301 // all the exports both from the pattern and from the augmentation, but
49302 // 'getMergedSymbol()' on *.foo only gives you exports from *.foo.
49303 if (ts.some(patternAmbientModules, function (module) { return mainModule_1 === module.symbol; })) {
49304 var merged = mergeSymbol(moduleAugmentation.symbol, mainModule_1, /*unidirectional*/ true);
49305 if (!patternAmbientModuleAugmentations) {
49306 patternAmbientModuleAugmentations = new ts.Map();
49307 }
49308 // moduleName will be a StringLiteral since this is not `declare global`.
49309 patternAmbientModuleAugmentations.set(moduleName.text, merged);
49310 }
49311 else {
49312 if (((_b = mainModule_1.exports) === null || _b === void 0 ? void 0 : _b.get("__export" /* InternalSymbolName.ExportStar */)) && ((_c = moduleAugmentation.symbol.exports) === null || _c === void 0 ? void 0 : _c.size)) {
49313 // We may need to merge the module augmentation's exports into the target symbols of the resolved exports
49314 var resolvedExports = getResolvedMembersOrExportsOfSymbol(mainModule_1, "resolvedExports" /* MembersOrExportsResolutionKind.resolvedExports */);
49315 for (var _i = 0, _d = ts.arrayFrom(moduleAugmentation.symbol.exports.entries()); _i < _d.length; _i++) {
49316 var _e = _d[_i], key = _e[0], value = _e[1];
49317 if (resolvedExports.has(key) && !mainModule_1.exports.has(key)) {
49318 mergeSymbol(resolvedExports.get(key), value);
49319 }
49320 }
49321 }
49322 mergeSymbol(mainModule_1, moduleAugmentation.symbol);
49323 }
49324 }
49325 else {
49326 // moduleName will be a StringLiteral since this is not `declare global`.
49327 error(moduleName, ts.Diagnostics.Cannot_augment_module_0_because_it_resolves_to_a_non_module_entity, moduleName.text);
49328 }
49329 }

Callers 1

initializeTypeCheckerFunction · 0.85

Calls 12

mergeSymbolTableFunction · 0.85
mergeSymbolFunction · 0.85
assertMethod · 0.80
someMethod · 0.80
errorFunction · 0.70
getMethod · 0.65
hasMethod · 0.65
setMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…