Repository navigation
Fix panic during declaration emit with stripInternal on parenthesized and wrapped types - #65624
Open
Shakil Ur Rehman (ShakilUrRehman21) wants to merge 2 commits into
Conversation
… wrapped types Fixes microsoft#65623
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Declaration emit still panics with --stripInternal when an indexed-access type loses its object operand, requiring nil-aware handling and a regression test.
1 open issue
What changed in this PR
This PR addresses #65623 by preventing declaration-emission panics when --stripInternal removes types inside parentheses, type operators, or arrays.
Changes:
- Adds wrapper-specific transforms that propagate removal of an inner type.
- Adds regression cases for type aliases, variable annotations, and nested wrappers.
- Records expected declaration output and type/symbol baselines.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts |
Adds regression cases for stripped wrapped types. |
tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.types |
Records inferred types for the test. |
tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.symbols |
Records symbol bindings for the test. |
tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.js |
Records JavaScript, declarations, and declaration diagnostics. |
tsc/internal/transformers/declarations/transform.go |
Adds nil-aware transforms for parentheses, operators, and arrays. |
Review effort: Balanced
This branch has not been deployed
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 #65623
Analysis
When
--declarationand--stripInternalare enabled, encountering an@internaltype wrapped in parentheses (e.g.export type T = ( /** @internal */ Foo );orexport const x: ( /** @internal */ Foo ) = ...) causes the compiler to panic with a nil pointer dereference:In
tsc/internal/transformers/declarations/transform.go,KindParenthesizedType,KindTypeOperator, andKindArrayTypefell into the default visitor:result = tx.Visitor().VisitEachChild(input).When the inner type was elided by
--stripInternal(returningnil),VisitEachChildcalledUpdateParenthesizedTypeNode(input, nil), constructing a node whose inner.Typepointer wasnil.transformTypeAliasDeclaration,t := tx.Visitor().Visit(input.Type)returned this non-nilParenthesizedTypeNode, bypassingif t == nil { t = any }.ast.GetTypeNodePrecedence(node.Type)on the innernilnode, dereferencingnil.Kindand panicking.ensureTypefor variable declarations, returning a parenthesized type with an innernilpointer crashedemitTypeAnnotation.Fix
KindParenthesizedType,KindTypeOperator, andKindArrayTypeinDeclarationTransformer:nil(elided byshouldStripInternal), the wrapper returnsnilas well.nilallowstransformTypeAliasDeclarationto correctly substituteany(consistent with bare@internaltype aliases) and allowsensureTypeto elide the type annotation cleanly.declarationEmitStripInternalParenthesizedType.tscovering parenthesized type aliases, variable type annotations, and nested type operators/arrays.