Improve JSX braces context handling.
This commit is contained in:
parent
e93b69d595
commit
719ecbd203
12
acorn.js
12
acorn.js
@ -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);
|
||||
|
||||
@ -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: []
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user