Permalink
Browse files

Tolerate missing ) in a with and do-while statement

Fix #1481
Closes gh-1694
  • Loading branch information...
ariya committed Dec 24, 2016
1 parent 8bdae74 commit 6e2bd2868045a21134f91f3fd47719e7075fb427
View
@@ -2142,9 +2142,14 @@ export class Parser {
this.expectKeyword('while');
this.expect('(');
const test = this.parseExpression();
this.expect(')');
if (this.match(';')) {
this.nextToken();
if (!this.match(')') && this.config.tolerant) {
this.tolerateUnexpectedToken(this.nextToken());
} else {
this.expect(')');
if (this.match(';')) {
this.nextToken();
}
}
return this.finalize(node, new Node.DoWhileStatement(body, test));
@@ -2403,11 +2408,19 @@ export class Parser {
}
const node = this.createNode();
let body;
this.expectKeyword('with');
this.expect('(');
const object = this.parseExpression();
this.expect(')');
const body = this.parseStatement();
if (!this.match(')') && this.config.tolerant) {
this.tolerateUnexpectedToken(this.nextToken());
body = this.finalize(this.createNode(), new Node.EmptyStatement());
} else {
this.expect(')');
body = this.parseStatement();
}
return this.finalize(node, new Node.WithStatement(object, body));
}
@@ -0,0 +1 @@
do {} while (true
@@ -0,0 +1,192 @@
{
"type": "Program",
"body": [
{
"type": "DoWhileStatement",
"body": {
"type": "BlockStatement",
"body": [],
"range": [
3,
5
],
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 5
}
}
},
"test": {
"type": "Literal",
"value": true,
"raw": "true",
"range": [
13,
17
],
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 17
}
}
},
"range": [
0,
18
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 0
}
}
}
],
"sourceType": "script",
"range": [
0,
18
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 0
}
},
"tokens": [
{
"type": "Keyword",
"value": "do",
"range": [
0,
2
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 2
}
}
},
{
"type": "Punctuator",
"value": "{",
"range": [
3,
4
],
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
}
}
},
{
"type": "Punctuator",
"value": "}",
"range": [
4,
5
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 5
}
}
},
{
"type": "Keyword",
"value": "while",
"range": [
6,
11
],
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 11
}
}
},
{
"type": "Punctuator",
"value": "(",
"range": [
12,
13
],
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 13
}
}
},
{
"type": "Boolean",
"value": "true",
"range": [
13,
17
],
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 17
}
}
}
],
"errors": [
{
"index": 18,
"lineNumber": 2,
"column": 1,
"message": "Error: Line 2: Unexpected end of input"
}
]
}
@@ -0,0 +1 @@
with (x
@@ -0,0 +1,136 @@
{
"type": "Program",
"body": [
{
"type": "WithStatement",
"object": {
"type": "Identifier",
"name": "x",
"range": [
6,
7
],
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
}
}
},
"body": {
"type": "EmptyStatement",
"range": [
8,
8
],
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 0
}
}
},
"range": [
0,
8
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 0
}
}
}
],
"sourceType": "script",
"range": [
0,
8
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 0
}
},
"tokens": [
{
"type": "Keyword",
"value": "with",
"range": [
0,
4
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 4
}
}
},
{
"type": "Punctuator",
"value": "(",
"range": [
5,
6
],
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
}
}
},
{
"type": "Identifier",
"value": "x",
"range": [
6,
7
],
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
}
}
}
],
"errors": [
{
"index": 8,
"lineNumber": 2,
"column": 1,
"message": "Error: Line 2: Unexpected end of input"
}
]
}

0 comments on commit 6e2bd28

Please sign in to comment.