File tree Expand file tree Collapse file tree 7 files changed +46
-1
lines changed Expand file tree Collapse file tree 7 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -19850,6 +19850,7 @@ namespace ts {
19850
19850
}
19851
19851
19852
19852
function checkJsxExpression(node: JsxExpression, checkMode?: CheckMode) {
19853
+ checkGrammarJsxExpression(node);
19853
19854
if (node.expression) {
19854
19855
const type = checkExpression(node.expression, checkMode);
19855
19856
if (node.dotDotDotToken && type !== anyType && !isArrayType(type)) {
@@ -31658,6 +31659,12 @@ namespace ts {
31658
31659
}
31659
31660
}
31660
31661
31662
+ function checkGrammarJsxExpression(node: JsxExpression) {
31663
+ if (node.expression && isCommaSequence(node.expression)) {
31664
+ return grammarErrorOnNode(node.expression, Diagnostics.JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array);
31665
+ }
31666
+ }
31667
+
31661
31668
function checkGrammarForInOrForOfStatement(forInOrOfStatement: ForInOrOfStatement): boolean {
31662
31669
if (checkGrammarStatementInAmbientContext(forInOrOfStatement)) {
31663
31670
return true;
Original file line number Diff line number Diff line change 4986
4986
"Classes may not have a field named 'constructor'." : {
4987
4987
"category" : " Error" ,
4988
4988
"code" : 18006
4989
+ },
4990
+ "JSX expressions may not use the comma operator. Did you mean to write an array?" : {
4991
+ "category" : " Error" ,
4992
+ "code" : 18007
4989
4993
}
4990
4994
}
Original file line number Diff line number Diff line change @@ -4430,7 +4430,10 @@ namespace ts {
4430
4430
4431
4431
if ( token ( ) !== SyntaxKind . CloseBraceToken ) {
4432
4432
node . dotDotDotToken = parseOptionalToken ( SyntaxKind . DotDotDotToken ) ;
4433
- node . expression = parseAssignmentExpressionOrHigher ( ) ;
4433
+ // Only an AssignmentExpression is valid here per the JSX spec,
4434
+ // but we can unambiguously parse a comma sequence and provide
4435
+ // a better error message in grammar checking.
4436
+ node . expression = parseExpression ( ) ;
4434
4437
}
4435
4438
if ( inExpressionContext ) {
4436
4439
parseExpected ( SyntaxKind . CloseBraceToken ) ;
Original file line number Diff line number Diff line change @@ -582,6 +582,20 @@ namespace FourSlash {
582
582
} ) ;
583
583
}
584
584
585
+ public verifyErrorExistsAtRange ( range : Range , code : number ) {
586
+ const span = ts . createTextSpanFromRange ( range ) ;
587
+ const hasMatchingError = ts . some (
588
+ this . getDiagnostics ( range . fileName ) ,
589
+ ( { code, start, length } ) =>
590
+ code === code &&
591
+ ts . isNumber ( start ) && ts . isNumber ( length ) &&
592
+ ts . textSpansEqual ( span , { start, length } ) ) ;
593
+
594
+ if ( ! hasMatchingError ) {
595
+ this . raiseError ( `No error with code ${ code } found at provided range.` ) ;
596
+ }
597
+ }
598
+
585
599
public verifyNumberOfErrorsInCurrentFile ( expected : number ) {
586
600
const errors = this . getDiagnostics ( this . activeFile . fileName ) ;
587
601
const actual = errors . length ;
@@ -3968,6 +3982,10 @@ namespace FourSlashInterface {
3968
3982
this . state . verifyNoErrors ( ) ;
3969
3983
}
3970
3984
3985
+ public errorExistsAtRange ( range : FourSlash . Range , code : number ) {
3986
+ this . state . verifyErrorExistsAtRange ( range , code ) ;
3987
+ }
3988
+
3971
3989
public numberOfErrorsInCurrentFile ( expected : number ) {
3972
3990
this . state . verifyNumberOfErrorsInCurrentFile ( expected ) ;
3973
3991
}
Original file line number Diff line number Diff line change @@ -238,6 +238,7 @@ declare namespace FourSlashInterface {
238
238
signatureHelp ( ...options : VerifySignatureHelpOptions [ ] , ) : void ;
239
239
// Checks that there are no compile errors.
240
240
noErrors ( ) : void ;
241
+ errorExistsAtRange ( range : Range , code : number ) : void ;
241
242
numberOfErrorsInCurrentFile ( expected : number ) : void ;
242
243
baselineCurrentFileBreakpointLocations ( ) : void ;
243
244
baselineCurrentFileNameOrDottedNameSpans ( ) : void ;
Original file line number Diff line number Diff line change 4
4
////declare var React: any;
5
5
////declare var x: string;
6
6
////const a = <div>{<div />[|x|]}</div>
7
+ ////const b = <div x={<div />[|x|]} />
7
8
8
9
const range = test . ranges ( ) [ 0 ] ;
9
10
verify . getSyntacticDiagnostics ( [ {
Original file line number Diff line number Diff line change
1
+ /// <reference path="fourslash.ts" />
2
+
3
+ //@Filename : jsxExpressionWithCommaExpression.tsx
4
+ //@jsx : react
5
+ ////declare var React: any;
6
+ ////declare var x: string;
7
+ ////const a = <div x={[|x, x|]} />
8
+ ////const b = <div>{[|x, x|]}</div>
9
+
10
+ verify . getSyntacticDiagnostics ( [ ] ) ;
11
+ test . ranges ( ) . forEach ( range => verify . errorExistsAtRange ( range , 18006 ) ) ;
You can’t perform that action at this time.
0 commit comments