-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix invalid JSXExpressions having identifier-ish things in their trivia, improve error messages for comma expressions in JSX #31480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
422b541
0a3c755
897e10a
77a76c1
feaef9c
2856aab
52894cf
ad9c36e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,18 +28,21 @@ var foo = /** @class */ (function () { | |
return foo; | ||
}()); | ||
var x; | ||
x = <any> {test} <any></any> }; | ||
x = <any> {test}: <any></any> }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The TypeScript generating this was |
||
|
||
x = <any><any></any>; | ||
|
||
x = <foo>hello {<foo>} </foo>} | ||
x = <foo>hello {<foo>} </foo>}; | ||
|
||
x = <foo test={<foo>}>hello</foo>}/> | ||
|
||
x = <foo test={<foo>}>hello{<foo>}</foo>} | ||
x = <foo test={<foo>}>hello{<foo>}</foo>}; | ||
|
||
x = <foo>x</foo>, x = <foo />; | ||
|
||
<foo>{<foo><foo>{/foo/.test(x) ? <foo><foo></foo> : <foo><foo></foo>}</foo>}</foo> | ||
: | ||
}</></>}</></>}/></></></>; | ||
} | ||
|
||
|
||
</></>}</></>}/></></></>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,7 @@ var x = <div>one</div>, <div>two</div>; | |
var x = <div>one</div> /* intervening comment */, /* intervening comment */ <div>two</div>; | ||
; | ||
//// [20.jsx] | ||
<a>{"str"}}</a>; | ||
<a>{"str"};}</a>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is weird, but barely weirder than the previous |
||
//// [21.jsx] | ||
<span className="a" id="b"/>; | ||
//// [22.jsx] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
tests/cases/conformance/jsx/file.tsx(11,36): error TS1005: '}' expected. | ||
tests/cases/conformance/jsx/file.tsx(11,44): error TS1003: Identifier expected. | ||
tests/cases/conformance/jsx/file.tsx(11,46): error TS1161: Unterminated regular expression literal. | ||
tests/cases/conformance/jsx/file.tsx(11,30): error TS2695: Left side of comma operator is unused and has no side effects. | ||
tests/cases/conformance/jsx/file.tsx(11,30): error TS18007: JSX expressions may not use the comma operator. Did you mean to write an array? | ||
|
||
|
||
==== tests/cases/conformance/jsx/file.tsx (3 errors) ==== | ||
==== tests/cases/conformance/jsx/file.tsx (2 errors) ==== | ||
declare module JSX { | ||
interface Element { } | ||
interface IntrinsicElements { | ||
|
@@ -15,10 +14,8 @@ tests/cases/conformance/jsx/file.tsx(11,46): error TS1161: Unterminated regular | |
const class1 = "foo"; | ||
const class2 = "bar"; | ||
const elem = <div className={class1, class2}/>; | ||
~ | ||
!!! error TS1005: '}' expected. | ||
~ | ||
!!! error TS1003: Identifier expected. | ||
|
||
!!! error TS1161: Unterminated regular expression literal. | ||
~~~~~~ | ||
!!! error TS2695: Left side of comma operator is unused and has no side effects. | ||
~~~~~~~~~~~~~~ | ||
!!! error TS18007: JSX expressions may not use the comma operator. Did you mean to write an array? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two errors make a lot more sense to me than the previous three, although I could do without the first. I considered making the error range start on the comma operator instead of at the beginning of the expression. Thoughts? |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,4 @@ const elem = <div className={class1, class2}/>; | |
// This should be a parse error | ||
var class1 = "foo"; | ||
var class2 = "bar"; | ||
var elem = <div className={class1} class2/>; | ||
/>;; | ||
var elem = <div className={class1, class2}/>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This emit is invalid although slightly less so than the previous? We could potentially put these inside a ParenthesizedExpression, but we're already emitting a grammar error, and it seems like there's no requirement for the emit to be totally valid if the input wasn't totally valid. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
tests/cases/conformance/jsx/file.tsx(4,11): error TS17008: JSX element 'div' has no corresponding closing tag. | ||
tests/cases/conformance/jsx/file.tsx(4,19): error TS1109: Expression expected. | ||
tests/cases/conformance/jsx/file.tsx(7,11): error TS2304: Cannot find name 'a'. | ||
tests/cases/conformance/jsx/file.tsx(7,12): error TS1005: '}' expected. | ||
tests/cases/conformance/jsx/file.tsx(8,1): error TS1005: '</' expected. | ||
|
||
|
||
==== tests/cases/conformance/jsx/file.tsx (5 errors) ==== | ||
==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== | ||
declare namespace JSX { interface Element { } } | ||
|
||
function foo() { | ||
var x = <div> { </div> | ||
~~~ | ||
!!! error TS17008: JSX element 'div' has no corresponding closing tag. | ||
~~ | ||
!!! error TS1109: Expression expected. | ||
} | ||
// Shouldn't see any errors down here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we don't. I think this gets significantly better. |
||
var y = { a: 1 }; | ||
~ | ||
!!! error TS2304: Cannot find name 'a'. | ||
~ | ||
!!! error TS1005: '}' expected. | ||
|
||
|
||
!!! error TS1005: '</' expected. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//@Filename: jsxExpressionFollowedByIdentifier.tsx | ||
////declare var React: any; | ||
////const a = <div>{<div />[|x|]}</div> | ||
////const b = <div x={<div />[|x|]} /> | ||
|
||
test.ranges().forEach(range => { | ||
verify.errorExistsAtRange(range, ts.Diagnostics._0_expected.code, "'}' expected."); | ||
// This is just to ensure getting quick info doesn’t crash | ||
verify.not.quickInfoExists(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//@Filename: jsxExpressionWithCommaExpression.tsx | ||
//@jsx: react | ||
////declare var React: any; | ||
////declare var x: string; | ||
////const a = <div x={[|x, x|]} /> | ||
////const b = <div>{[|x, x|]}</div> | ||
|
||
verify.getSyntacticDiagnostics([]); | ||
test.ranges().forEach(range => verify.errorExistsAtRange(range, 18006)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we successfully parse something we know is illegal, is that always a grammar error, or is there ever a reason why that should be a parse error? I know a parse error will prevent the node from being reused incrementally—in this case the tree should be well-formed, so I think reusing it isn’t a problem.