[babel 8] Disallow sequence expressions in JSX expression containers (#12447)
* jsx: fix sequence expression at JSXAttributeValue (#8787) * jsx: fix sequence expression at JSXAttributeValue * Change logic for detecting unparenthesized expressions * use parseMaybeAssign instead of custom error handling Co-authored-by: Daniel Tschinder <daniel@tschinder.de> Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com> * I'm not good at booleans * Format * Throw a recoverable error Co-authored-by: Bruno Macabeus <macabeus@users.noreply.github.com> Co-authored-by: Daniel Tschinder <daniel@tschinder.de>
This commit is contained in:
@@ -24,6 +24,8 @@ const JsxErrors = Object.freeze({
|
||||
"JSX attributes must only be assigned a non-empty expression",
|
||||
MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>",
|
||||
MissingClosingTagElement: "Expected corresponding JSX closing tag for <%0>",
|
||||
UnexpectedSequenceExpression:
|
||||
"Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
|
||||
UnsupportedJsxValue:
|
||||
"JSX value should be either an expression or a quoted JSX text",
|
||||
UnterminatedJsxContent: "Unterminated JSX contents",
|
||||
@@ -344,9 +346,24 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
if (this.match(tt.braceR)) {
|
||||
node.expression = this.jsxParseEmptyExpression();
|
||||
} else {
|
||||
node.expression = this.parseExpression();
|
||||
const expression = this.parseExpression();
|
||||
|
||||
if (process.env.BABEL_8_BREAKING) {
|
||||
if (
|
||||
expression.type === "SequenceExpression" &&
|
||||
!expression.extra?.parenthesized
|
||||
) {
|
||||
this.raise(
|
||||
expression.expressions[1].start,
|
||||
JsxErrors.UnexpectedSequenceExpression,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
node.expression = expression;
|
||||
}
|
||||
this.expect(tt.braceR);
|
||||
|
||||
return this.finishNode(node, "JSXExpressionContainer");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user