-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ts.Node.getChildren() returns duplicate copies of the same AST nodes in TS 4.3 #44422
Comments
Seems like we might need to back-port this to 4.3. |
I suspect that these nodes are being added both as jsdoc children and as normal children inside the tree-trivia-reconstruction part of the services code. |
ts-ast-viewer shows this off interactively, right down to highlighting two items in the tree pane: https://ts-ast-viewer.com/#code/PQKhCgAIUgBAHAhgJ0QW0ig5gRkgFQAsBTSAb1gBsBLAOwGsCBPeYgJWIDNjljaBjYgGcAkrQCCxACYB7fgF8AdFBDBwANxSQAHuCA For the smaller program: /**
* @param arg1 The {@link TypeReferencesInAedoc}.
*/
var x Note that this doesn't repro with |
(In order to see this, you need to change |
Anyway, it's just a bug in the visitor code for case SyntaxKind.JSDocParameterTag:
case SyntaxKind.JSDocPropertyTag:
return visitNode(cbNode, (node as JSDocTag).tagName) ||
((node as JSDocPropertyLikeTag).isNameFirst
? visitNode(cbNode, (node as JSDocPropertyLikeTag).name) ||
visitNode(cbNode, (node as JSDocPropertyLikeTag).typeExpression) ||
(typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray<JSDocComment> | undefined))
: visitNode(cbNode, (node as JSDocPropertyLikeTag).typeExpression) ||
visitNode(cbNode, (node as JSDocPropertyLikeTag).name)) ||
(typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray<JSDocComment> | undefined)); This visits the comment twice, and the test we have to make sure the visitor covers everything doesn't check for double visits. |
Fixes #44422 Co-authored-by: Nathan Shively-Sanders <[email protected]>
Thanks for getting this fixed! |
This reverts commit cfa0abe
This reverts commit cfa0abe
Bug Report
Starting with TypeScript 4.3, the
ts.Node.getChildren()
API may return two copies of the same AST node.🔎 Search Terms
getChildren
🕗 Version & Regression Information
Repros with TypeScript
4.3.2
and4.4.0-dev.20210602
Does NOT repro with TypeScript
4.2.4
💻 Code
Here is a complete project that reproduces the problem: repro.zip
The code looks like this:
repro.js
It uses the compiler API to parse an input like this:
input.ts
🙁 Actual behavior
The printed output looks like this:
The duplicated pos/end nodes are actually the same object instances, which can be verified in the debugger:
🙂 Expected behavior
ts.Node.getChildren()
should not return duplicate nodes.The text was updated successfully, but these errors were encountered: