-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Under jsx: preserve, actually preserve expressions which contain only comments #41757
Merged
weswigham
merged 2 commits into
microsoft:master
from
weswigham:fix-jsx-preserve-comment-emit
Dec 18, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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
44 changes: 44 additions & 0 deletions
44
...baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).js
This file contains 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,44 @@ | ||
//// [commentsOnJSXExpressionsArePreserved.tsx] | ||
// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs | ||
namespace JSX {} | ||
class Component { | ||
render() { | ||
return <div> | ||
{/* missing */} | ||
{null/* preserved */} | ||
{ | ||
// ??? 1 | ||
} | ||
{ // ??? 2 | ||
} | ||
{// ??? 3 | ||
} | ||
{ | ||
// ??? 4 | ||
/* ??? 5 */} | ||
</div>; | ||
} | ||
} | ||
|
||
//// [commentsOnJSXExpressionsArePreserved.jsx] | ||
var Component = /** @class */ (function () { | ||
function Component() { | ||
} | ||
Component.prototype.render = function () { | ||
return <div> | ||
{/* missing */} | ||
{null /* preserved */} | ||
{ | ||
// ??? 1 | ||
} | ||
{// ??? 2 | ||
} | ||
{// ??? 3 | ||
} | ||
{ | ||
// ??? 4 | ||
/* ??? 5 */ } | ||
</div>; | ||
}; | ||
return Component; | ||
}()); |
27 changes: 27 additions & 0 deletions
27
...ines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).symbols
This file contains 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,27 @@ | ||
=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === | ||
// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs | ||
namespace JSX {} | ||
>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) | ||
|
||
class Component { | ||
>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) | ||
|
||
render() { | ||
>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) | ||
|
||
return <div> | ||
{/* missing */} | ||
{null/* preserved */} | ||
{ | ||
// ??? 1 | ||
} | ||
{ // ??? 2 | ||
} | ||
{// ??? 3 | ||
} | ||
{ | ||
// ??? 4 | ||
/* ??? 5 */} | ||
</div>; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...elines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).types
This file contains 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/compiler/commentsOnJSXExpressionsArePreserved.tsx === | ||
// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs | ||
namespace JSX {} | ||
class Component { | ||
>Component : Component | ||
|
||
render() { | ||
>render : () => any | ||
|
||
return <div> | ||
><div> {/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */} </div> : error | ||
>div : any | ||
|
||
{/* missing */} | ||
{null/* preserved */} | ||
>null : null | ||
{ | ||
// ??? 1 | ||
} | ||
{ // ??? 2 | ||
} | ||
{// ??? 3 | ||
} | ||
{ | ||
// ??? 4 | ||
/* ??? 5 */} | ||
</div>; | ||
>div : any | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...s/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).js
This file contains 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,44 @@ | ||
//// [commentsOnJSXExpressionsArePreserved.tsx] | ||
// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs | ||
namespace JSX {} | ||
class Component { | ||
render() { | ||
return <div> | ||
{/* missing */} | ||
{null/* preserved */} | ||
{ | ||
// ??? 1 | ||
} | ||
{ // ??? 2 | ||
} | ||
{// ??? 3 | ||
} | ||
{ | ||
// ??? 4 | ||
/* ??? 5 */} | ||
</div>; | ||
} | ||
} | ||
|
||
//// [commentsOnJSXExpressionsArePreserved.jsx] | ||
var Component = /** @class */ (function () { | ||
function Component() { | ||
} | ||
Component.prototype.render = function () { | ||
return <div> | ||
{/* missing */} | ||
{null /* preserved */} | ||
{ | ||
// ??? 1 | ||
} | ||
{// ??? 2 | ||
} | ||
{// ??? 3 | ||
} | ||
{ | ||
// ??? 4 | ||
/* ??? 5 */ } | ||
</div>; | ||
}; | ||
return Component; | ||
}()); |
27 changes: 27 additions & 0 deletions
27
...elines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).symbols
This file contains 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,27 @@ | ||
=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === | ||
// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs | ||
namespace JSX {} | ||
>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) | ||
|
||
class Component { | ||
>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) | ||
|
||
render() { | ||
>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) | ||
|
||
return <div> | ||
{/* missing */} | ||
{null/* preserved */} | ||
{ | ||
// ??? 1 | ||
} | ||
{ // ??? 2 | ||
} | ||
{// ??? 3 | ||
} | ||
{ | ||
// ??? 4 | ||
/* ??? 5 */} | ||
</div>; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...aselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).types
This file contains 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/compiler/commentsOnJSXExpressionsArePreserved.tsx === | ||
// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs | ||
namespace JSX {} | ||
class Component { | ||
>Component : Component | ||
|
||
render() { | ||
>render : () => any | ||
|
||
return <div> | ||
><div> {/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */} </div> : error | ||
>div : any | ||
|
||
{/* missing */} | ||
{null/* preserved */} | ||
>null : null | ||
{ | ||
// ??? 1 | ||
} | ||
{ // ??? 2 | ||
} | ||
{// ??? 3 | ||
} | ||
{ | ||
// ??? 4 | ||
/* ??? 5 */} | ||
</div>; | ||
>div : any | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...ines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).errors.txt
This file contains 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,26 @@ | ||
tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,17): error TS2304: Cannot find name 'React'. | ||
|
||
|
||
==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== | ||
// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs | ||
namespace JSX {} | ||
class Component { | ||
render() { | ||
return <div> | ||
~~~ | ||
!!! error TS2304: Cannot find name 'React'. | ||
{/* missing */} | ||
{null/* preserved */} | ||
{ | ||
// ??? 1 | ||
} | ||
{ // ??? 2 | ||
} | ||
{// ??? 3 | ||
} | ||
{ | ||
// ??? 4 | ||
/* ??? 5 */} | ||
</div>; | ||
} | ||
} |
Oops, something went wrong.
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.
This change (and the similar ones in
system
) are what fix the crash mentioned in the OP. The non-module file has a reference to a synthetic import that, since it's never actually inserted into the file (since it's not a module), is never parented, and thus has no name. We emit a (admittedly type system, rather than grammar/program) error in these cases usually (module "react/jsx-runtime" not found
), so the emitted JS being nonfunctional is probably fine, but this case might need a more descriptive error added. The emit simply uses an arbitrary name now (_a
), rather than crashing.Since this part fixes a crash, I'm wondering if I should (partially?) port this to the 4.1 branch or no? @DanielRosenwasser ?
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 comment may actually be referring to the crash fixed here (assuming the input file is exactly what the user in that comment says, odd as a top-level
return
is, since we wouldn't mark that as a module), though the stack is very different than the on the OP of that thread refers to (and is definitely a separate issue).