From 00505ac1713b66be1d884735f8670c851a8f51d0 Mon Sep 17 00:00:00 2001 From: Jesse McCarthy Date: Mon, 28 Dec 2015 09:57:43 -0500 Subject: [PATCH 1/2] Add non-directive fixture. (Failing.) --- .../core/categorized/not-directive/actual.js | 1 + .../categorized/not-directive/expected.json | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 packages/babylon/test/fixtures/core/categorized/not-directive/actual.js create mode 100644 packages/babylon/test/fixtures/core/categorized/not-directive/expected.json 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": [] + } +} From 424d0592924d28d6f563f24fa8641023cfcc7dc0 Mon Sep 17 00:00:00 2001 From: Jesse McCarthy Date: Mon, 28 Dec 2015 09:58:21 -0500 Subject: [PATCH 2/2] Don't make directive from parenthesized string. --- packages/babylon/src/parser/statement.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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);