clear rawValue from JSX attribute values as they're tokenised and parsed differently - fixes #2114

This commit is contained in:
Sebastian McKenzie 2015-07-29 16:15:47 +01:00
parent c43daa83df
commit 99d8dec04d
11 changed files with 199 additions and 23 deletions

View File

@ -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");

View File

@ -147,7 +147,7 @@
}
},
"value": "attribute",
"rawValue": "attribute",
"rawValue": null,
"raw": "\"attribute\""
}
}
@ -175,6 +175,5 @@
}
}
]
},
"comments": []
}
}

View File

@ -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": []
}
}

View File

@ -147,7 +147,7 @@
}
},
"value": "bar",
"rawValue": "bar",
"rawValue": null,
"raw": "\"bar\""
}
}

View File

@ -180,7 +180,7 @@
}
},
"value": " ",
"rawValue": " ",
"rawValue": null,
"raw": "\" \""
}
},
@ -229,7 +229,7 @@
}
},
"value": "&",
"rawValue": "&",
"rawValue": null,
"raw": "\"&\""
}
},
@ -278,7 +278,7 @@
}
},
"value": "&ampr;",
"rawValue": "&ampr;",
"rawValue": null,
"raw": "\"&ampr;\""
}
}
@ -306,6 +306,5 @@
}
}
]
},
"comments": []
}
}

View File

@ -116,7 +116,7 @@
}
},
"value": "&&",
"rawValue": "&&",
"rawValue": null,
"raw": "\"&&\""
}
}

View File

@ -213,7 +213,7 @@
}
},
"value": "test",
"rawValue": "test",
"rawValue": null,
"raw": "\"test\""
}
}

View File

@ -116,7 +116,7 @@
}
},
"value": "leading",
"rawValue": "leading",
"rawValue": null,
"raw": "\"leading\""
}
},
@ -175,6 +175,5 @@
}
}
]
},
"comments": []
}
}

View File

@ -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": []
}
}

View File

@ -0,0 +1 @@
<div pattern="^([\w\.\-]+\s)*[\w\.\-]+\s?$"></div>;

View 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": []
}
}
]
}
}