Skip to content

Commit

Permalink
Do not incorrectly add line separators for non-synthetic nodes when e…
Browse files Browse the repository at this point in the history
…mitting 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 #44068.
  • Loading branch information
devversion committed May 13, 2021
1 parent 7aacd6b commit 44944a2
Show file tree
Hide file tree
Showing 10 changed files with 6,445 additions and 6,421 deletions.
11,432 changes: 5,716 additions & 5,716 deletions src/compiler/emitter.ts

Large diffs are not rendered by default.

1,186 changes: 603 additions & 583 deletions src/testRunner/unittests/transform.ts

Large diffs are not rendered by default.

57 changes: 29 additions & 28 deletions tests/baselines/reference/decoratorOnClassMethodThisParameter.js
@@ -1,4 +1,4 @@
//// [decoratorOnClassMethodThisParameter.ts]
//// [decoratorOnClassMethodThisParameter.ts]
declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void;

class C {
Expand All @@ -7,30 +7,31 @@ class C {

class C2 {
method(@dec allowed: C2, @dec this: C2) {}
}

//// [decoratorOnClassMethodThisParameter.js]
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var C = /** @class */ (function () {
function C() {
}
C.prototype.method = function () { };
return C;
}());
var C2 = /** @class */ (function () {
function C2() {
}
C2.prototype.method = function (allowed) { };
__decorate([
__param(0, dec), __param(1, dec)
], C2.prototype, "method", null);
return C2;
}());
}

//// [decoratorOnClassMethodThisParameter.js]
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var C = /** @class */ (function () {
function C() {
}
C.prototype.method = function () { };
return C;
}());
var C2 = /** @class */ (function () {
function C2() {
}
C2.prototype.method = function (allowed) { };
__decorate([
__param(0, dec),
__param(1, dec)
], C2.prototype, "method", null);
return C2;
}());
@@ -1,4 +1,4 @@
//// [jsxJsxsCjsTransformNestedSelfClosingChild.tsx]
//// [jsxJsxsCjsTransformNestedSelfClosingChild.tsx]
/// <reference path="/.lib/react16.d.ts" />
import type * as React from 'react';

Expand All @@ -19,13 +19,12 @@ console.log(
<div>
{[1, 2].map(i => <div key={i}>{i}</div>)}
</div>
)

//// [jsxJsxsCjsTransformNestedSelfClosingChild.js]
"use strict";
exports.__esModule = true;
var jsx_runtime_1 = require("react/jsx-runtime");
console.log(jsx_runtime_1.jsx("div", { children: jsx_runtime_1.jsx("div", {}, void 0) }, void 0));
console.log(jsx_runtime_1.jsxs("div", { children: [jsx_runtime_1.jsx("div", {}, void 0),
jsx_runtime_1.jsx("div", {}, void 0)] }, void 0));
console.log(jsx_runtime_1.jsx("div", { children: [1, 2].map(function (i) { return jsx_runtime_1.jsx("div", { children: i }, i); }) }, void 0));
)

//// [jsxJsxsCjsTransformNestedSelfClosingChild.js]
"use strict";
exports.__esModule = true;
var jsx_runtime_1 = require("react/jsx-runtime");
console.log(jsx_runtime_1.jsx("div", { children: jsx_runtime_1.jsx("div", {}, void 0) }, void 0));
console.log(jsx_runtime_1.jsxs("div", { children: [jsx_runtime_1.jsx("div", {}, void 0), jsx_runtime_1.jsx("div", {}, void 0)] }, void 0));
console.log(jsx_runtime_1.jsx("div", { children: [1, 2].map(function (i) { return jsx_runtime_1.jsx("div", { children: i }, i); }) }, void 0));
@@ -1,4 +1,4 @@
//// [jsxJsxsCjsTransformNestedSelfClosingChild.tsx]
//// [jsxJsxsCjsTransformNestedSelfClosingChild.tsx]
/// <reference path="/.lib/react16.d.ts" />
import type * as React from 'react';

Expand All @@ -19,15 +19,14 @@ console.log(
<div>
{[1, 2].map(i => <div key={i}>{i}</div>)}
</div>
)

//// [jsxJsxsCjsTransformNestedSelfClosingChild.js]
"use strict";
var _this = this;
exports.__esModule = true;
var jsx_dev_runtime_1 = require("react/jsx-dev-runtime");
var _jsxFileName = "tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformNestedSelfClosingChild.tsx";
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));
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));
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));
)

