Repository navigation
Extract to typedef from (invalid) type with comments in JS file causes assertion failure #48540
Description
Activity
- addedBugA bug in TypeScriptA bug in TypeScriptHelp WantedYou can do thisYou can do thisDomain: LS: Refactoringse.g. extract to constant or function, rename symbole.g. extract to constant or function, rename symbolDomain: JavaScriptThe issue relates to JavaScript specificallyThe issue relates to JavaScript specificallyCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputEffort: CasualGood issue if you're already used to contributing to the codebase. Harder than "good first issue".Good issue if you're already used to contributing to the codebase. Harder than "good first issue".
on Apr 3, 2022 I was encountering a similar error in #48112 due to new synthetic nodes being added as a result of processing text changes. I fixed the case I ran into using this: https://github.com/microsoft/TypeScript/pull/48112/files?show-viewed-files=true&file-filters%5B%5D=#diff-386d93db50a938da0c4af7bb293ac679b5da235cebeeee9adbc040fbf8aa222cR1128-R1136
I'll have to check whether the issues are related.
DanielRosenwasser commented
on Apr 4, 2022 MemberAuthorMore actionsThat link seems to have issues on my end - can you hard-link to the line range of the file?
TypeScript/src/services/textChanges.ts
Lines 1128 to 1136 in 01b9a2d
const textChangesTransformationContext: TransformationContext = { ...nullTransformationContext, factory: createNodeFactory( nullTransformationContext.factory.flags | NodeFactoryFlags.NoParenthesizerRules, nullTransformationContext.factory.baseFactory), }; export function assignPositionsToNode(node: Node): Node { const visited = visitEachChild(node, assignPositionsToNode, textChangesTransformationContext, assignPositionsToNodeArray, assignPositionsToNode); The problem is that the
nullTransformationContextuses a defaultNodeFactorythat does auto-parenthesization, and our auto-parenthesization for types is fairly aggressive, so we sometimes introduce a new parenthesized type when visiting on 1136. Since this visitor is only supposed to create a proxy for existing nodes for the purpose of setting positions, its not designed to handle net-new nodes.DanielRosenwasser commented
on Apr 5, 2022 MemberAuthorMore actionsIs it a parenthesization issue? It seems more like it's specific to putting a comment inside of a comment. The fix that Minh Quy (@MQuy) has at #48545 of just dropping the comments fixes the specific tests at a shallow level, but would fail any deeper.
Is there a way to turn off comment trivia emit for an entire subtree? That would probably be an ideal fix, but admittedly I'm not familiar with the transform pipeline anymore.
Is it a parenthesization issue? It seems more like it's specific to putting a comment inside of a comment. The fix that Minh Quy (@MQuy) has at #48545 of just dropping the comments fixes the specific tests at a shallow level, but would fail any deeper.
I thought it may have been due to a ParenthesizedType node being silently added to the type, but that does not seem to be the case here.
Is there a way to turn off comment trivia emit for an entire subtree? That would probably be an ideal fix, but admittedly I'm not familiar with the transform pipeline anymore.
Yes, you can set
EmitFlags.NoComments | EmitFlags.NoNestedCommentsto disable comments for the node and its subtree.DanielRosenwasser commented
on Apr 5, 2022 MemberAuthorMore actionsThank you Minh Quy (@MQuy)!
DanielRosenwasser commented
on Apr 6, 2022 MemberAuthorMore actionsLooks like there's still an issue when triggering the command from inside of a comment (#48593).
- locked as resolved and limited conversation to collaborators
on Oct 22, 2025
Request "extract to typedef" on each
[|region|].