Repository navigation
Fix enum crash when namespace and enum share a name - #64743
Jake Bailey (jakebailey) merged 11 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The unrelated ModuleBlock member-list expansion weakens an established AST API invariant.
1 open finding
What changed in this PR
Prevents a compiler panic when merged namespace/enum member access reaches enum value computation.
Changes:
- Guards enum computation by node kind.
- Expands
MemberListto module blocks. - Adds regression coverage and baselines.
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Guards enum value computation. |
tsc/internal/ast/ast.go |
Adds module blocks to MemberList. |
tsc/testdata/tests/cases/compiler/enumMemberListModuleBlock.ts |
Adds regression case. |
tsc/testdata/baselines/reference/compiler/enumMemberListModuleBlock.errors.txt |
Captures expected diagnostic. |
tsc/testdata/baselines/reference/compiler/enumMemberListModuleBlock.js |
Captures emitted JavaScript. |
tsc/testdata/baselines/reference/compiler/enumMemberListModuleBlock.symbols |
Captures symbol output. |
tsc/testdata/baselines/reference/compiler/enumMemberListModuleBlock.types |
Captures type output. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
Addressed the AST API invariant review: removed the unrelated |
|
If you're not a person who can sign a CLA, I don't think you should be sending PRs |
|
@microsoft-github-policy-service agree |
|
To clarify: I am submitting this PR personally, as an independent individual contributor, not on behalf of my employer or any company. I can sign the Microsoft CLA in my individual capacity if GitHub still requires it; please let me know if any contributor verification remains outstanding. The earlier AST MemberList review finding has already been addressed in d064a4c. |
Signed LCA, Can you please review? Jake Bailey (@jakebailey) |

Fixes #64668
Analysis
For a merged namespace and enum, the enum symbol's exports include namespace declarations. In this example,
Cis a class:The element-access path in
evaluateEntitychecks thatEhas enum flags, then passes the exported class symbol toevaluateEnumMember. That eventually callsgetEnumMemberValueon a class declaration and attempts to compute enum values on its parent module block.Fix
Require
SymbolFlagsEnumMemberon the exported symbol before evaluating it as an enum member. This matches the check already used by the identifier and property-access path. Other exports produce the evaluator's existing nonconstant result, allowing the initializer check to report TS18033.The regression covers the merged namespace and enum case. Removing the previous guard reproduced the
KindModuleBlockpanic. With the caller check, that regression and the enum compiler suite pass.Copilot Checklist
npx hereby validateThe first full run encountered a file-watcher delete-event timeout. That test passed three retries, the complete compiler test suite passed on rerun, and the final full validation passed.