fix(semantic): import-equals declares an import_binding symbol (#64) - #66
Merged
Conversation
The `import X = require(...)` / `import X = Y.Z` branch in parseImportDeclaration advanced past the binding name without creating a node or declaring it — unlike `import * as X` and default imports — so `X` had no symbol. References to `X` then fell through to a name-keyed fallback and collided with same-named classes/locals (e.g. `class C` and `import C = …` both resolving to `typeof C`). Capture the binding token, create its identifier node, and `emitDeclare(.import_binding, local_node)`, mirroring the namespace/default paths. `import_decl` already uses lhs as the import-equals discriminator (.none) and rhs as the module reference, so the binding has no data slot — anchor it under the declaration via parent_fixups so it is reachable in the parent tree (previously it rendered as `<no-node>`). Validated: full suite green; TS conformance 17910/17913 · 1210/1223; test262 3966/3966 · 1389/1389; semantic sweep 0 crashes, +1215 import_binding symbols and no other structural change (scopes/refs/diagnostics unchanged).
…ds; strengthen tests Per review: emit the binding declare AFTER the TS1141/reserved-word guards (not before) so a rejected `import X = require(nonLiteral)` leaves no orphaned phantom symbol on the error path. Tests: tighten ref counts to exact (== 1), add the deep-qualified `import X = Y.Z.W` case, a negative control that the module reference's own identifiers (`Y`/`Z`) are not declared as bindings, and assert exactly one identifier child is anchored to the declaration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #64.
Problem
The
import X = require("./m")/import X = Y.Z(TSImportEqualsDeclaration) branch advanced past the binding name without creating a node or declaring it — unlikeimport * as Xand default imports, which bothemitDeclare(.import_binding, …). SoXhad no symbol:symbolForIdentRef(X)returned null → references fell through to a name-keyed fallback and collided with same-named classes/locals (class C+import C = …both resolving totypeof C).<no-node>in the ez-checker type oracle.Fix
Capture the binding token, create its identifier node, and
emitDeclare(.import_binding, local_node), mirroring the namespace/default-import paths.import_declalready useslhsas the import-equals discriminator (.none) andrhsas the module reference, so the binding has no data slot — anchor it under the declaration viaparent_fixupsso it's reachable in the parent tree.Validation
import X = require(...)andimport X = Y.Zeach declare animport_bindingsymbol that usages resolve to; theimport C = N.C; class D extends C {}collision case resolvesextends Cto the import; and a parser test that the binding identifier is created and parented to the declaration.