Skip to content

Fix emit for non-local/merged enum/namespace references#2846

Open
jakebailey wants to merge 2 commits intomainfrom
jabaile/fix-namespace-and-enums
Open

Fix emit for non-local/merged enum/namespace references#2846
jakebailey wants to merge 2 commits intomainfrom
jabaile/fix-namespace-and-enums

Conversation

@jakebailey
Copy link
Member

Fixes #961

Thankfully this was simple.

Copilot AI review requested due to automatic review settings February 19, 2026 23:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect JS emit where unqualified references to enum/namespace members inside merged enum/namespace declarations were not being runtime-qualified (e.g., emitting Afunc() instead of game.Afunc()), aligning tsgo output with tsc and resolving #961.

Changes:

  • Update export-container resolution for identifiers so merged enum/namespace member references are correctly qualified during emit.
  • Add new compiler test cases covering merged enum and merged namespace member references.
  • Refresh multiple submodule baseline outputs/diffs to reflect corrected qualification behavior.

Reviewed changes

Copilot reviewed 82 out of 83 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/transformers/tstransforms/runtimesyntax.go Always qualifies enum/namespace member identifiers when a referenced export-container is found (no longer gated on container.Contains(location)).
internal/binder/referenceresolver.go Adjusts GetReferencedExportContainer to prefer the container associated with the reference site (ancestor of node.Parent) rather than the symbol’s value-declaration container, fixing merged-declaration qualification.
internal/transformers/tstransforms/runtimesyntax_test.go Updates expected outputs to reflect correct qualification for merged enum/namespace reference cases.
testdata/tests/cases/compiler/mergedNamespaceDeclarationMemberReferences.ts New compiler test: unqualified references across merged namespace declarations should emit qualified runtime references.
testdata/tests/cases/compiler/mergedEnumDeclarationMemberReferences.ts New compiler test: unqualified references across merged enum declarations should emit qualified runtime references.
testdata/baselines/reference/compiler/mergedNamespaceDeclarationMemberReferences.js New baseline JS output for merged-namespace test (expects N.x, N.fn, N.A, etc.).
testdata/baselines/reference/compiler/mergedNamespaceDeclarationMemberReferences.symbols New baseline symbols output for merged-namespace test.
testdata/baselines/reference/compiler/mergedNamespaceDeclarationMemberReferences.types New baseline types output for merged-namespace test.
testdata/baselines/reference/compiler/mergedEnumDeclarationMemberReferences.js New baseline JS output for merged-enum test (expects E.A, E.B + 1, etc.).
testdata/baselines/reference/compiler/mergedEnumDeclarationMemberReferences.symbols New baseline symbols output for merged-enum test.
testdata/baselines/reference/compiler/mergedEnumDeclarationMemberReferences.types New baseline types output for merged-enum test.
testdata/baselines/reference/submodule/conformance/tsxEmit3.js Baseline updated to reflect corrected qualification for merged namespace references in TSX emit scenario.
testdata/baselines/reference/submodule/conformance/tsxEmit3.js.diff Diff baseline removed/updated due to convergence with expected output after qualification fix.
testdata/baselines/reference/submodule/conformance/tsxEmit3.js.map Baseline sourcemap updated to reflect changed emitted identifiers/qualification.
testdata/baselines/reference/submodule/conformance/tsxEmit3.js.map.diff Diff baseline updated due to new sourcemap mapping after corrected qualification.
testdata/baselines/reference/submodule/conformance/tsxEmit3.sourcemap.txt Baseline sourcemap text updated to reflect corrected qualification.
testdata/baselines/reference/submodule/conformance/tsxEmit3.sourcemap.txt.diff Diff baseline updated due to sourcemap text changes after qualification fix.
testdata/baselines/reference/submodule/conformance/objectLiteralShorthandPropertiesWithModule.js Baseline updated to keep module qualification (e.g., m.x) where required.
testdata/baselines/reference/submodule/conformance/objectLiteralShorthandPropertiesWithModule.js.diff Diff baseline removed/updated due to convergence after qualification fix.
testdata/baselines/reference/submodule/conformance/objectLiteralShorthandPropertiesWithModuleES6.js Baseline updated to keep module qualification (e.g., m.x) where required.
testdata/baselines/reference/submodule/conformance/objectLiteralShorthandPropertiesWithModuleES6.js.diff Diff baseline removed/updated due to convergence after qualification fix.
testdata/baselines/reference/submodule/conformance/enumExportMergingES6.js Baseline updated to qualify merged enum references (Animals.Cat, Animals.Dog).
testdata/baselines/reference/submodule/conformance/enumExportMergingES6.js.diff Diff baseline updated due to corrected enum member qualification.
testdata/baselines/reference/submodule/compiler/recursiveMods.js Baseline updated to qualify namespace/class reference (new Foo.C()).
testdata/baselines/reference/submodule/compiler/recursiveMods.js.diff Diff baseline removed/updated due to convergence after qualification fix.
testdata/baselines/reference/submodule/compiler/qualify.js Baseline updated to qualify namespace/module references (M.m, N.n).
testdata/baselines/reference/submodule/compiler/qualify.js.diff Diff baseline removed/updated due to convergence after qualification fix.
testdata/baselines/reference/submodule/compiler/nameCollisionWithBlockScopedVariable1.js Baseline updated to preserve correct qualified reference (new M_1.C()).
testdata/baselines/reference/submodule/compiler/nameCollisionWithBlockScopedVariable1.js.diff Diff baseline removed/updated due to convergence after qualification fix.
testdata/baselines/reference/submodule/compiler/multipleExports.js Baseline updated to qualify merged module export reference (M.v).
testdata/baselines/reference/submodule/compiler/multipleExports.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/moduleVisibilityTest1.js Baseline updated to qualify module member reference (M.c = M.x).
testdata/baselines/reference/submodule/compiler/moduleVisibilityTest1.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/moduleVariables.js Baseline updated to qualify module member reference (console.log(M.x)).
testdata/baselines/reference/submodule/compiler/moduleVariables.js.diff Diff baseline removed/updated due to convergence after qualification fix.
testdata/baselines/reference/submodule/compiler/moduleMemberWithoutTypeAnnotation1.js Baseline updated to qualify namespace members (TypeScript.Syntax.childIndex, TypeScript.PositionedToken).
testdata/baselines/reference/submodule/compiler/moduleMemberWithoutTypeAnnotation1.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationWithSharedExportedVar.js Baseline updated to qualify shared merged-module var reference (M.v).
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationWithSharedExportedVar.js.diff Diff baseline removed/updated due to convergence after qualification fix.
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationCodeGen5.js Baseline updated to qualify merged module references (plop_1.doom, plop_1.M).
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationCodeGen5.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationCodeGen4.js Baseline updated to qualify merged module reference (data_1.foo()).
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationCodeGen4.js.diff Diff baseline removed/updated due to convergence after qualification fix.
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationCodeGen3.js Baseline updated to qualify merged module reference (data_1.buz()).
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationCodeGen3.js.diff Diff baseline removed/updated due to convergence after qualification fix.
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationCodeGen2.js Baseline updated to qualify merged module reference (data_1.foo.buz()).
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationCodeGen2.js.diff Diff baseline removed/updated due to convergence after qualification fix.
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationCodeGen.js Baseline updated to qualify merged module reference (new Y_1.B()).
testdata/baselines/reference/submodule/compiler/mergedModuleDeclarationCodeGen.js.diff Diff baseline removed/updated due to convergence after qualification fix.
testdata/baselines/reference/submodule/compiler/mergedEnumDeclarationCodeGen.js Baseline updated to qualify merged enum member reference (E.a).
testdata/baselines/reference/submodule/compiler/mergedEnumDeclarationCodeGen.js.diff Diff baseline updated due to corrected enum member qualification.
testdata/baselines/reference/submodule/compiler/mergedDeclarations2.js Baseline updated to qualify merged enum reference (Foo.b).
testdata/baselines/reference/submodule/compiler/mergedDeclarations2.js.diff Diff baseline updated due to corrected merged-enum qualification.
testdata/baselines/reference/submodule/compiler/isolatedModulesGlobalNamespacesAndEnums.js Baseline updated to qualify enum member references (Enum.A, Enum.X).
testdata/baselines/reference/submodule/compiler/isolatedModulesGlobalNamespacesAndEnums.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/genericRecursiveImplicitConstructorErrors3.js Baseline updated to qualify namespace access (TypeScript.MemberName.create).
testdata/baselines/reference/submodule/compiler/genericRecursiveImplicitConstructorErrors3.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/genericConstraintOnExtendedBuiltinTypes.js Baseline updated to qualify base class (Tweening.Tween).
testdata/baselines/reference/submodule/compiler/genericConstraintOnExtendedBuiltinTypes.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/genericConstraintOnExtendedBuiltinTypes2.js Baseline updated to qualify base class (Tweening.Tween).
testdata/baselines/reference/submodule/compiler/genericConstraintOnExtendedBuiltinTypes2.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/functionMergedWithModule.js Baseline updated to qualify function/module merged reference (foo.Bar.f()).
testdata/baselines/reference/submodule/compiler/functionMergedWithModule.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/extBaseClass1.js Baseline updated to qualify base class reference (M.B).
testdata/baselines/reference/submodule/compiler/extBaseClass1.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/duplicateIdentifiersAcrossContainerBoundaries.js Baseline updated to qualify merged container reference (M.v = 3).
testdata/baselines/reference/submodule/compiler/duplicateIdentifiersAcrossContainerBoundaries.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/dottedModuleName.js Baseline updated to qualify dotted module references (f(Z.v), N.f(10)).
testdata/baselines/reference/submodule/compiler/dottedModuleName.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/declFileWithExtendsClauseThatHasItsContainerNameConflict.js Baseline updated to qualify base class (B.EventManager).
testdata/baselines/reference/submodule/compiler/declFileWithExtendsClauseThatHasItsContainerNameConflict.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithModuleReopening.js Baseline updated to preserve correct qualified references (new m1.m1(), m2_1.b10, new m2_1.c1()).
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithModuleReopening.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithModuleChildren.js Baseline updated to preserve correct qualified references (M_2.x, M_3.x, M.x, M_4.x).
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithModuleChildren.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithMethodChildren.js Baseline updated to preserve correct qualified references (M_2.x, M_3.x).
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithMethodChildren.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithFunctionChildren.js Baseline updated to preserve correct qualified references (M_2.x, M_3.x).
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithFunctionChildren.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithConstructorChildren.js Baseline updated to preserve correct qualified defaults/refs (p = M_2.x, var p = M_3.x).
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithConstructorChildren.js.diff Diff baseline updated due to corrected qualification behavior.
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithAccessorChildren.js Baseline updated to preserve correct qualified refs in accessors (M_2.x, M.x, M_3.x).
testdata/baselines/reference/submodule/compiler/collisionCodeGenModuleWithAccessorChildren.js.diff Diff baseline updated due to corrected qualification behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsgo fails to resolve namespace symbols in non-extends contexts across files

1 participant

Comments