Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,10 @@ export class Parser {
op === '>>>=' ||
op === '&=' ||
op === '^=' ||
op === '|=';
op === '|=' ||
op === '&&=' ||
op === '||=' ||
op === '??=';
}

// Cover grammar support.
Expand Down
12 changes: 9 additions & 3 deletions src/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,12 @@ export class Scanner {
++this.index;
if (this.source[this.index] === '?') {
++this.index;
str = '??';
if (this.source[this.index] === '=') {
++this.index;
str = '??=';
} else {
str = '??';
}
} if (this.source[this.index] === '.' && !/^\d$/.test(this.source[this.index + 1])) {
// "?." in "foo?.3:0" should not be treated as optional chaining.
// See https://github.com/tc39/proposal-optional-chaining#notes
Expand Down Expand Up @@ -642,13 +647,14 @@ export class Scanner {
// 3-character punctuators.
str = str.substr(0, 3);
if (str === '===' || str === '!==' || str === '>>>' ||
str === '<<=' || str === '>>=' || str === '**=') {
str === '<<=' || str === '>>=' || str === '**=' ||
str === '&&=' || str === '||=') {
this.index += 3;
} else {

// 2-character punctuators.
str = str.substr(0, 2);
if (str === '&&' || str === '||' || str === '??' ||
if (str === '&&' || str === '||' ||
str === '==' || str === '!=' ||
str === '+=' || str === '-=' || str === '*=' || str === '/=' ||
str === '++' || str === '--' ||
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo &&= true
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "&&=",
"left": {
"type": "Identifier",
"name": "foo",
"range": [
0,
3
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 3
}
}
},
"right": {
"type": "Literal",
"value": true,
"raw": "true",
"range": [
8,
12
],
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 12
}
}
},
"range": [
0,
12
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
}
},
"range": [
0,
12
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
}
}
],
"sourceType": "script",
"range": [
0,
12
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"tokens": [
{
"type": "Identifier",
"value": "foo",
"range": [
0,
3
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 3
}
}
},
{
"type": "Punctuator",
"value": "&&=",
"range": [
4,
7
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 7
}
}
},
{
"type": "Boolean",
"value": "true",
"range": [
8,
12
],
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 12
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo ??= true
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "??=",
"left": {
"type": "Identifier",
"name": "foo",
"range": [
0,
3
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 3
}
}
},
"right": {
"type": "Literal",
"value": true,
"raw": "true",
"range": [
8,
12
],
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 12
}
}
},
"range": [
0,
12
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
}
},
"range": [
0,
12
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
}
}
],
"sourceType": "script",
"range": [
0,
12
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"tokens": [
{
"type": "Identifier",
"value": "foo",
"range": [
0,
3
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 3
}
}
},
{
"type": "Punctuator",
"value": "??=",
"range": [
4,
7
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 7
}
}
},
{
"type": "Boolean",
"value": "true",
"range": [
8,
12
],
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 12
}
}
}
]
}
Loading