MCPcopy Create free account
hub / github.com/microsoft/typescript-go / bindModuleDeclaration

Method bindModuleDeclaration

internal/binder/binder.go:776–816  ·  view source on GitHub ↗
(node *ast.Node)

Source from the content-addressed store, hash-verified

774}
775
776func (b *Binder) bindModuleDeclaration(node *ast.Node) {
777 b.setExportContextFlag(node)
778 if ast.IsAmbientModule(node) {
779 if ast.HasSyntacticModifier(node, ast.ModifierFlagsExport) {
780 b.errorOnFirstToken(node, diagnostics.X_export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible)
781 }
782 if ast.IsModuleAugmentationExternal(node) {
783 b.declareModuleSymbol(node)
784 } else {
785 name := node.AsModuleDeclaration().Name()
786 symbol := b.declareSymbolAndAddToSymbolTable(node, ast.SymbolFlagsValueModule, ast.SymbolFlagsValueModuleExcludes)
787
788 if ast.IsStringLiteral(name) {
789 pattern := core.TryParsePattern(name.Text())
790 if !pattern.IsValid() {
791 // An invalid pattern - must have multiple wildcards.
792 b.errorOnFirstToken(name, diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character, name.Text())
793 } else if pattern.StarIndex >= 0 {
794 b.file.PatternAmbientModules = append(b.file.PatternAmbientModules, &ast.PatternAmbientModule{Pattern: pattern, Symbol: symbol})
795 }
796 }
797 }
798 } else {
799 state := b.declareModuleSymbol(node)
800 if state != ast.ModuleInstanceStateNonInstantiated {
801 symbol := node.Symbol()
802 // if module was already merged with some function, class or non-const enum, treat it as non-const-enum-only
803 constEnumOnlyModule := (symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsClass|ast.SymbolFlagsRegularEnum) == 0) &&
804 // Current must be `const enum` only
805 state == ast.ModuleInstanceStateConstEnumOnly &&
806 // Can't have been set to 'false' in a previous merged symbol. ('undefined' OK)
807 !b.notConstEnumOnlyModules.Has(symbol)
808 if constEnumOnlyModule {
809 symbol.Flags |= ast.SymbolFlagsConstEnumOnlyModule
810 } else {
811 symbol.Flags &^= ast.SymbolFlagsConstEnumOnlyModule
812 b.notConstEnumOnlyModules.Add(symbol)
813 }
814 }
815 }
816}
817
818func (b *Binder) declareModuleSymbol(node *ast.Node) ast.ModuleInstanceState {
819 state := ast.GetModuleInstanceState(node)

Callers 1

bindMethod · 0.95

Calls 15

setExportContextFlagMethod · 0.95
errorOnFirstTokenMethod · 0.95
declareModuleSymbolMethod · 0.95
IsAmbientModuleFunction · 0.92
HasSyntacticModifierFunction · 0.92
IsStringLiteralFunction · 0.92
TryParsePatternFunction · 0.92
AsModuleDeclarationMethod · 0.80
NameMethod · 0.65
TextMethod · 0.65

Tested by

no test coverage detected