Add ??= to Logical Assignment Operators (#7623)

`??=` is being merged into the Logical Assignment Operator proposal, and the overall proposal will wait until nullish coalescing is finalized.
This commit is contained in:
Justin Ridgewell
2018-03-25 18:58:51 +01:00
committed by GitHub
parent 023f8bd1cb
commit a7bddc02ba
19 changed files with 391 additions and 9 deletions

View File

@@ -299,10 +299,6 @@ export default class ExpressionParser extends LValParser {
this.state.potentialArrowAt = startPos;
}
if (node.operator === "??") {
this.expectPlugin("nullishCoalescingOperator");
}
node.right = this.parseExprOp(
this.parseMaybeUnary(),
startPos,

View File

@@ -607,8 +607,16 @@ export default class Tokenizer extends LocationParser {
const next = this.input.charCodeAt(this.state.pos + 1);
const next2 = this.input.charCodeAt(this.state.pos + 2);
if (next === charCodes.questionMark) {
// '??'
this.finishOp(tt.nullishCoalescing, 2);
this.expectPlugin("nullishCoalescingOperator");
if (next2 === charCodes.equalsTo) {
// '??='
this.expectPlugin("logicalAssignment");
this.finishOp(tt.assign, 3);
} else {
// '??'
this.finishOp(tt.nullishCoalescing, 2);
}
} else if (
next === charCodes.dot &&
!(next2 >= charCodes.digit0 && next2 <= charCodes.digit9)