diff --git a/src/plugins/jsx/index.js b/src/plugins/jsx/index.js index c4e363ee35..49231318f4 100644 --- a/src/plugins/jsx/index.js +++ b/src/plugins/jsx/index.js @@ -247,9 +247,7 @@ pp.jsxParseAttributeValue = function() { case tt.jsxTagStart: case tt.string: - node = this.parseExprAtom(); - node.extra = null; - return node; + return this.parseExprAtom(); default: this.raise(this.state.start, "JSX value should be either an expression or a quoted JSX text"); @@ -401,10 +399,7 @@ export default function(instance) { instance.extend("parseExprAtom", function(inner) { return function(refShortHandDefaultPos) { if (this.match(tt.jsxText)) { - const node = this.parseLiteral(this.state.value, "JSXText"); - // https://github.com/babel/babel/issues/2078 - node.extra = null; - return node; + return this.parseLiteral(this.state.value, "JSXText"); } else if (this.match(tt.jsxTagStart)) { return this.jsxParseElement(); } else { diff --git a/test/fixtures/jsx/basic/11/expected.json b/test/fixtures/jsx/basic/11/expected.json index 28fdb031d2..04d9debf7f 100644 --- a/test/fixtures/jsx/basic/11/expected.json +++ b/test/fixtures/jsx/basic/11/expected.json @@ -135,7 +135,10 @@ "column": 18 } }, - "extra": null, + "extra": { + "rawValue": "@test content", + "raw": "@test content" + }, "value": "@test content" } ] diff --git a/test/fixtures/jsx/basic/12/expected.json b/test/fixtures/jsx/basic/12/expected.json index 6fd2dafebd..3dfab62bd7 100644 --- a/test/fixtures/jsx/basic/12/expected.json +++ b/test/fixtures/jsx/basic/12/expected.json @@ -185,7 +185,10 @@ "column": 35 } }, - "extra": null, + "extra": { + "rawValue": "7x invalid-js-identifier", + "raw": "7x invalid-js-identifier" + }, "value": "7x invalid-js-identifier" } ] diff --git a/test/fixtures/jsx/basic/13/expected.json b/test/fixtures/jsx/basic/13/expected.json index 33e3801372..63dd742439 100644 --- a/test/fixtures/jsx/basic/13/expected.json +++ b/test/fixtures/jsx/basic/13/expected.json @@ -149,8 +149,7 @@ "selfClosing": true }, "closingElement": null, - "children": [], - "extra": null + "children": [] } }, { @@ -276,11 +275,13 @@ "column": 50 } }, - "extra": null, + "extra": { + "rawValue": "monkeys /> gorillas", + "raw": "monkeys /> gorillas" + }, "value": "monkeys /> gorillas" } - ], - "extra": null + ] } } ], diff --git a/test/fixtures/jsx/basic/18/expected.json b/test/fixtures/jsx/basic/18/expected.json index ecbc6076b7..30be28155d 100644 --- a/test/fixtures/jsx/basic/18/expected.json +++ b/test/fixtures/jsx/basic/18/expected.json @@ -147,7 +147,10 @@ "column": 32 } }, - "extra": null, + "extra": { + "rawValue": "attribute", + "raw": "\"attribute\"" + }, "value": "attribute" } } diff --git a/test/fixtures/jsx/basic/19/expected.json b/test/fixtures/jsx/basic/19/expected.json index e18fa97fd0..eb742ee767 100644 --- a/test/fixtures/jsx/basic/19/expected.json +++ b/test/fixtures/jsx/basic/19/expected.json @@ -115,7 +115,10 @@ "column": 18 } }, - "extra": null, + "extra": { + "rawValue": "leading", + "raw": "\"leading\"" + }, "value": "leading" } }, @@ -163,7 +166,10 @@ "column": 35 } }, - "extra": null, + "extra": { + "rawValue": "attribute", + "raw": "\"attribute\"" + }, "value": "attribute" } }, diff --git a/test/fixtures/jsx/basic/21/expected.json b/test/fixtures/jsx/basic/21/expected.json index 25fba8ed09..2fa06f64c8 100644 --- a/test/fixtures/jsx/basic/21/expected.json +++ b/test/fixtures/jsx/basic/21/expected.json @@ -168,7 +168,10 @@ "column": 13 } }, - "extra": null, + "extra": { + "rawValue": " ", + "raw": " " + }, "value": " " }, { diff --git a/test/fixtures/jsx/basic/3/expected.json b/test/fixtures/jsx/basic/3/expected.json index 7fef3da7b3..e1b54a6b01 100644 --- a/test/fixtures/jsx/basic/3/expected.json +++ b/test/fixtures/jsx/basic/3/expected.json @@ -146,7 +146,10 @@ "column": 14 } }, - "extra": null, + "extra": { + "rawValue": "bar", + "raw": "\"bar\"" + }, "value": "bar" } } @@ -215,7 +218,10 @@ "column": 16 } }, - "extra": null, + "extra": { + "rawValue": " ", + "raw": " " + }, "value": " " }, { @@ -264,7 +270,10 @@ "column": 24 } }, - "extra": null, + "extra": { + "rawValue": " ", + "raw": " " + }, "value": " " }, { diff --git a/test/fixtures/jsx/basic/4/expected.json b/test/fixtures/jsx/basic/4/expected.json index 1c24bbb736..f0f895006b 100644 --- a/test/fixtures/jsx/basic/4/expected.json +++ b/test/fixtures/jsx/basic/4/expected.json @@ -181,7 +181,10 @@ "column": 16 } }, - "extra": null, + "extra": { + "rawValue": " ", + "raw": "\" \"" + }, "value": " " } }, @@ -229,7 +232,10 @@ "column": 26 } }, - "extra": null, + "extra": { + "rawValue": "&", + "raw": "\"&\"" + }, "value": "&" } }, @@ -277,7 +283,10 @@ "column": 37 } }, - "extra": null, + "extra": { + "rawValue": "&r;", + "raw": "\"&r;\"" + }, "value": "&r;" } } diff --git a/test/fixtures/jsx/basic/7/expected.json b/test/fixtures/jsx/basic/7/expected.json index 154626c2da..95d6016840 100644 --- a/test/fixtures/jsx/basic/7/expected.json +++ b/test/fixtures/jsx/basic/7/expected.json @@ -115,7 +115,10 @@ "column": 22 } }, - "extra": null, + "extra": { + "rawValue": "&&", + "raw": "\"&&\"" + }, "value": "&&" } } @@ -184,7 +187,10 @@ "column": 0 } }, - "extra": null, + "extra": { + "rawValue": "\nbar\nbaz\n", + "raw": "\nbar\nbaz\n" + }, "value": "\nbar\nbaz\n" } ] diff --git a/test/fixtures/jsx/basic/entity/expected.json b/test/fixtures/jsx/basic/entity/expected.json index 69f4b59ea6..e95455df4c 100644 --- a/test/fixtures/jsx/basic/entity/expected.json +++ b/test/fixtures/jsx/basic/entity/expected.json @@ -135,7 +135,10 @@ "column": 12 } }, - "extra": null, + "extra": { + "rawValue": "💩", + "raw": "💩" + }, "value": "💩" } ] diff --git a/test/fixtures/jsx/basic/nonentity-decimal/expected.json b/test/fixtures/jsx/basic/nonentity-decimal/expected.json index 8ddb29c276..50a5f67c5a 100644 --- a/test/fixtures/jsx/basic/nonentity-decimal/expected.json +++ b/test/fixtures/jsx/basic/nonentity-decimal/expected.json @@ -135,7 +135,10 @@ "column": 11 } }, - "extra": null, + "extra": { + "rawValue": "f4a9;", + "raw": "f4a9;" + }, "value": "f4a9;" } ] diff --git a/test/fixtures/jsx/basic/nonentity/expected.json b/test/fixtures/jsx/basic/nonentity/expected.json index 7d91ec929e..9b6cf134af 100644 --- a/test/fixtures/jsx/basic/nonentity/expected.json +++ b/test/fixtures/jsx/basic/nonentity/expected.json @@ -135,7 +135,10 @@ "column": 12 } }, - "extra": null, + "extra": { + "rawValue": "g4q9;", + "raw": "g4q9;" + }, "value": "g4q9;" } ] diff --git a/test/fixtures/jsx/regression/1/expected.json b/test/fixtures/jsx/regression/1/expected.json index 568a15f9e9..aadc50ad85 100644 --- a/test/fixtures/jsx/regression/1/expected.json +++ b/test/fixtures/jsx/regression/1/expected.json @@ -135,7 +135,10 @@ "column": 7 } }, - "extra": null, + "extra": { + "rawValue": "foo ", + "raw": "foo " + }, "value": "foo " }, { @@ -211,7 +214,10 @@ "column": 21 } }, - "extra": null, + "extra": { + "rawValue": "test", + "raw": "\"test\"" + }, "value": "test" } } @@ -280,7 +286,10 @@ "column": 26 } }, - "extra": null, + "extra": { + "rawValue": " bar", + "raw": " bar" + }, "value": " bar" } ] @@ -299,7 +308,10 @@ "column": 34 } }, - "extra": null, + "extra": { + "rawValue": " baz", + "raw": " baz" + }, "value": " baz" } ] diff --git a/test/fixtures/jsx/regression/4/expected.json b/test/fixtures/jsx/regression/4/expected.json index 6e86caee9b..4479b6debd 100644 --- a/test/fixtures/jsx/regression/4/expected.json +++ b/test/fixtures/jsx/regression/4/expected.json @@ -135,7 +135,10 @@ "column": 10 } }, - "extra": null, + "extra": { + "rawValue": "/text", + "raw": "/text" + }, "value": "/text" } ] diff --git a/test/fixtures/jsx/regression/6/expected.json b/test/fixtures/jsx/regression/6/expected.json index fbfd450b91..acd021ff39 100644 --- a/test/fixtures/jsx/regression/6/expected.json +++ b/test/fixtures/jsx/regression/6/expected.json @@ -115,7 +115,10 @@ "column": 18 } }, - "extra": null, + "extra": { + "rawValue": "leading", + "raw": "\"leading\"" + }, "value": "leading" } }, diff --git a/test/fixtures/jsx/regression/7/expected.json b/test/fixtures/jsx/regression/7/expected.json index d82ea9606a..fc8f6720e2 100644 --- a/test/fixtures/jsx/regression/7/expected.json +++ b/test/fixtures/jsx/regression/7/expected.json @@ -115,7 +115,10 @@ "column": 15 } }, - "extra": null, + "extra": { + "rawValue": "M230 80\n\t\tA 45 45, 0, 1, 0, 275 125\n L 275 80 Z", + "raw": "\"M230 80\n\t\tA 45 45, 0, 1, 0, 275 125\n L 275 80 Z\"" + }, "value": "M230 80\n\t\tA 45 45, 0, 1, 0, 275 125\n L 275 80 Z" } } diff --git a/test/fixtures/jsx/regression/issue-2114/expected.json b/test/fixtures/jsx/regression/issue-2114/expected.json index 15b1d87259..6abcb37004 100644 --- a/test/fixtures/jsx/regression/issue-2114/expected.json +++ b/test/fixtures/jsx/regression/issue-2114/expected.json @@ -115,7 +115,10 @@ "column": 43 } }, - "extra": null, + "extra": { + "rawValue": "^([\\w\\.\\-]+\\s)*[\\w\\.\\-]+\\s?$", + "raw": "\"^([\\w\\.\\-]+\\s)*[\\w\\.\\-]+\\s?$\"" + }, "value": "^([\\w\\.\\-]+\\s)*[\\w\\.\\-]+\\s?$" } } diff --git a/test/fixtures/jsx/regression/nbsp/actual.js b/test/fixtures/jsx/regression/nbsp/actual.js new file mode 100644 index 0000000000..e6b2eb47be --- /dev/null +++ b/test/fixtures/jsx/regression/nbsp/actual.js @@ -0,0 +1 @@ +
 
diff --git a/test/fixtures/jsx/regression/nbsp/expected.json b/test/fixtures/jsx/regression/nbsp/expected.json new file mode 100644 index 0000000000..32e90c742f --- /dev/null +++ b/test/fixtures/jsx/regression/nbsp/expected.json @@ -0,0 +1,150 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "expression": { + "type": "JSXElement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "attributes": [], + "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": 11, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "JSXIdentifier", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "name": "div" + } + }, + "children": [ + { + "type": "JSXText", + "start": 5, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "extra": { + "rawValue": " ", + "raw": " " + }, + "value": " " + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file