(moduleName *ast.Node)
| 1395 | } |
| 1396 | |
| 1397 | func (c *Checker) mergeModuleAugmentation(moduleName *ast.Node) { |
| 1398 | moduleNode := moduleName.Parent |
| 1399 | moduleAugmentation := moduleNode.AsModuleDeclaration() |
| 1400 | if moduleAugmentation.Symbol.Declarations[0] != moduleNode { |
| 1401 | // this is a combined symbol for multiple augmentations within the same file. |
| 1402 | // its symbol already has accumulated information for all declarations |
| 1403 | // so we need to add it just once - do the work only for first declaration |
| 1404 | return |
| 1405 | } |
| 1406 | if ast.IsGlobalScopeAugmentation(moduleNode) { |
| 1407 | c.mergeSymbolTable(c.globals, moduleAugmentation.Symbol.Exports, false /*unidirectional*/, nil /*parent*/) |
| 1408 | } else { |
| 1409 | // find a module that about to be augmented |
| 1410 | // do not validate names of augmentations that are defined in ambient context |
| 1411 | var moduleNotFoundError *diagnostics.Message |
| 1412 | if moduleName.Parent.Parent.Flags&ast.NodeFlagsAmbient == 0 { |
| 1413 | moduleNotFoundError = diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found |
| 1414 | } |
| 1415 | mainModule := c.resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError /*ignoreErrors*/, false /*isForAugmentation*/, true) |
| 1416 | if mainModule == nil { |
| 1417 | return |
| 1418 | } |
| 1419 | // obtain item referenced by 'export=' |
| 1420 | mainModule = c.resolveExternalModuleSymbol(mainModule, false /*dontResolveAlias*/) |
| 1421 | if mainModule.Flags&ast.SymbolFlagsNamespace != 0 { |
| 1422 | // If we're merging an augmentation to a pattern ambient module, we want to |
| 1423 | // perform the merge unidirectionally from the augmentation ('a.foo') to |
| 1424 | // the pattern ('*.foo'), so that 'getMergedSymbol()' on a.foo gives you |
| 1425 | // all the exports both from the pattern and from the augmentation, but |
| 1426 | // 'getMergedSymbol()' on *.foo only gives you exports from *.foo. |
| 1427 | if core.Some(c.patternAmbientModules, func(module *ast.PatternAmbientModule) bool { |
| 1428 | return mainModule == module.Symbol |
| 1429 | }) { |
| 1430 | merged := c.mergeSymbol(moduleAugmentation.Symbol, mainModule, true /*unidirectional*/) |
| 1431 | // moduleName will be a StringLiteral since this is not `declare global`. |
| 1432 | ast.GetSymbolTable(&c.patternAmbientModuleAugmentations)[moduleName.Text()] = merged |
| 1433 | } else { |
| 1434 | if mainModule.Exports[ast.InternalSymbolNameExportStar] != nil && len(moduleAugmentation.Symbol.Exports) != 0 { |
| 1435 | // We may need to merge the module augmentation's exports into the target symbols of the resolved exports |
| 1436 | resolvedExports := c.getResolvedMembersOrExportsOfSymbol(mainModule, MembersOrExportsResolutionKindResolvedExports) |
| 1437 | for key, value := range moduleAugmentation.Symbol.Exports { |
| 1438 | if resolvedExports[key] != nil && mainModule.Exports[key] == nil { |
| 1439 | c.mergeSymbol(resolvedExports[key], value, false /*unidirectional*/) |
| 1440 | } |
| 1441 | } |
| 1442 | } |
| 1443 | c.mergeSymbol(mainModule, moduleAugmentation.Symbol, false /*unidirectional*/) |
| 1444 | } |
| 1445 | } else { |
| 1446 | // moduleName will be a StringLiteral since this is not `declare global`. |
| 1447 | c.error(moduleName, diagnostics.Cannot_augment_module_0_because_it_resolves_to_a_non_module_entity, moduleName.Text()) |
| 1448 | } |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | func (c *Checker) addUndefinedToGlobalsOrErrorOnRedeclaration() { |
| 1453 | name := c.undefinedSymbol.Name |
no test coverage detected