Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Accept an unwrapped tag as an attribute value #9

Merged
merged 1 commit into from
Jan 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -5374,6 +5374,8 @@ parseYieldExpression: true
'expression'
);
}
} else if (match('<')) {
value = parseXJSElement();
} else if (lookahead.type === Token.XJSText) {
value = delegate.createLiteral(lex());
} else {
Expand Down Expand Up @@ -5440,8 +5442,9 @@ parseYieldExpression: true
}

function parseXJSClosingElement() {
var name, origInXJSChild;
var name, origInXJSChild, origInXJSTag;
origInXJSChild = state.inXJSChild;
origInXJSTag = state.inXJSTag;
state.inXJSChild = false;
state.inXJSTag = true;
expect('<');
Expand All @@ -5451,15 +5454,16 @@ parseYieldExpression: true
// to be a valid token after >, it needs to know whether to look for a
// standard JS token or an XJS text node
state.inXJSChild = origInXJSChild;
state.inXJSTag = false;
state.inXJSTag = origInXJSTag;
expect('>');
return delegate.createXJSClosingElement(name);
}

function parseXJSOpeningElement() {
var name, attribute, attributes = [], selfClosing = false, origInXJSChild;
var name, attribute, attributes = [], selfClosing = false, origInXJSChild, origInXJSTag;

origInXJSChild = state.inXJSChild;
origInXJSTag = state.inXJSTag;
state.inXJSChild = false;
state.inXJSTag = true;

Expand All @@ -5473,7 +5477,7 @@ parseYieldExpression: true
attributes.push(parseXJSAttribute());
}

state.inXJSTag = false;
state.inXJSTag = origInXJSTag;

if (lookahead.value === '/') {
expect('/');
Expand All @@ -5491,9 +5495,10 @@ parseYieldExpression: true
}

function parseXJSElement() {
var openingElement, closingElement, children = [], origInXJSChild;
var openingElement, closingElement, children = [], origInXJSChild, origInXJSTag;

origInXJSChild = state.inXJSChild;
origInXJSTag = state.inXJSTag;
openingElement = parseXJSOpeningElement();

if (!openingElement.selfClosing) {
Expand All @@ -5507,6 +5512,7 @@ parseYieldExpression: true
children.push(parseXJSChild());
}
state.inXJSChild = origInXJSChild;
state.inXJSTag = origInXJSTag;
closingElement = parseXJSClosingElement();
if (closingElement.name.namespace !== openingElement.name.namespace || closingElement.name.name !== openingElement.name.name) {
throwError({}, Messages.ExpectedXJSClosingTag, openingElement.name.namespace ? openingElement.name.namespace + ':' + openingElement.name.name : openingElement.name.name);
Expand Down
309 changes: 309 additions & 0 deletions test/fbtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,315 @@ var fbTestFixture = {
column: 41
}
}
},

'<LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />': {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man...
Great test case, but let's hope I never have to read code that does this

"type": "ExpressionStatement",
"expression": {
"type": "XJSElement",
"openingElement": {
"type": "XJSOpeningElement",
"name": {
"type": "XJSIdentifier",
"name": "LeftRight",
"range": [
1,
10
],
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
}
}
},
"selfClosing": true,
"attributes": [
{
"type": "XJSAttribute",
"name": {
"type": "XJSIdentifier",
"name": "left",
"range": [
11,
15
],
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 15
}
}
},
"value": {
"type": "XJSElement",
"openingElement": {
"type": "XJSOpeningElement",
"name": {
"type": "XJSIdentifier",
"name": "a",
"range": [
17,
18
],
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 18
}
}
},
"selfClosing": true,
"attributes": [],
"range": [
16,
21
],
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 21
}
}
},
"children": [],
"range": [
16,
21
],
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 21
}
}
},
"range": [
11,
21
],
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 21
}
}
},
{
"type": "XJSAttribute",
"name": {
"type": "XJSIdentifier",
"name": "right",
"range": [
22,
27
],
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 27
}
}
},
"value": {
"type": "XJSElement",
"openingElement": {
"type": "XJSOpeningElement",
"name": {
"type": "XJSIdentifier",
"name": "b",
"range": [
29,
30
],
"loc": {
"start": {
"line": 1,
"column": 29
},
"end": {
"line": 1,
"column": 30
}
}
},
"selfClosing": false,
"attributes": [],
"range": [
28,
31
],
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 31
}
}
},
"closingElement": {
"type": "XJSClosingElement",
"name": {
"type": "XJSIdentifier",
"name": "b",
"range": [
52,
53
],
"loc": {
"start": {
"line": 1,
"column": 52
},
"end": {
"line": 1,
"column": 53
}
}
},
"range": [
50,
54
],
"loc": {
"start": {
"line": 1,
"column": 50
},
"end": {
"line": 1,
"column": 54
}
}
},
"children": [
{
"type": "Literal",
"value": "monkeys /> gorillas",
"raw": "monkeys /> gorillas",
"range": [
31,
50
],
"loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 1,
"column": 50
}
}
}
],
"range": [
28,
54
],
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 54
}
}
},
"range": [
22,
54
],
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 54
}
}
}
],
"range": [
0,
57
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 57
}
}
},
"children": [],
"range": [
0,
57
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 57
}
}
},
"range": [
0,
57
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 57
}
}
}
},

Expand Down