Merge pull request #3220 from jmm/not-a-directive

Don't parse parenthesized string as directive
This commit is contained in:
Sebastian McKenzie 2015-12-31 01:54:47 +00:00
commit 2ec842d425
3 changed files with 74 additions and 1 deletions

View File

@ -460,7 +460,8 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {
let stmt = this.parseStatement(true, topLevel);
if (allowDirectives && !parsedNonDirective &&
stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral") {
stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" &&
!stmt.expression.extra.parenthesized) {
let directive = this.stmtToDirective(stmt);
node.directives.push(directive);

View File

@ -0,0 +1 @@
("not a directive");

View File

@ -0,0 +1,71 @@
{
"type": "File",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
},
"program": {
"type": "Program",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
},
"expression": {
"type": "StringLiteral",
"start": 1,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 18
}
},
"extra": {
"rawValue": "not a directive",
"raw": "\"not a directive\"",
"parenthesized": true,
"parenStart": 0
},
"value": "not a directive"
}
}
],
"directives": []
}
}