Under jsx: preserve, actually preserve expressions which contain only comments (#41757)

* Under jsx: preserve, actually preserve expressions which contain only comments

* Even better best effort comment preservation in JSX comments
This commit is contained in:
Wesley Wigham 2020-12-18 11:42:33 -08:00 committed by GitHub
parent caebbe6714
commit c3ff0d4c17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 1034 additions and 32 deletions

View file

@ -2864,7 +2864,8 @@ namespace ts {
}
pos = writeTokenText(token, writer, pos);
if (isSimilarNode && contextNode.end !== pos) {
emitTrailingCommentsOfPosition(pos, /*prefixSpace*/ true);
const isJsxExprContext = contextNode.kind === SyntaxKind.JsxExpression;
emitTrailingCommentsOfPosition(pos, /*prefixSpace*/ !isJsxExprContext, /*forceNoNewline*/ isJsxExprContext);
}
return pos;
}
@ -3421,12 +3422,35 @@ namespace ts {
writePunctuation("}");
}
function hasTrailingCommentsAtPosition(pos: number) {
let result = false;
forEachTrailingCommentRange(currentSourceFile?.text || "", pos + 1, () => result = true);
return result;
}
function hasLeadingCommentsAtPosition(pos: number) {
let result = false;
forEachLeadingCommentRange(currentSourceFile?.text || "", pos + 1, () => result = true);
return result;
}
function hasCommentsAtPosition(pos: number) {
return hasTrailingCommentsAtPosition(pos) || hasLeadingCommentsAtPosition(pos);
}
function emitJsxExpression(node: JsxExpression) {
if (node.expression) {
writePunctuation("{");
if (node.expression || (!commentsDisabled && !nodeIsSynthesized(node) && hasCommentsAtPosition(node.pos))) { // preserve empty expressions if they contain comments!
const isMultiline = currentSourceFile && !nodeIsSynthesized(node) && getLineAndCharacterOfPosition(currentSourceFile, node.pos).line !== getLineAndCharacterOfPosition(currentSourceFile, node.end).line;
if (isMultiline) {
writer.increaseIndent();
}
const end = emitTokenWithComment(SyntaxKind.OpenBraceToken, node.pos, writePunctuation, node);
emit(node.dotDotDotToken);
emitExpression(node.expression);
writePunctuation("}");
emitTokenWithComment(SyntaxKind.CloseBraceToken, node.expression?.end || end, writePunctuation, node);
if (isMultiline) {
writer.decreaseIndent();
}
}
}
@ -5274,15 +5298,27 @@ namespace ts {
}
}
function emitTrailingCommentsOfPosition(pos: number, prefixSpace?: boolean) {
function emitTrailingCommentsOfPosition(pos: number, prefixSpace?: boolean, forceNoNewline?: boolean) {
if (commentsDisabled) {
return;
}
enterComment();
forEachTrailingCommentToEmit(pos, prefixSpace ? emitTrailingComment : emitTrailingCommentOfPosition);
forEachTrailingCommentToEmit(pos, prefixSpace ? emitTrailingComment : forceNoNewline ? emitTrailingCommentOfPositionNoNewline : emitTrailingCommentOfPosition);
exitComment();
}
function emitTrailingCommentOfPositionNoNewline(commentPos: number, commentEnd: number, kind: SyntaxKind) {
// trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
emitPos(commentPos);
writeCommentRange(currentSourceFile!.text, getCurrentLineMap(), writer, commentPos, commentEnd, newLine);
emitPos(commentEnd);
if (kind === SyntaxKind.SingleLineCommentTrivia) {
writer.writeLine(); // still write a newline for single-line comments, so closing tokens aren't written on the same line
}
}
function emitTrailingCommentOfPosition(commentPos: number, commentEnd: number, _kind: SyntaxKind, hasTrailingNewLine: boolean) {
// trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space

View file

@ -1790,7 +1790,7 @@ namespace ts {
const name = importDeclaration.propertyName || importDeclaration.name;
return setTextRange(
factory.createPropertyAccessExpression(
factory.getGeneratedNameForNode(importDeclaration.parent.parent.parent),
factory.getGeneratedNameForNode(importDeclaration.parent?.parent?.parent || importDeclaration),
factory.cloneNode(name)
),
/*location*/ node

View file

@ -1678,7 +1678,7 @@ namespace ts {
factory.createPropertyAssignment(
factory.cloneNode(name),
factory.createPropertyAccessExpression(
factory.getGeneratedNameForNode(importDeclaration.parent.parent.parent),
factory.getGeneratedNameForNode(importDeclaration.parent?.parent?.parent || importDeclaration),
factory.cloneNode(importDeclaration.propertyName || importDeclaration.name)
),
),
@ -1747,7 +1747,7 @@ namespace ts {
else if (isImportSpecifier(importDeclaration)) {
return setTextRange(
factory.createPropertyAccessExpression(
factory.getGeneratedNameForNode(importDeclaration.parent.parent.parent),
factory.getGeneratedNameForNode(importDeclaration.parent?.parent?.parent || importDeclaration),
factory.cloneNode(importDeclaration.propertyName || importDeclaration.name)
),
/*location*/ node

View file

@ -39,19 +39,21 @@ var React = require("react");
</div>;
<div>
// Not Comment
{
//Comment just Fine
}
// Another not Comment
</div>;
<div>
// Not Comment
{
//Comment just Fine
"Hi"}
//Comment just Fine
"Hi"}
// Another not Comment
</div>;
<div>
/* Not Comment */
{
//Comment just Fine
"Hi"}
//Comment just Fine
"Hi"}
</div>;

View file

@ -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;
}());

View file

@ -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>;
}
}

View file

@ -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
}
}

