Merge pull request #3220 from jmm/not-a-directive
Don't parse parenthesized string as directive
This commit is contained in:
commit
2ec842d425
@ -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);
|
||||
|
||||
|
||||
1
packages/babylon/test/fixtures/core/categorized/not-directive/actual.js
vendored
Normal file
1
packages/babylon/test/fixtures/core/categorized/not-directive/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
("not a directive");
|
||||
71
packages/babylon/test/fixtures/core/categorized/not-directive/expected.json
vendored
Normal file
71
packages/babylon/test/fixtures/core/categorized/not-directive/expected.json
vendored
Normal 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": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user