diff --git a/acorn.js b/acorn.js index 1e8fc48b37..692e6c6796 100644 --- a/acorn.js +++ b/acorn.js @@ -805,7 +805,10 @@ function readToken_pipe_amp(code) { // '|&' var next = input.charCodeAt(tokPos + 1); - if (next === code) return finishOp(code === 124 ? _logicalOR : _logicalAND, 2); + if (next === code) { + if (options.playground && input.charCodeAt(tokPos + 2) === 61) return finishOp(_assign, 3); + return finishOp(code === 124 ? _logicalOR : _logicalAND, 2); + } if (next === 61) return finishOp(_assign, 2); return finishOp(code === 124 ? _bitwiseOR : _bitwiseAND, 1); } diff --git a/test/tests-6to5-playground.js b/test/tests-6to5-playground.js index d0d5b0af8a..d04f037aaf 100644 --- a/test/tests-6to5-playground.js +++ b/test/tests-6to5-playground.js @@ -245,6 +245,83 @@ test("obj.x ?= 2;", { playground: true }); + + +test("x ||= 2;", { + type: "Program", + start: 0, + end: 8, + body: [{ + type: "ExpressionStatement", + start: 0, + end: 8, + expression: { + type: "AssignmentExpression", + start: 0, + end: 7, + left: { + type: "Identifier", + start: 0, + end: 1 + }, + right: { + type: "Literal", + start: 6, + end: 7, + value: 2, + raw: "2" + }, + operator: "||=" + } + }] +}, { + playground: true +}); + +test("obj.x ||= 2;", { + type: "Program", + start: 0, + end: 12, + body: [{ + type: "ExpressionStatement", + start: 0, + end: 12, + expression: { + type: "AssignmentExpression", + start: 0, + end: 11, + left: { + type: "MemberExpression", + start: 0, + end: 5, + object: { + type: "Identifier", + start: 0, + end: 3, + name: "obj" + }, + property: { + type: "Identifier", + start: 4, + end: 5, + name: "x" + }, + computed: false + }, + right: { + type: "Literal", + start: 10, + end: 11, + value: 2, + raw: "2" + }, + operator: "||=" + } + }] +}, { + playground: true +}); + // Method binding test("var fn = obj#method", {