View file

@ -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;
}());

View file

@ -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>;
}
}

View file

@ -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
}
}

View file

@ -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>;
}
}

View file

@ -0,0 +1,31 @@
//// [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.js]
var Component = /** @class */ (function () {
function Component() {
}
Component.prototype.render = function () {
return React.createElement("div", null, null /* preserved */);
};
return Component;
}());

View file

@ -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>;
}
}

View file

@ -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> : any
>div : any
{/* missing */}
{null/* preserved */}
>null : null
{
// ??? 1
}
{ // ??? 2
}
{// ??? 3
}
{
// ??? 4
/* ??? 5 */}
</div>;
>div : any
}
}

View file

@ -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>;
}
}

View file

@ -0,0 +1,31 @@
//// [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.js]
var Component = /** @class */ (function () {
function Component() {
}
Component.prototype.render = function () {
return React.createElement("div", null, null /* preserved */);
};
return Component;
}());

View file

@ -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>;
}
}

View file

@ -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> : any
>div : any
{/* missing */}
{null/* preserved */}
>null : null
{
// ??? 1
}
{ // ??? 2
}
{// ??? 3
}
{
// ??? 4
/* ??? 5 */}
</div>;
>div : any
}
}

View file

@ -0,0 +1,39 @@
tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2307: Cannot find module 'react/jsx-runtime' or its corresponding type declarations.
==== 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>
~~~~~
{/* missing */}
~~~~~~~~~~~~~~~~~~~~~~~~~~~
{null/* preserved */}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
~~~~~~~~~~~~~
// ??? 1
~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{ // ??? 2
~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{// ??? 3
~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{
~~~~~~~~~~~~~
// ??? 4
~~~~~~~~~~~~~~~~~~~~~~~~
/* ??? 5 */}
~~~~~~~~~~~~~~~~~~~~~~~~
</div>;
~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'react/jsx-runtime' or its corresponding type declarations.
}
}

View file

@ -0,0 +1,31 @@
//// [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.js]
var Component = /** @class */ (function () {
function Component() {
}
Component.prototype.render = function () {
return _a.jsx("div", { children: null /* preserved */ }, void 0);
};
return Component;
}());

View file

@ -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>;
}
}

View file

@ -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> : any
>div : any
{/* missing */}
{null/* preserved */}
>null : null
{
// ??? 1
}
{ // ??? 2
}
{// ??? 3
}
{
// ??? 4
/* ??? 5 */}
</div>;
>div : any
}
}

View file

@ -0,0 +1,39 @@
tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2792: Cannot find module 'react/jsx-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
==== 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>
~~~~~
{/* missing */}
~~~~~~~~~~~~~~~~~~~~~~~~~~~
{null/* preserved */}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
~~~~~~~~~~~~~
// ??? 1
~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{ // ??? 2
~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{// ??? 3
~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{
~~~~~~~~~~~~~
// ??? 4
~~~~~~~~~~~~~~~~~~~~~~~~
/* ??? 5 */}
~~~~~~~~~~~~~~~~~~~~~~~~
</div>;
~~~~~~~~~~~~~~
!!! error TS2792: Cannot find module 'react/jsx-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
}
}

View file

@ -0,0 +1,31 @@
//// [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.js]
var Component = /** @class */ (function () {
function Component() {
}
Component.prototype.render = function () {
return _jsx("div", { children: null /* preserved */ }, void 0);
};
return Component;
}());

View file

@ -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>;
}
}

View file

@ -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> : any
>div : any
{/* missing */}
{null/* preserved */}
>null : null
{
// ??? 1
}
{ // ??? 2
}
{// ??? 3
}
{
// ??? 4
/* ??? 5 */}
</div>;
>div : any
}
}

View file

