Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Merge pull request #762 from azz/nullish-tests
Browse files Browse the repository at this point in the history
Add more tests for the nullish coalescing operator
  • Loading branch information
hzoo authored Oct 16, 2017
2 parents f1d2db6 + 727767c commit eaf054b
Show file tree
Hide file tree
Showing 25 changed files with 967 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ coverage
lib
node_modules
npm-debug.log
.vscode
3 changes: 1 addition & 2 deletions ast/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,6 @@ enum BinaryOperator {
| "|" | "^" | "&" | "in"
| "instanceof"
| "|>"
| "??"
}
```

Expand Down Expand Up @@ -839,7 +838,7 @@ A logical operator expression.

```js
enum LogicalOperator {
"||" | "&&"
"||" | "&&" | "??"
}
```

Expand Down
4 changes: 3 additions & 1 deletion src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ export default class ExpressionParser extends LValParser {

this.finishNode(
node,
op === tt.logicalOR || op === tt.logicalAND
op === tt.logicalOR ||
op === tt.logicalAND ||
op === tt.nullishCoalescing
? "LogicalExpression"
: "BinaryExpression",
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a && b ?? c;
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"type": "File",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"program": {
"type": "Program",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"expression": {
"type": "LogicalExpression",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"left": {
"type": "LogicalExpression",
"start": 0,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
},
"left": {
"type": "Identifier",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
},
"identifierName": "a"
},
"name": "a"
},
"operator": "&&",
"right": {
"type": "Identifier",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
},
"identifierName": "b"
},
"name": "b"
}
},
"operator": "??",
"right": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "c"
},
"name": "c"
}
}
}
],
"directives": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["nullishCoalescingOperator"]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a ?? b ?? c;
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"type": "File",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"program": {
"type": "Program",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"expression": {
"type": "LogicalExpression",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"left": {
"type": "LogicalExpression",
"start": 0,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
},
"left": {
"type": "Identifier",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
},
"identifierName": "a"
},
"name": "a"
},
"operator": "??",
"right": {
"type": "Identifier",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
},
"identifierName": "b"
},
"name": "b"
}
},
"operator": "??",
"right": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "c"
},
"name": "c"
}
}
}
],
"directives": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["nullishCoalescingOperator"]
}

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
}
},
"expression": {
"type": "BinaryExpression",
"type": "LogicalExpression",
"start": 0,
"end": 8,
"loc": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a
?? b
?? c;
Loading

0 comments on commit eaf054b

Please sign in to comment.