-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Better error recovery for adjacent JSX elements in expression positions #5295
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
Merged
RyanCavanaugh
merged 1 commit into
microsoft:master
from
RyanCavanaugh:detectAdjacentJsxElements
Oct 20, 2015
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
tests/cases/conformance/jsx/file1.tsx(6,1): error TS2657: JSX expressions must have one parent element | ||
tests/cases/conformance/jsx/file2.tsx(2,1): error TS2657: JSX expressions must have one parent element | ||
|
||
|
||
==== tests/cases/conformance/jsx/file1.tsx (1 errors) ==== | ||
|
||
declare namespace JSX { interface Element { } } | ||
|
||
<div></div> | ||
<div></div> | ||
|
||
|
||
!!! error TS2657: JSX expressions must have one parent element | ||
==== tests/cases/conformance/jsx/file2.tsx (1 errors) ==== | ||
var x = <div></div><div></div> | ||
|
||
|
||
!!! error TS2657: JSX expressions must have one parent element |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//// [tests/cases/conformance/jsx/tsxErrorRecovery2.tsx] //// | ||
|
||
//// [file1.tsx] | ||
|
||
declare namespace JSX { interface Element { } } | ||
|
||
<div></div> | ||
<div></div> | ||
|
||
//// [file2.tsx] | ||
var x = <div></div><div></div> | ||
|
||
|
||
//// [file1.jsx] | ||
<div></div> | ||
, | ||
<div></div>; | ||
//// [file2.jsx] | ||
var x = <div></div>, <div></div>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
tests/cases/conformance/jsx/file1.tsx(4,2): error TS2304: Cannot find name 'React'. | ||
tests/cases/conformance/jsx/file1.tsx(5,2): error TS2304: Cannot find name 'React'. | ||
tests/cases/conformance/jsx/file1.tsx(6,1): error TS2657: JSX expressions must have one parent element | ||
tests/cases/conformance/jsx/file2.tsx(1,10): error TS2304: Cannot find name 'React'. | ||
tests/cases/conformance/jsx/file2.tsx(1,21): error TS2304: Cannot find name 'React'. | ||
tests/cases/conformance/jsx/file2.tsx(2,1): error TS2657: JSX expressions must have one parent element | ||
|
||
|
||
==== tests/cases/conformance/jsx/file1.tsx (3 errors) ==== | ||
|
||
declare namespace JSX { interface Element { } } | ||
|
||
<div></div> | ||
~~~ | ||
!!! error TS2304: Cannot find name 'React'. | ||
<div></div> | ||
~~~ | ||
!!! error TS2304: Cannot find name 'React'. | ||
|
||
|
||
!!! error TS2657: JSX expressions must have one parent element | ||
==== tests/cases/conformance/jsx/file2.tsx (3 errors) ==== | ||
var x = <div></div><div></div> | ||
~~~ | ||
!!! error TS2304: Cannot find name 'React'. | ||
~~~ | ||
!!! error TS2304: Cannot find name 'React'. | ||
|
||
|
||
!!! error TS2657: JSX expressions must have one parent element |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//// [tests/cases/conformance/jsx/tsxErrorRecovery3.tsx] //// | ||
|
||
//// [file1.tsx] | ||
|
||
declare namespace JSX { interface Element { } } | ||
|
||
<div></div> | ||
<div></div> | ||
|
||
//// [file2.tsx] | ||
var x = <div></div><div></div> | ||
|
||
|
||
//// [file1.js] | ||
React.createElement("div", null) | ||
, | ||
React.createElement("div", null); | ||
//// [file2.js] | ||
var x = React.createElement("div", null), React.createElement("div", null); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//@jsx: preserve | ||
|
||
//@filename: file1.tsx | ||
declare namespace JSX { interface Element { } } | ||
|
||
<div></div> | ||
<div></div> | ||
|
||
//@filename: file2.tsx | ||
var x = <div></div><div></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//@jsx: react | ||
|
||
//@filename: file1.tsx | ||
declare namespace JSX { interface Element { } } | ||
|
||
<div></div> | ||
<div></div> | ||
|
||
//@filename: file2.tsx | ||
var x = <div></div><div></div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is this
,
comes from synthesized missing node?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.
Correct
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.
interesting, I didn't realize that we print missing nodes. In this case I'm not sure that user would expect to see it - this is our internal recovery strategy and I don' think it should leak outside. Maybe we should not emit missing nodes (since they are ...missed in the source code)
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.
This is consistent with what we've done for a while. For example if you write
we emit
As I've said before, I don't think emitting in the presence of syntax errors is a rational thing to do, but since we're doing it anyway, I think the code we emit should at least be syntactically valid (even if it makes guesses at the intent).