diff --git a/packages/babylon/src/plugins/jsx/index.js b/packages/babylon/src/plugins/jsx/index.js index 03086cdfc9..f05266d1de 100644 --- a/packages/babylon/src/plugins/jsx/index.js +++ b/packages/babylon/src/plugins/jsx/index.js @@ -230,7 +230,7 @@ pp.jsxParseElementName = function() { pp.jsxParseAttributeValue = function() { switch (this.state.type) { case tt.braceL: - var node = this.jsxParseExpressionContainer(); + let node = this.jsxParseExpressionContainer(); if (node.expression.type === "JSXEmptyExpression") { this.raise(node.start, "JSX attributes must only be assigned a non-empty expression"); } else { @@ -239,7 +239,9 @@ pp.jsxParseAttributeValue = function() { case tt.jsxTagStart: case tt.string: - return this.parseExprAtom(); + let node = this.parseExprAtom(); + node.rawValue = null; + return node; default: this.raise(this.state.start, "JSX value should be either an expression or a quoted JSX text"); diff --git a/packages/babylon/test/fixtures/jsx/basic/18/expected.json b/packages/babylon/test/fixtures/jsx/basic/18/expected.json index 9b855ee2d4..d1b336d98a 100644 --- a/packages/babylon/test/fixtures/jsx/basic/18/expected.json +++ b/packages/babylon/test/fixtures/jsx/basic/18/expected.json @@ -147,7 +147,7 @@ } }, "value": "attribute", - "rawValue": "attribute", + "rawValue": null, "raw": "\"attribute\"" } } @@ -175,6 +175,5 @@ } } ] - }, - "comments": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/jsx/basic/19/expected.json b/packages/babylon/test/fixtures/jsx/basic/19/expected.json index 2df390efdf..bce1bcea7f 100644 --- a/packages/babylon/test/fixtures/jsx/basic/19/expected.json +++ b/packages/babylon/test/fixtures/jsx/basic/19/expected.json @@ -116,7 +116,7 @@ } }, "value": "leading", - "rawValue": "leading", + "rawValue": null, "raw": "\"leading\"" } }, @@ -165,7 +165,7 @@ } }, "value": "attribute", - "rawValue": "attribute", + "rawValue": null, "raw": "\"attribute\"" } }, @@ -254,6 +254,5 @@ } } ] - }, - "comments": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/jsx/basic/3/expected.json b/packages/babylon/test/fixtures/jsx/basic/3/expected.json index 164af0ff03..0f475db901 100644 --- a/packages/babylon/test/fixtures/jsx/basic/3/expected.json +++ b/packages/babylon/test/fixtures/jsx/basic/3/expected.json @@ -147,7 +147,7 @@ } }, "value": "bar", - "rawValue": "bar", + "rawValue": null, "raw": "\"bar\"" } } diff --git a/packages/babylon/test/fixtures/jsx/basic/4/expected.json b/packages/babylon/test/fixtures/jsx/basic/4/expected.json index 7ddfe6f7d3..7d7feea21e 100644 --- a/packages/babylon/test/fixtures/jsx/basic/4/expected.json +++ b/packages/babylon/test/fixtures/jsx/basic/4/expected.json @@ -180,7 +180,7 @@ } }, "value": " ", - "rawValue": " ", + "rawValue": null, "raw": "\" \"" } }, @@ -229,7 +229,7 @@ } }, "value": "&", - "rawValue": "&", + "rawValue": null, "raw": "\"&\"" } }, @@ -278,7 +278,7 @@ } }, "value": "&r;", - "rawValue": "&r;", + "rawValue": null, "raw": "\"&r;\"" } } @@ -306,6 +306,5 @@ } } ] - }, - "comments": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/jsx/basic/7/expected.json b/packages/babylon/test/fixtures/jsx/basic/7/expected.json index 7aaa7e9e26..86927f63d6 100644 --- a/packages/babylon/test/fixtures/jsx/basic/7/expected.json +++ b/packages/babylon/test/fixtures/jsx/basic/7/expected.json @@ -116,7 +116,7 @@ } }, "value": "&&", - "rawValue": "&&", + "rawValue": null, "raw": "\"&&\"" } } diff --git a/packages/babylon/test/fixtures/jsx/regression/1/expected.json b/packages/babylon/test/fixtures/jsx/regression/1/expected.json index 399ec66e40..5a09d6bfde 100644 --- a/packages/babylon/test/fixtures/jsx/regression/1/expected.json +++ b/packages/babylon/test/fixtures/jsx/regression/1/expected.json @@ -213,7 +213,7 @@ } }, "value": "test", - "rawValue": "test", + "rawValue": null, "raw": "\"test\"" } } diff --git a/packages/babylon/test/fixtures/jsx/regression/6/expected.json b/packages/babylon/test/fixtures/jsx/regression/6/expected.json index b259bfb717..dda6e404ca 100644 --- a/packages/babylon/test/fixtures/jsx/regression/6/expected.json +++ b/packages/babylon/test/fixtures/jsx/regression/6/expected.json @@ -116,7 +116,7 @@ } }, "value": "leading", - "rawValue": "leading", + "rawValue": null, "raw": "\"leading\"" } }, @@ -175,6 +175,5 @@ } } ] - }, - "comments": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/jsx/regression/7/expected.json b/packages/babylon/test/fixtures/jsx/regression/7/expected.json index 3025ad61b6..a37ebed7c8 100644 --- a/packages/babylon/test/fixtures/jsx/regression/7/expected.json +++ b/packages/babylon/test/fixtures/jsx/regression/7/expected.json @@ -116,7 +116,7 @@ } }, "value": "M230 80\n\t\tA 45 45, 0, 1, 0, 275 125\n L 275 80 Z", - "rawValue": "M230 80\n\t\tA 45 45, 0, 1, 0, 275 125\n L 275 80 Z", + "rawValue": null, "raw": "\"M230 80\n\t\tA 45 45, 0, 1, 0, 275 125\n L 275 80 Z\"" } } @@ -144,6 +144,5 @@ } } ] - }, - "comments": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/jsx/regression/issue-2114/actual.js b/packages/babylon/test/fixtures/jsx/regression/issue-2114/actual.js new file mode 100644 index 0000000000..372597f2a0 --- /dev/null +++ b/packages/babylon/test/fixtures/jsx/regression/issue-2114/actual.js @@ -0,0 +1 @@ +
; diff --git a/packages/babylon/test/fixtures/jsx/regression/issue-2114/expected.json b/packages/babylon/test/fixtures/jsx/regression/issue-2114/expected.json new file mode 100644 index 0000000000..9259331d8f --- /dev/null +++ b/packages/babylon/test/fixtures/jsx/regression/issue-2114/expected.json @@ -0,0 +1,178 @@ +{ + "type": "File", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "expression": { + "type": "JSXElement", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "attributes": [ + { + "type": "JSXAttribute", + "start": 5, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "name": { + "type": "JSXIdentifier", + "start": 5, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": "pattern" + }, + "value": { + "type": "Literal", + "start": 13, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "value": "^([\\w\\.\\-]+\\s)*[\\w\\.\\-]+\\s?$", + "rawValue": null, + "raw": "\"^([\\w\\.\\-]+\\s)*[\\w\\.\\-]+\\s?$\"" + } + } + ], + "name": { + "type": "JSXIdentifier", + "start": 1, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "name": "div" + }, + "selfClosing": false + }, + "closingElement": { + "type": "JSXClosingElement", + "start": 44, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "name": { + "type": "JSXIdentifier", + "start": 46, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 46 + }, + "end": { + "line": 1, + "column": 49 + } + }, + "name": "div" + } + }, + "children": [] + } + } + ] + } +} \ No newline at end of file