mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #31480 from andrewbranch/bug/25487
Fix invalid JSXExpressions having identifier-ish things in their trivia, improve error messages for comma expressions in JSX
This commit is contained in:
@@ -20033,6 +20033,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkJsxExpression(node: JsxExpression, checkMode?: CheckMode) {
|
||||
checkGrammarJsxExpression(node);
|
||||
if (node.expression) {
|
||||
const type = checkExpression(node.expression, checkMode);
|
||||
if (node.dotDotDotToken && type !== anyType && !isArrayType(type)) {
|
||||
@@ -31912,6 +31913,12 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarJsxExpression(node: JsxExpression) {
|
||||
if (node.expression && isCommaSequence(node.expression)) {
|
||||
return grammarErrorOnNode(node.expression, Diagnostics.JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array);
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarForInOrForOfStatement(forInOrOfStatement: ForInOrOfStatement): boolean {
|
||||
if (checkGrammarStatementInAmbientContext(forInOrOfStatement)) {
|
||||
return true;
|
||||
|
||||
@@ -5009,5 +5009,9 @@
|
||||
"Classes may not have a field named 'constructor'.": {
|
||||
"category": "Error",
|
||||
"code": 18006
|
||||
},
|
||||
"JSX expressions may not use the comma operator. Did you mean to write an array?": {
|
||||
"category": "Error",
|
||||
"code": 18007
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4430,14 +4430,18 @@ namespace ts {
|
||||
|
||||
if (token() !== SyntaxKind.CloseBraceToken) {
|
||||
node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
|
||||
node.expression = parseAssignmentExpressionOrHigher();
|
||||
// Only an AssignmentExpression is valid here per the JSX spec,
|
||||
// but we can unambiguously parse a comma sequence and provide
|
||||
// a better error message in grammar checking.
|
||||
node.expression = parseExpression();
|
||||
}
|
||||
if (inExpressionContext) {
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
}
|
||||
else {
|
||||
parseExpected(SyntaxKind.CloseBraceToken, /*message*/ undefined, /*shouldAdvance*/ false);
|
||||
scanJsxText();
|
||||
if (parseExpected(SyntaxKind.CloseBraceToken, /*message*/ undefined, /*shouldAdvance*/ false)) {
|
||||
scanJsxText();
|
||||
}
|
||||
}
|
||||
|
||||
return finishNode(node);
|
||||
|
||||
Reference in New Issue
Block a user