Skip to content

Commit 57be95d

Browse files
committed
fix review
1 parent 8227034 commit 57be95d

16 files changed

+93
-24
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,6 @@ namespace ts {
13751375
}
13761376
}
13771377

1378-
// TODO(rbuckton): Determine how to hook ?? into flow typing
13791378
function bindBinaryExpressionFlow(node: BinaryExpression) {
13801379
const operator = node.operatorToken.kind;
13811380
if (operator === SyntaxKind.AmpersandAmpersandToken || operator === SyntaxKind.BarBarToken || operator === SyntaxKind.QuestionQuestionToken) {
@@ -2730,7 +2729,7 @@ namespace ts {
27302729
init = init && getRightMostAssignedExpression(init);
27312730
if (init) {
27322731
const isPrototypeAssignment = isPrototypeAccess(isVariableDeclaration(node) ? node.name : isBinaryExpression(node) ? node.left : node);
2733-
return !!getExpandoInitializer(isBinaryExpression(init) && init.operatorToken.kind === SyntaxKind.BarBarToken ? init.right : init, isPrototypeAssignment);
2732+
return !!getExpandoInitializer(isBinaryExpression(init) && (init.operatorToken.kind === SyntaxKind.BarBarToken || init.operatorToken.kind === SyntaxKind.QuestionQuestionToken) ? init.right : init, isPrototypeAssignment);
27342733
}
27352734
return false;
27362735
}

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24514,10 +24514,10 @@ namespace ts {
2451424514
const { left, operatorToken, right } = node;
2451524515
if (operatorToken.kind === SyntaxKind.QuestionQuestionToken) {
2451624516
if (isBinaryExpression(left) && (left.operatorToken.kind === SyntaxKind.BarBarToken || left.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken)) {
24517-
error(left, Diagnostics.Operator_0_cannot_immediately_contain_or_be_contained_within_an_1_operation, tokenToString(left.operatorToken.kind), tokenToString(operatorToken.kind));
24517+
grammarErrorOnNode(left, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(left.operatorToken.kind), tokenToString(operatorToken.kind));
2451824518
}
2451924519
if (isBinaryExpression(right) && (right.operatorToken.kind === SyntaxKind.BarBarToken || right.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken)) {
24520-
error(right, Diagnostics.Operator_0_cannot_immediately_contain_or_be_contained_within_an_1_operation, tokenToString(right.operatorToken.kind), tokenToString(operatorToken.kind));
24520+
grammarErrorOnNode(right, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(right.operatorToken.kind), tokenToString(operatorToken.kind));
2452124521
}
2452224522
}
2452324523
}

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3180,7 +3180,7 @@
31803180
"category": "Error",
31813181
"code": 5075
31823182
},
3183-
"Operator '{0}' cannot immediately contain, or be contained within an '{1}' operation.": {
3183+
"'{0}' and '{1}' operations cannot be mixed without parentheses.": {
31843184
"category": "Error",
31853185
"code": 5076
31863186
},

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3006,7 +3006,7 @@ namespace ts {
30063006
return parseJSDocAllType(/*postfixEquals*/ true);
30073007
case SyntaxKind.QuestionQuestionToken:
30083008
// If there is '??', consider that is prefix '?' in JSDoc type.
3009-
scanner.reScanQuestionQuestionToken();
3009+
scanner.reScanQuestionToken();
30103010
// falls through
30113011
case SyntaxKind.QuestionToken:
30123012
return parseJSDocUnknownOrNullableType();

src/compiler/scanner.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace ts {
3333
scanJsxAttributeValue(): SyntaxKind;
3434
reScanJsxToken(): JsxTokenSyntaxKind;
3535
reScanLessThanToken(): SyntaxKind;
36-
reScanQuestionQuestionToken(): SyntaxKind;
36+
reScanQuestionToken(): SyntaxKind;
3737
scanJsxToken(): JsxTokenSyntaxKind;
3838
scanJsDocToken(): JSDocSyntaxKind;
3939
scan(): SyntaxKind;
@@ -902,7 +902,7 @@ namespace ts {
902902
scanJsxAttributeValue,
903903
reScanJsxToken,
904904
reScanLessThanToken,
905-
reScanQuestionQuestionToken,
905+
reScanQuestionToken,
906906
scanJsxToken,
907907
scanJsDocToken,
908908
scan,
@@ -2023,8 +2023,8 @@ namespace ts {
20232023
return token;
20242024
}
20252025

2026-
function reScanQuestionQuestionToken(): SyntaxKind {
2027-
Debug.assert(token === SyntaxKind.QuestionQuestionToken, "'reScanQuestionQuestionToken' should only be called on a '??'");
2026+
function reScanQuestionToken(): SyntaxKind {
2027+
Debug.assert(token === SyntaxKind.QuestionQuestionToken, "'reScanQuestionToken' should only be called on a '??'");
20282028
pos = tokenPos + 1;
20292029
return token = SyntaxKind.QuestionToken;
20302030
}

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ namespace ts {
19821982
/** Given an expando initializer, return its declaration name, or the left-hand side of the assignment if it's part of an assignment declaration. */
19831983
export function getNameOfExpando(node: Declaration): DeclarationName | undefined {
19841984
if (isBinaryExpression(node.parent)) {
1985-
const parent = (node.parent.operatorToken.kind === SyntaxKind.BarBarToken && isBinaryExpression(node.parent.parent)) ? node.parent.parent : node.parent;
1985+
const parent = ((node.parent.operatorToken.kind === SyntaxKind.BarBarToken || node.parent.operatorToken.kind === SyntaxKind.QuestionQuestionToken) && isBinaryExpression(node.parent.parent)) ? node.parent.parent : node.parent;
19861986
if (parent.operatorToken.kind === SyntaxKind.EqualsToken && isIdentifier(parent.left)) {
19871987
return parent.left;
19881988
}

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3203,7 +3203,7 @@ declare namespace ts {
32033203
scanJsxAttributeValue(): SyntaxKind;
32043204
reScanJsxToken(): JsxTokenSyntaxKind;
32053205
reScanLessThanToken(): SyntaxKind;
3206-
reScanQuestionQuestionToken(): SyntaxKind;
3206+
reScanQuestionToken(): SyntaxKind;
32073207
scanJsxToken(): JsxTokenSyntaxKind;
32083208
scanJsDocToken(): JSDocSyntaxKind;
32093209
scan(): SyntaxKind;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3203,7 +3203,7 @@ declare namespace ts {
32033203
scanJsxAttributeValue(): SyntaxKind;
32043204
reScanJsxToken(): JsxTokenSyntaxKind;
32053205
reScanLessThanToken(): SyntaxKind;
3206-
reScanQuestionQuestionToken(): SyntaxKind;
3206+
reScanQuestionToken(): SyntaxKind;
32073207
scanJsxToken(): JsxTokenSyntaxKind;
32083208
scanJsDocToken(): JSDocSyntaxKind;
32093209
scan(): SyntaxKind;

tests/baselines/reference/nullishCoalescingOperator3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ const aa1 = a1 ?? a2 ?? a3 ?? a4 ?? a5 ?? a6 ?? 'whatever'
1111

1212

1313
//// [nullishCoalescingOperator3.js]
14-
var _a, _b, _c, _d, _e;
1514
"use strict";
15+
var _a, _b, _c, _d, _e;
1616
var aa1 = (_e = (_d = (_c = (_b = (_a = (a1 != null ? a1 : a2), (_a != null ? _a : a3)), (_b != null ? _b : a4)), (_c != null ? _c : a5)), (_d != null ? _d : a6)), (_e != null ? _e : 'whatever'));

tests/baselines/reference/nullishCoalescingOperator5.errors.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator5.ts(6,6): error TS5076: Operator '||' cannot immediately contain, or be contained within an '??' operation.
2-
tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator5.ts(9,1): error TS5076: Operator '||' cannot immediately contain, or be contained within an '??' operation.
3-
tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator5.ts(12,6): error TS5076: Operator '&&' cannot immediately contain, or be contained within an '??' operation.
4-
tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator5.ts(15,1): error TS5076: Operator '&&' cannot immediately contain, or be contained within an '??' operation.
1+
tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator5.ts(6,6): error TS5076: '||' and '??' operations cannot be mixed without parentheses.
2+
tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator5.ts(9,1): error TS5076: '||' and '??' operations cannot be mixed without parentheses.
3+
tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator5.ts(12,6): error TS5076: '&&' and '??' operations cannot be mixed without parentheses.
4+
tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator5.ts(15,1): error TS5076: '&&' and '??' operations cannot be mixed without parentheses.
55

66

77
==== tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator5.ts (4 errors) ====
@@ -12,22 +12,22 @@ tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingO
1212
// should be a syntax error
1313
a ?? b || c;
1414
~~~~~~
15-
!!! error TS5076: Operator '||' cannot immediately contain, or be contained within an '??' operation.
15+
!!! error TS5076: '||' and '??' operations cannot be mixed without parentheses.
1616

1717
// should be a syntax error
1818
a || b ?? c;
1919
~~~~~~
20-
!!! error TS5076: Operator '||' cannot immediately contain, or be contained within an '??' operation.
20+
!!! error TS5076: '||' and '??' operations cannot be mixed without parentheses.
2121

2222
// should be a syntax error
2323
a ?? b && c;
2424
~~~~~~
25-
!!! error TS5076: Operator '&&' cannot immediately contain, or be contained within an '??' operation.
25+
!!! error TS5076: '&&' and '??' operations cannot be mixed without parentheses.
2626

2727
// should be a syntax error
2828
a && b ?? c;
2929
~~~~~~
30-
!!! error TS5076: Operator '&&' cannot immediately contain, or be contained within an '??' operation.
30+
!!! error TS5076: '&&' and '??' operations cannot be mixed without parentheses.
3131

3232
// Valid according to spec
3333
a ?? (b || c);

0 commit comments

Comments
 (0)