//// [jsxJsxsCjsTransformNestedSelfClosingChild.js]
"use strict";
var _this = this;
exports.__esModule = true;
var jsx_dev_runtime_1 = require("react/jsx-dev-runtime");
var _jsxFileName = "tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformNestedSelfClosingChild.tsx";
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));
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));
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));
@@ -1,4 +1,4 @@
//// [objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts]
//// [objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts]
// errors
var y = {
"stringLiteral",
Expand All @@ -18,28 +18,29 @@ var x = {
a[1],
};

var v = { class }; // error

//// [objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.js]
var _a;
// errors
var y = {
"stringLiteral": ,
42: ,
get e() { },
set f() { },
"this": ,
"super": ,
"var": ,
"class": ,
"typeof":
};
var x = (_a = {
a: a, : .b,
a: a
},
_a["ss"] = ,
_a.a = a,
_a[1] = ,
_a);
var v = { "class": }; // error
var v = { class }; // error

//// [objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.js]
var _a;
// errors
var y = {
"stringLiteral": ,
42: ,
get e() { },
set f() { },
"this": ,
"super": ,
"var": ,
"class": ,
"typeof":
};
var x = (_a = {
a: a,
: .b,
a: a
},
_a["ss"] = ,
_a.a = a,
_a[1] = ,
_a);
var v = { "class": }; // error
@@ -1,4 +1,4 @@
//// [objectLiteralShorthandPropertiesErrorWithModule.ts]
//// [objectLiteralShorthandPropertiesErrorWithModule.ts]
// module export
var x = "Foo";
module m {
Expand All @@ -13,19 +13,20 @@ module n {
}

m.y.x;


//// [objectLiteralShorthandPropertiesErrorWithModule.js]
// module export
var x = "Foo";
var m;
(function (m) {
})(m || (m = {}));
var n;
(function (n) {
var z = 10000;
n.y = {
m: m, : .x // error
};
})(n || (n = {}));
m.y.x;


//// [objectLiteralShorthandPropertiesErrorWithModule.js]
// module export
var x = "Foo";
var m;
(function (m) {
})(m || (m = {}));
var n;
(function (n) {
var z = 10000;
n.y = {
m: m,
: .x // error
};
})(n || (n = {}));
m.y.x;
43 changes: 22 additions & 21 deletions tests/baselines/reference/objectTypesWithOptionalProperties2.js
@@ -1,4 +1,4 @@
//// [objectTypesWithOptionalProperties2.ts]
//// [objectTypesWithOptionalProperties2.ts]
// Illegal attempts to define optional methods

var a: {
Expand All @@ -24,23 +24,24 @@ class C2<T> {

var b = {
x()?: 1 // error
}

//// [objectTypesWithOptionalProperties2.js]
// Illegal attempts to define optional methods
var a;
var C = /** @class */ (function () {
function C() {
}
C.prototype.x = function () { };
return C;
}());
var C2 = /** @class */ (function () {
function C2() {
}
C2.prototype.x = function () { };
return C2;
}());
var b = {
x: function () { }, 1: // error
};
}

//// [objectTypesWithOptionalProperties2.js]
// Illegal attempts to define optional methods
var a;
var C = /** @class */ (function () {
function C() {
}
C.prototype.x = function () { };
return C;
}());
var C2 = /** @class */ (function () {
function C2() {
}
C2.prototype.x = function () { };
return C2;
}());
var b = {
x: function () { },
1: // error
};
11 changes: 5 additions & 6 deletions tests/baselines/reference/parserErrorRecovery_ObjectLiteral2.js
@@ -1,7 +1,6 @@
//// [parserErrorRecovery_ObjectLiteral2.ts]
//// [parserErrorRecovery_ObjectLiteral2.ts]
var v = { a
return;

//// [parserErrorRecovery_ObjectLiteral2.js]
var v = { a: a,
"return": };
return;

//// [parserErrorRecovery_ObjectLiteral2.js]
var v = { a: a, "return": };
@@ -0,0 +1,3 @@
const FirstVar = null;
const SecondVar = null;
[FirstVar, FirstVar];

0 comments on commit 44944a2

Please sign in to comment.