diff --git a/packages/babylon/src/parser/statement.js b/packages/babylon/src/parser/statement.js index f58e661e83..a0050cc2d0 100644 --- a/packages/babylon/src/parser/statement.js +++ b/packages/babylon/src/parser/statement.js @@ -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); diff --git a/packages/babylon/test/fixtures/core/categorized/not-directive/actual.js b/packages/babylon/test/fixtures/core/categorized/not-directive/actual.js new file mode 100644 index 0000000000..2392784f31 --- /dev/null +++ b/packages/babylon/test/fixtures/core/categorized/not-directive/actual.js @@ -0,0 +1 @@ +("not a directive"); diff --git a/packages/babylon/test/fixtures/core/categorized/not-directive/expected.json b/packages/babylon/test/fixtures/core/categorized/not-directive/expected.json new file mode 100644 index 0000000000..7e25efd1e5 --- /dev/null +++ b/packages/babylon/test/fixtures/core/categorized/not-directive/expected.json @@ -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": [] + } +}