Improve JSX braces context handling.

This commit is contained in:
Ingvar Stepanyan 2015-01-25 00:33:03 +02:00
parent e93b69d595
commit 719ecbd203
2 changed files with 51 additions and 7 deletions

View File

@ -653,10 +653,6 @@
return true;
if (prevType == _braceL)
return curTokContext() === b_stat;
if (prevType === _jsxTagEnd || prevType === _jsxText)
return true;
if (prevType === _jsxName)
return false;
return !tokExprAllowed;
}
@ -676,8 +672,6 @@
if (type === _parenR || type === _braceR) {
var out = tokContext.pop();
if (out === b_tmpl) {
preserveSpace = true;
} else if (curTokContext() === j_expr) {
preserveSpace = tokExprAllowed = true;
} else if (out === b_stat && curTokContext() === f_expr) {
tokContext.pop();
@ -686,7 +680,11 @@
tokExprAllowed = !(out && out.isExpr);
}
} else if (type === _braceL) {
tokContext.push(braceIsBlock(prevType) ? b_stat : b_expr);
switch (curTokContext()) {
case j_oTag: tokContext.push(b_expr); break;
case j_expr: tokContext.push(b_tmpl); break;
default: tokContext.push(braceIsBlock(prevType) ? b_stat : b_expr);
}
tokExprAllowed = true;
} else if (type === _dollarBraceL) {
tokContext.push(b_tmpl);

View File

@ -3541,6 +3541,52 @@ var fbTestFixture = {
}
]
}
},
'<div pre="leading" {...props} />': {
type: "ExpressionStatement",
range: [0, 32],
expression: {
type: "JSXElement",
range: [0, 32],
openingElement: {
type: "JSXOpeningElement",
range: [0, 32],
attributes: [
{
type: "JSXAttribute",
range: [5, 18],
name: {
type: "JSXIdentifier",
range: [5, 8],
name: "pre"
},
value: {
type: "Literal",
range: [9, 18],
value: "leading"
}
},
{
type: "JSXSpreadAttribute",
range: [19, 29],
argument: {
type: "Identifier",
range: [23, 28],
name: "props"
}
}
],
name: {
type: "JSXIdentifier",
range: [1, 4],
name: "div"
},
selfClosing: true
},
closingElement: null,
children: []
}
}
}
};