Fixed nullish coalesce operator's precedence (#61372)

This commit is contained in:
Mateusz Burzyński
2025-06-30 22:49:03 +02:00
committed by GitHub
parent 58665cf3ae
commit 91cdbd518c
15 changed files with 240 additions and 30 deletions

View File

@@ -366,5 +366,62 @@ describe("unittests:: PrinterAPI", () => {
ts.factory.createNoSubstitutionTemplateLiteral("\n"),
ts.createSourceFile("source.ts", "", ts.ScriptTarget.ESNext),
));
printsCorrectly("binaryBarBarExpressionWithLeftConditionalExpression", {}, printer =>
printer.printNode(
ts.EmitHint.Unspecified,
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"),
),
),
ts.createSourceFile("source.ts", "", ts.ScriptTarget.ESNext),
));
printsCorrectly("binaryAmpersandAmpersandExpressionWithLeftConditionalExpression", {}, printer =>
printer.printNode(
ts.EmitHint.Unspecified,
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.AmpersandAmpersandToken),
ts.factory.createIdentifier("d"),
),
),
ts.createSourceFile("source.ts", "", ts.ScriptTarget.ESNext),
));
printsCorrectly("binaryQuestionQuestionExpressionWithLeftConditionalExpression", {}, printer =>
printer.printNode(
ts.EmitHint.Unspecified,
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"),
),
),
ts.createSourceFile("source.ts", "", ts.ScriptTarget.ESNext),
));
});
});