Skip to content

Commit 44944a2

Browse files
committed
Do not incorrectly add line separators for non-synthetic nodes when emitting node list
As of 3c32f6e, a line separator is added between nodes if the nodes are not synthetic and on separate lines. This is wrong and previously only happened if the non-synthetic nodes were on different lines but had the same parent. Fixes microsoft#44068.
1 parent 7aacd6b commit 44944a2

10 files changed

+6445
-6421
lines changed

src/compiler/emitter.ts

+5,716-5,716
Large diffs are not rendered by default.

src/testRunner/unittests/transform.ts

+603-583
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [decoratorOnClassMethodThisParameter.ts]
1+
//// [decoratorOnClassMethodThisParameter.ts]
22
declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void;
33

44
class C {
@@ -7,30 +7,31 @@ class C {
77

88
class C2 {
99
method(@dec allowed: C2, @dec this: C2) {}
10-
}
11-
12-
//// [decoratorOnClassMethodThisParameter.js]
13-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17-
return c > 3 && r && Object.defineProperty(target, key, r), r;
18-
};
19-
var __param = (this && this.__param) || function (paramIndex, decorator) {
20-
return function (target, key) { decorator(target, key, paramIndex); }
21-
};
22-
var C = /** @class */ (function () {
23-
function C() {
24-
}
25-
C.prototype.method = function () { };
26-
return C;
27-
}());
28-
var C2 = /** @class */ (function () {
29-
function C2() {
30-
}
31-
C2.prototype.method = function (allowed) { };
32-
__decorate([
33-
__param(0, dec), __param(1, dec)
34-
], C2.prototype, "method", null);
35-
return C2;
36-
}());
10+
}
11+
12+
//// [decoratorOnClassMethodThisParameter.js]
13+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17+
return c > 3 && r && Object.defineProperty(target, key, r), r;
18+
};
19+
var __param = (this && this.__param) || function (paramIndex, decorator) {
20+
return function (target, key) { decorator(target, key, paramIndex); }
21+
};
22+
var C = /** @class */ (function () {
23+
function C() {
24+
}
25+
C.prototype.method = function () { };
26+
return C;
27+
}());
28+
var C2 = /** @class */ (function () {
29+
function C2() {
30+
}
31+
C2.prototype.method = function (allowed) { };
32+
__decorate([
33+
__param(0, dec),
34+
__param(1, dec)
35+
], C2.prototype, "method", null);
36+
return C2;
37+
}());

tests/baselines/reference/jsxJsxsCjsTransformNestedSelfClosingChild(jsx=react-jsx).js

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [jsxJsxsCjsTransformNestedSelfClosingChild.tsx]
1+
//// [jsxJsxsCjsTransformNestedSelfClosingChild.tsx]
22
/// <reference path="/.lib/react16.d.ts" />
33
import type * as React from 'react';
44

@@ -19,13 +19,12 @@ console.log(
1919
<div>
2020
{[1, 2].map(i => <div key={i}>{i}</div>)}
2121
</div>
22-
)
23-
24-
//// [jsxJsxsCjsTransformNestedSelfClosingChild.js]
25-
"use strict";
26-
exports.__esModule = true;
27-
var jsx_runtime_1 = require("react/jsx-runtime");
28-
console.log(jsx_runtime_1.jsx("div", { children: jsx_runtime_1.jsx("div", {}, void 0) }, void 0));
29-
console.log(jsx_runtime_1.jsxs("div", { children: [jsx_runtime_1.jsx("div", {}, void 0),
30-
jsx_runtime_1.jsx("div", {}, void 0)] }, void 0));
31-
console.log(jsx_runtime_1.jsx("div", { children: [1, 2].map(function (i) { return jsx_runtime_1.jsx("div", { children: i }, i); }) }, void 0));
22+
)
23+
24+
//// [jsxJsxsCjsTransformNestedSelfClosingChild.js]
25+
"use strict";
26+
exports.__esModule = true;
27+
var jsx_runtime_1 = require("react/jsx-runtime");
28+
console.log(jsx_runtime_1.jsx("div", { children: jsx_runtime_1.jsx("div", {}, void 0) }, void 0));
29+
console.log(jsx_runtime_1.jsxs("div", { children: [jsx_runtime_1.jsx("div", {}, void 0), jsx_runtime_1.jsx("div", {}, void 0)] }, void 0));
30+
console.log(jsx_runtime_1.jsx("div", { children: [1, 2].map(function (i) { return jsx_runtime_1.jsx("div", { children: i }, i); }) }, void 0));
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [jsxJsxsCjsTransformNestedSelfClosingChild.tsx]
1+
//// [jsxJsxsCjsTransformNestedSelfClosingChild.tsx]
22
/// <reference path="/.lib/react16.d.ts" />
33
import type * as React from 'react';
44

@@ -19,15 +19,14 @@ console.log(
1919
<div>
2020
{[1, 2].map(i => <div key={i}>{i}</div>)}
2121
</div>
22-
)
23-
24-
//// [jsxJsxsCjsTransformNestedSelfClosingChild.js]
25-
"use strict";
26-
var _this = this;
27-
exports.__esModule = true;
28-
var jsx_dev_runtime_1 = require("react/jsx-dev-runtime");
29-
var _jsxFileName = "tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformNestedSelfClosingChild.tsx";
30-
console.log(jsx_dev_runtime_1.jsxDEV("div", { children: jsx_dev_runtime_1.jsxDEV("div", {}, void 0, false, { fileName: _jsxFileName, lineNumber: 6, columnNumber: 5 }, this) }, void 0, false, { fileName: _jsxFileName, lineNumber: 4, columnNumber: 13 }, this));
31-
console.log(jsx_dev_runtime_1.jsxDEV("div", { children: [jsx_dev_runtime_1.jsxDEV("div", {}, void 0, false, { fileName: _jsxFileName, lineNumber: 12, columnNumber: 5 }, this),
32-
jsx_dev_runtime_1.jsxDEV("div", {}, void 0, false, { fileName: _jsxFileName, lineNumber: 13, columnNumber: 5 }, this)] }, void 0, true, { fileName: _jsxFileName, lineNumber: 10, columnNumber: 13 }, this));
33-
console.log(jsx_dev_runtime_1.jsxDEV("div", { children: [1, 2].map(function (i) { return jsx_dev_runtime_1.jsxDEV("div", { children: i }, i, false, { fileName: _jsxFileName, lineNumber: 19, columnNumber: 21 }, _this); }) }, void 0, false, { fileName: _jsxFileName, lineNumber: 17, columnNumber: 13 }, this));
22+
)
23+
24+
//// [jsxJsxsCjsTransformNestedSelfClosingChild.js]
25+
"use strict";
26+
var _this = this;
27+
exports.__esModule = true;
28+
var jsx_dev_runtime_1 = require("react/jsx-dev-runtime");
29+
var _jsxFileName = "tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformNestedSelfClosingChild.tsx";
30+
console.log(jsx_dev_runtime_1.jsxDEV("div", { children: jsx_dev_runtime_1.jsxDEV("div", {}, void 0, false, { fileName: _jsxFileName, lineNumber: 6, columnNumber: 5 }, this) }, void 0, false, { fileName: _jsxFileName, lineNumber: 4, columnNumber: 13 }, this));
31+
console.log(jsx_dev_runtime_1.jsxDEV("div", { children: [jsx_dev_runtime_1.jsxDEV("div", {}, void 0, false, { fileName: _jsxFileName, lineNumber: 12, columnNumber: 5 }, this), jsx_dev_runtime_1.jsxDEV("div", {}, void 0, false, { fileName: _jsxFileName, lineNumber: 13, columnNumber: 5 }, this)] }, void 0, true, { fileName: _jsxFileName, lineNumber: 10, columnNumber: 13 }, this));
32+
console.log(jsx_dev_runtime_1.jsxDEV("div", { children: [1, 2].map(function (i) { return jsx_dev_runtime_1.jsxDEV("div", { children: i }, i, false, { fileName: _jsxFileName, lineNumber: 19, columnNumber: 21 }, _this); }) }, void 0, false, { fileName: _jsxFileName, lineNumber: 17, columnNumber: 13 }, this));
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts]
1+
//// [objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts]
22
// errors
33
var y = {
44
"stringLiteral",
@@ -18,28 +18,29 @@ var x = {
1818
a[1],
1919
};
2020

21-
var v = { class }; // error
22-
23-
//// [objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.js]
24-
var _a;
25-
// errors
26-
var y = {
27-
"stringLiteral": ,
28-
42: ,
29-
get e() { },
30-
set f() { },
31-
"this": ,
32-
"super": ,
33-
"var": ,
34-
"class": ,
35-
"typeof":
36-
};
37-
var x = (_a = {
38-
a: a, : .b,
39-
a: a
40-
},
41-
_a["ss"] = ,
42-
_a.a = a,
43-
_a[1] = ,
44-
_a);
45-
var v = { "class": }; // error
21+
var v = { class }; // error
22+
23+
//// [objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.js]
24+
var _a;
25+
// errors
26+
var y = {
27+
"stringLiteral": ,
28+
42: ,
29+
get e() { },
30+
set f() { },
31+
"this": ,
32+
"super": ,
33+
"var": ,
34+
"class": ,
35+
"typeof":
36+
};
37+
var x = (_a = {
38+
a: a,
39+
: .b,
40+
a: a
41+
},
42+
_a["ss"] = ,
43+
_a.a = a,
44+
_a[1] = ,
45+
_a);
46+
var v = { "class": }; // error
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [objectLiteralShorthandPropertiesErrorWithModule.ts]
1+
//// [objectLiteralShorthandPropertiesErrorWithModule.ts]
22
// module export
33
var x = "Foo";
44
module m {
@@ -13,19 +13,20 @@ module n {
1313
}
1414

1515
m.y.x;
16-
17-
18-
//// [objectLiteralShorthandPropertiesErrorWithModule.js]
19-
// module export
20-
var x = "Foo";
21-
var m;
22-
(function (m) {
23-
})(m || (m = {}));
24-
var n;
25-
(function (n) {
26-
var z = 10000;
27-
n.y = {
28-
m: m, : .x // error
29-
};
30-
})(n || (n = {}));
31-
m.y.x;
16+
17+
18+
//// [objectLiteralShorthandPropertiesErrorWithModule.js]
19+
// module export
20+
var x = "Foo";
21+
var m;
22+
(function (m) {
23+
})(m || (m = {}));
24+
var n;
25+
(function (n) {
26+
var z = 10000;
27+
n.y = {
28+
m: m,
29+
: .x // error
30+
};
31+
})(n || (n = {}));
32+
m.y.x;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [objectTypesWithOptionalProperties2.ts]
1+
//// [objectTypesWithOptionalProperties2.ts]
22
// Illegal attempts to define optional methods
33

44
var a: {
@@ -24,23 +24,24 @@ class C2<T> {
2424

2525
var b = {
2626
x()?: 1 // error
27-
}
28-
29-
//// [objectTypesWithOptionalProperties2.js]
30-
// Illegal attempts to define optional methods
31-
var a;
32-
var C = /** @class */ (function () {
33-
function C() {
34-
}
35-
C.prototype.x = function () { };
36-
return C;
37-
}());
38-
var C2 = /** @class */ (function () {
39-
function C2() {
40-
}
41-
C2.prototype.x = function () { };
42-
return C2;
43-
}());
44-
var b = {
45-
x: function () { }, 1: // error
46-
};
27+
}
28+
29+
//// [objectTypesWithOptionalProperties2.js]
30+
// Illegal attempts to define optional methods
31+
var a;
32+
var C = /** @class */ (function () {
33+
function C() {
34+
}
35+
C.prototype.x = function () { };
36+
return C;
37+
}());
38+
var C2 = /** @class */ (function () {
39+
function C2() {
40+
}
41+
C2.prototype.x = function () { };
42+
return C2;
43+
}());
44+
var b = {
45+
x: function () { },
46+
1: // error
47+
};
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
//// [parserErrorRecovery_ObjectLiteral2.ts]
1+
//// [parserErrorRecovery_ObjectLiteral2.ts]
22
var v = { a
3-
return;
4-
5-
//// [parserErrorRecovery_ObjectLiteral2.js]
6-
var v = { a: a,
7-
"return": };
3+
return;
4+
5+
//// [parserErrorRecovery_ObjectLiteral2.js]
6+
var v = { a: a, "return": };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const FirstVar = null;
2+
const SecondVar = null;
3+
[FirstVar, FirstVar];

0 commit comments

Comments
 (0)