@ -0,0 +1,39 @@
tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2307: Cannot find module 'react/jsx-dev-runtime' or its corresponding type declarations.
==== 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>
~~~~~
{/* missing */}
~~~~~~~~~~~~~~~~~~~~~~~~~~~
{null/* preserved */}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
~~~~~~~~~~~~~
// ??? 1
~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{ // ??? 2
~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{// ??? 3
~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{
~~~~~~~~~~~~~
// ??? 4
~~~~~~~~~~~~~~~~~~~~~~~~
/* ??? 5 */}
~~~~~~~~~~~~~~~~~~~~~~~~
</div>;
~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'react/jsx-dev-runtime' or its corresponding type declarations.
}
}

View file

@ -0,0 +1,32 @@
//// [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.js]
var _jsxFileName = "tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx";
var Component = /** @class */ (function () {
function Component() {
}
Component.prototype.render = function () {
return _a.jsxDEV("div", { children: null /* preserved */ }, void 0, false, { fileName: _jsxFileName, lineNumber: 5, columnNumber: 15 }, this);
};
return Component;
}());

View file

@ -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>;
}
}

View file

@ -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> : any
>div : any
{/* missing */}
{null/* preserved */}
>null : null
{
// ??? 1
}
{ // ??? 2
}
{// ??? 3
}
{
// ??? 4
/* ??? 5 */}
</div>;
>div : any
}
}

View file

@ -0,0 +1,39 @@
tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2792: Cannot find module 'react/jsx-dev-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
==== 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>
~~~~~
{/* missing */}
~~~~~~~~~~~~~~~~~~~~~~~~~~~
{null/* preserved */}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
~~~~~~~~~~~~~
// ??? 1
~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{ // ??? 2
~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{// ??? 3
~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
{
~~~~~~~~~~~~~
// ??? 4
~~~~~~~~~~~~~~~~~~~~~~~~
/* ??? 5 */}
~~~~~~~~~~~~~~~~~~~~~~~~
</div>;
~~~~~~~~~~~~~~
!!! error TS2792: Cannot find module 'react/jsx-dev-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
}
}

View file

@ -0,0 +1,32 @@
//// [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.js]
var _jsxFileName = "tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx";
var Component = /** @class */ (function () {
function Component() {
}
Component.prototype.render = function () {
return _jsxDEV("div", { children: null /* preserved */ }, void 0, false, { fileName: _jsxFileName, lineNumber: 5, columnNumber: 15 }, this);
};
return Component;
}());

View file

@ -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>;
}
}

View file

@ -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> : any
>div : any
{/* missing */}
{null/* preserved */}
>null : null
{
// ??? 1
}
{ // ??? 2
}
{// ??? 3
}
{
// ??? 4
/* ??? 5 */}
</div>;
>div : any
}
}

View file

@ -40,9 +40,9 @@ 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>
:
}
<foo>{<foo><foo>{/foo/.test(x) ? <foo><foo></foo> : <foo><foo></foo>}</foo>}</foo>
:
}
</></>}</></>}/></></></>;
</></>}</></>}/></></></>;

View file

@ -69,7 +69,7 @@ baz
</AbC_def>;
<a b={x ? <c /> : <d />}/>;
<a></a>;
<a></a>;
<a>{/* this is a comment */}</a>;
<div>@test content</div>;
<div><br />7x invalid-js-identifier</div>;
<LeftRight left/>, <a />;

View file

@ -17,9 +17,9 @@ const a = (
var emptyMessage = null;
var a = (<div>
{0 ? (emptyMessage // must be identifier?
) : (
// must be exactly two expression holes
<span>
) : (
// must be exactly two expression holes
<span>
{0}{0}
</span>)}
</div>);

View file

@ -133,19 +133,21 @@ var x =
<Composite2 />
</Composite>;
var x = <div attr1={"foo" + "bar"} attr2={"foo" + "bar" +
"baz" + "bug"} attr3={"foo" + "bar" +
"baz" + "bug"} attr4="baz">
"baz" + "bug"} attr3={"foo" + "bar" +
"baz" + "bug"
// Extra line here.
} attr4="baz">
</div>;
(<div>
{/* A comment at the beginning */}
{/* A second comment at the beginning */}
<span>
{/* A nested comment */}
</span>
{/* A sandwiched comment */}
<br />
{/* A comment at the end */}
{/* A second comment at the end */}
</div>);
(<div
/* a multi-line

View file

@ -43,7 +43,7 @@ function Foo() {
return null;
}
<>
{/* JsxSelfClosingElement */}
<Foo />
<Foo />
<Foo />
@ -55,7 +55,7 @@ function Foo() {
<Foo />
<Foo />
{/* JsxOpeningElement */}
<Foo></Foo>
<Foo></Foo>
<Foo></Foo>

View file

@ -0,0 +1,22 @@
// @module: system,commonjs
// @jsx: react,react-jsx,react-jsxdev,preserve
// 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>;
}
}