clear rawValue from JSX attribute values as they're tokenised and parsed differently - fixes #2114
This commit is contained in:
parent
4945b8e6f6
commit
ffee5615e4
@ -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");
|
||||
|
||||
5
test/fixtures/jsx/basic/18/expected.json
vendored
5
test/fixtures/jsx/basic/18/expected.json
vendored
@ -147,7 +147,7 @@
|
||||
}
|
||||
},
|
||||
"value": "attribute",
|
||||
"rawValue": "attribute",
|
||||
"rawValue": null,
|
||||
"raw": "\"attribute\""
|
||||
}
|
||||
}
|
||||
@ -175,6 +175,5 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"comments": []
|
||||
}
|
||||
}
|
||||
7
test/fixtures/jsx/basic/19/expected.json
vendored
7
test/fixtures/jsx/basic/19/expected.json
vendored
@ -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": []
|
||||
}
|
||||
}
|
||||
2
test/fixtures/jsx/basic/3/expected.json
vendored
2
test/fixtures/jsx/basic/3/expected.json
vendored
@ -147,7 +147,7 @@
|
||||
}
|
||||
},
|
||||
"value": "bar",
|
||||
"rawValue": "bar",
|
||||
"rawValue": null,
|
||||
"raw": "\"bar\""
|
||||
}
|
||||
}
|
||||
|
||||
9
test/fixtures/jsx/basic/4/expected.json
vendored
9
test/fixtures/jsx/basic/4/expected.json
vendored
@ -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": []
|
||||
}
|
||||
}
|
||||
2
test/fixtures/jsx/basic/7/expected.json
vendored
2
test/fixtures/jsx/basic/7/expected.json
vendored
@ -116,7 +116,7 @@
|
||||
}
|
||||
},
|
||||
"value": "&&",
|
||||
"rawValue": "&&",
|
||||
"rawValue": null,
|
||||
"raw": "\"&&\""
|
||||
}
|
||||
}
|
||||
|
||||
2
test/fixtures/jsx/regression/1/expected.json
vendored
2
test/fixtures/jsx/regression/1/expected.json
vendored
@ -213,7 +213,7 @@
|
||||
}
|
||||
},
|
||||
"value": "test",
|
||||
"rawValue": "test",
|
||||
"rawValue": null,
|
||||
"raw": "\"test\""
|
||||
}
|
||||
}
|
||||
|
||||
5
test/fixtures/jsx/regression/6/expected.json
vendored
5
test/fixtures/jsx/regression/6/expected.json
vendored
@ -116,7 +116,7 @@
|
||||
}
|
||||
},
|
||||
"value": "leading",
|
||||
"rawValue": "leading",
|
||||
"rawValue": null,
|
||||
"raw": "\"leading\""
|
||||
}
|
||||
},
|
||||
@ -175,6 +175,5 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"comments": []
|
||||
}
|
||||
}
|
||||
5
test/fixtures/jsx/regression/7/expected.json
vendored
5
test/fixtures/jsx/regression/7/expected.json
vendored
@ -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": []
|
||||
}
|
||||
}
|
||||
1
test/fixtures/jsx/regression/issue-2114/actual.js
vendored
Normal file
1
test/fixtures/jsx/regression/issue-2114/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<div pattern="^([\w\.\-]+\s)*[\w\.\-]+\s?$"></div>;
|
||||
178
test/fixtures/jsx/regression/issue-2114/expected.json
vendored
Normal file
178
test/fixtures/jsx/regression/issue-2114/expected.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user