You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import*astsfrom'typescript';constprinter=ts.createPrinter({newLine: ts.NewLineKind.LineFeed});constsrc=ts.createSourceFile('test.ts','',ts.ScriptTarget.Latest);constnullishNode=ts.factory.createExpressionStatement(ts.factory.createBinaryExpression(ts.factory.createConditionalExpression(ts.factory.createIdentifier('a'),ts.factory.createToken(ts.SyntaxKind.QuestionToken),ts.factory.createIdentifier('b'),ts.factory.createToken(ts.SyntaxKind.ColonToken),ts.factory.createIdentifier('c')),ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),ts.factory.createIdentifier('d')));constorNode=ts.factory.createExpressionStatement(ts.factory.createBinaryExpression(ts.factory.createConditionalExpression(ts.factory.createIdentifier('a'),ts.factory.createToken(ts.SyntaxKind.QuestionToken),ts.factory.createIdentifier('b'),ts.factory.createToken(ts.SyntaxKind.ColonToken),ts.factory.createIdentifier('c')),ts.factory.createToken(ts.SyntaxKind.BarBarToken),ts.factory.createIdentifier('d')));// a ? b : c ?? dconstnullish=printer.printNode(ts.EmitHint.Unspecified,nullishNode,src);// (a ? b : c) || dconstor=printer.printNode(ts.EmitHint.Unspecified,orNode,src);
π Actual behavior
When I manually create AST for the expression (a ? b : c) ?? d but leave the parentheses out of the AST, the generated code does not add the parens back in and therefore does not match the structure of the AST.
When I do this same thing with || or && it behaves as expected, inserting the parens back in to the generated code.
π Expected behavior
The nullishNode should be printed in the same way the orNode is in the example, adding back in the parentheses so that the code matches the structure of the AST
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
π Search Terms
nullish coalescing parentheses ast
π Version & Regression Information
β― Playground Link
https://stackblitz.com/edit/vitejs-vite-letuvqes?file=src%2Fmain.ts
π» Code
π Actual behavior
When I manually create AST for the expression
(a ? b : c) ?? d
but leave the parentheses out of the AST, the generated code does not add the parens back in and therefore does not match the structure of the AST.When I do this same thing with
||
or&&
it behaves as expected, inserting the parens back in to the generated code.π Expected behavior
The
nullishNode
should be printed in the same way theorNode
is in the example, adding back in the parentheses so that the code matches the structure of the ASTAdditional information about the issue
No response
The text was updated successfully, but these errors were encountered: