Add extra.raw back to JSXText and JSXAttribute (#344)
This commit is contained in:
parent
14b7f50e51
commit
cbf4203237
@ -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 {
|
||||
|
||||
5
test/fixtures/jsx/basic/11/expected.json
vendored
5
test/fixtures/jsx/basic/11/expected.json
vendored
@ -135,7 +135,10 @@
|
||||
"column": 18
|
||||
}
|
||||
},
|
||||
"extra": null,
|
||||
"extra": {
|
||||
"rawValue": "@test content",
|
||||
"raw": "@test content"
|
||||
},
|
||||
"value": "@test content"
|
||||
}
|
||||
]
|
||||
|
||||
5
test/fixtures/jsx/basic/12/expected.json
vendored
5
test/fixtures/jsx/basic/12/expected.json
vendored
@ -185,7 +185,10 @@
|
||||
"column": 35
|
||||
}
|
||||
},
|
||||
"extra": null,
|
||||
"extra": {
|
||||
"rawValue": "7x invalid-js-identifier",
|
||||
"raw": "7x invalid-js-identifier"
|
||||
},
|
||||
"value": "7x invalid-js-identifier"
|
||||
}
|
||||
]
|
||||
|
||||
11
test/fixtures/jsx/basic/13/expected.json
vendored
11
test/fixtures/jsx/basic/13/expected.json
vendored
@ -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
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
5
test/fixtures/jsx/basic/18/expected.json
vendored
5
test/fixtures/jsx/basic/18/expected.json
vendored
@ -147,7 +147,10 @@
|
||||
"column": 32
|
||||
}
|
||||
},
|
||||
"extra": null,
|
||||
"extra": {
|
||||
"rawValue": "attribute",
|
||||
"raw": "\"attribute\""
|
||||
},
|
||||
"value": "attribute"
|
||||
}
|
||||
}
|
||||
|
||||
10
test/fixtures/jsx/basic/19/expected.json
vendored
10
test/fixtures/jsx/basic/19/expected.json
vendored
@ -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"
|
||||
}
|
||||
},
|
||||
|
||||
5
test/fixtures/jsx/basic/21/expected.json
vendored
5
test/fixtures/jsx/basic/21/expected.json
vendored
@ -168,7 +168,10 @@
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"extra": null,
|
||||
"extra": {
|
||||
"rawValue": " ",
|
||||
"raw": " "
|
||||
},
|
||||
"value": " "
|
||||
},
|
||||
{
|
||||
|
||||
15
test/fixtures/jsx/basic/3/expected.json
vendored
15
test/fixtures/jsx/basic/3/expected.json
vendored
@ -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": " "
|
||||
},
|
||||
{
|
||||
|
||||
15
test/fixtures/jsx/basic/4/expected.json
vendored
15
test/fixtures/jsx/basic/4/expected.json
vendored
@ -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;"
|
||||
}
|
||||
}
|
||||
|
||||
10
test/fixtures/jsx/basic/7/expected.json
vendored
10
test/fixtures/jsx/basic/7/expected.json
vendored
@ -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"
|
||||
}
|
||||
]
|
||||
|
||||
5
test/fixtures/jsx/basic/entity/expected.json
vendored
5
test/fixtures/jsx/basic/entity/expected.json
vendored
@ -135,7 +135,10 @@
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"extra": null,
|
||||
"extra": {
|
||||
"rawValue": "💩",
|
||||
"raw": "💩"
|
||||
},
|
||||
"value": "💩"
|
||||
}
|
||||
]
|
||||
|
||||
@ -135,7 +135,10 @@
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"extra": null,
|
||||
"extra": {
|
||||
"rawValue": "f4a9;",
|
||||
"raw": "f4a9;"
|
||||
},
|
||||
"value": "f4a9;"
|
||||
}
|
||||
]
|
||||
|
||||
@ -135,7 +135,10 @@
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"extra": null,
|
||||
"extra": {
|
||||
"rawValue": "g4q9;",
|
||||
"raw": "g4q9;"
|
||||
},
|
||||
"value": "g4q9;"
|
||||
}
|
||||
]
|
||||
|
||||
20
test/fixtures/jsx/regression/1/expected.json
vendored
20
test/fixtures/jsx/regression/1/expected.json
vendored
@ -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"
|
||||
}
|
||||
]
|
||||
|
||||
5
test/fixtures/jsx/regression/4/expected.json
vendored
5
test/fixtures/jsx/regression/4/expected.json
vendored
@ -135,7 +135,10 @@
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"extra": null,
|
||||
"extra": {
|
||||
"rawValue": "/text",
|
||||
"raw": "/text"
|
||||
},
|
||||
"value": "/text"
|
||||
}
|
||||
]
|
||||
|
||||
5
test/fixtures/jsx/regression/6/expected.json
vendored
5
test/fixtures/jsx/regression/6/expected.json
vendored
@ -115,7 +115,10 @@
|
||||
"column": 18
|
||||
}
|
||||
},
|
||||
"extra": null,
|
||||
"extra": {
|
||||
"rawValue": "leading",
|
||||
"raw": "\"leading\""
|
||||
},
|
||||
"value": "leading"
|
||||
}
|
||||
},
|
||||
|
||||
5
test/fixtures/jsx/regression/7/expected.json
vendored
5
test/fixtures/jsx/regression/7/expected.json
vendored
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,7 +115,10 @@
|
||||
"column": 43
|
||||
}
|
||||
},
|
||||
"extra": null,
|
||||
"extra": {
|
||||
"rawValue": "^([\\w\\.\\-]+\\s)*[\\w\\.\\-]+\\s?$",
|
||||
"raw": "\"^([\\w\\.\\-]+\\s)*[\\w\\.\\-]+\\s?$\""
|
||||
},
|
||||
"value": "^([\\w\\.\\-]+\\s)*[\\w\\.\\-]+\\s?$"
|
||||
}
|
||||
}
|
||||
|
||||
1
test/fixtures/jsx/regression/nbsp/actual.js
vendored
Normal file
1
test/fixtures/jsx/regression/nbsp/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<div> </div>
|
||||
150
test/fixtures/jsx/regression/nbsp/expected.json
vendored
Normal file
150
test/fixtures/jsx/regression/nbsp/expected.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user