-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Milestone
Description
π Search Terms
- nullish coalescing
- boolean operation
- parenthesis
π Version & Regression Information
- This changed between versions 5.8 and 5.9
- Was probably changed by Fixed nullish coalesce operator's precedenceΒ #61372
β― Playground Link
https://stackblitz.com/edit/vitejs-vite-a11yrnds?file=package.json,src%2Fmain.ts
π» Code
import * as ts from 'typescript';
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
const src = ts.createSourceFile('test.ts', '', ts.ScriptTarget.Latest);
const nullishOrNode = ts.factory.createExpressionStatement(
ts.factory.createBinaryExpression(
ts.factory.createBinaryExpression(
ts.factory.createIdentifier('a'),
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
ts.factory.createIdentifier('b')
),
ts.factory.createToken(ts.SyntaxKind.BarBarToken),
ts.factory.createIdentifier('d')
)
);
// (a ? b : c) || d
const nullishOr = printer.printNode(
ts.EmitHint.Unspecified,
nullishOrNode,
src
);
π Actual behavior
To output: a ?? b || d;
π Expected behavior
To output: (a ?? b) || d;
Additional information about the issue
This change as a breaking change by an Angular user after updating to TS 5.9 angular/angular#63287
michael-small, imaksp and hakimio