Permalink
Browse files

Recognize Token.StringLiteral as a ReturnStatement argument.

This fix is similar to the one from #1882 for Token.Template.

Fixes #1897
Fixes #1928
Closes gh-1925
  • Loading branch information...
mfitz3 authored and ariya committed Apr 1, 2018
1 parent 529a5f2 commit 39e7668d8262eff129a52c416e9b9be4e811bdf5
@@ -2453,6 +2453,7 @@ export class Parser {
const hasArgument = (!this.match(';') && !this.match('}') &&
!this.hasLineTerminator && this.lookahead.type !== Token.EOF) ||
this.lookahead.type === Token.StringLiteral ||
this.lookahead.type === Token.Template;
const argument = hasArgument ? this.parseExpression() : null;
@@ -0,0 +1,4 @@
function a() {
return 'hello \
world';
}
@@ -0,0 +1,278 @@
{
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "a",
"range": [
9,
10
],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
}
},
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ReturnStatement",
"argument": {
"type": "Literal",
"value": "hello \tworld",
"raw": "'hello \\\n \tworld'",
"range": [
24,
42
],
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 3,
"column": 9
}
}
},
"range": [
17,
43
],
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 3,
"column": 10
}
}
}
],
"range": [
13,
45
],
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 4,
"column": 1
}
}
},
"generator": false,
"expression": false,
"async": false,
"range": [
0,
45
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
}
}
],
"sourceType": "script",
"range": [
0,
45
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"tokens": [
{
"type": "Keyword",
"value": "function",
"range": [
0,
8
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
}
}
},
{
"type": "Identifier",
"value": "a",
"range": [
9,
10
],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
}
},
{
"type": "Punctuator",
"value": "(",
"range": [
10,
11
],
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
}
}
},
{
"type": "Punctuator",
"value": ")",
"range": [
11,
12
],
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
}
}
},
{
"type": "Punctuator",
"value": "{",
"range": [
13,
14
],
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
}
}
},
{
"type": "Keyword",
"value": "return",
"range": [
17,
23
],
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 8
}
}
},
{
"type": "String",
"value": "'hello \\\n \tworld'",
"range": [
24,
42
],
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 3,
"column": 9
}
}
},
{
"type": "Punctuator",
"value": ";",
"range": [
42,
43
],
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 10
}
}
},
{
"type": "Punctuator",
"value": "}",
"range": [
44,
45
],
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
}
}
]
}

0 comments on commit 39e7668

Please sign in to comment.