Skip to content

Commit 82d9576

Browse files
committed
Merge branch 'master' into always-error-on-property-override-accessor
2 parents 802e87b + 3eaa7c6 commit 82d9576

File tree

75 files changed

+992
-1317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+992
-1317
lines changed

src/compiler/transformers/ts.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ namespace ts {
2323
IsNamedExternalExport = 1 << 4,
2424
IsDefaultExternalExport = 1 << 5,
2525
IsDerivedClass = 1 << 6,
26+
UseImmediatelyInvokedFunctionExpression = 1 << 7,
2627

2728
HasAnyDecorators = HasConstructorDecorators | HasMemberDecorators,
2829
NeedsName = HasStaticInitializedProperties | HasMemberDecorators,
29-
UseImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties,
30+
MayNeedImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties,
3031
IsExported = IsExportOfNamespace | IsDefaultExternalExport | IsNamedExternalExport,
3132
}
3233

@@ -595,6 +596,7 @@ namespace ts {
595596
if (isExportOfNamespace(node)) facts |= ClassFacts.IsExportOfNamespace;
596597
else if (isDefaultExternalModuleExport(node)) facts |= ClassFacts.IsDefaultExternalExport;
597598
else if (isNamedExternalModuleExport(node)) facts |= ClassFacts.IsNamedExternalExport;
599+
if (languageVersion <= ScriptTarget.ES5 && (facts & ClassFacts.MayNeedImmediatelyInvokedFunctionExpression)) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression;
598600
return facts;
599601
}
600602

@@ -665,12 +667,6 @@ namespace ts {
665667
const iife = createImmediatelyInvokedArrowFunction(statements);
666668
setEmitFlags(iife, EmitFlags.TypeScriptClassWrapper);
667669

668-
// Class comment is already added by the ES2015 transform when targeting ES5 or below.
669-
// Only add if targetting ES2015+ to prevent duplicates
670-
if (languageVersion > ScriptTarget.ES5) {
671-
addSyntheticLeadingComment(iife, SyntaxKind.MultiLineCommentTrivia, "* @class ");
672-
}
673-
674670
const varStatement = createVariableStatement(
675671
/*modifiers*/ undefined,
676672
createVariableDeclarationList([
@@ -679,7 +675,7 @@ namespace ts {
679675
/*type*/ undefined,
680676
iife
681677
)
682-
], languageVersion > ScriptTarget.ES5 ? NodeFlags.Let : undefined)
678+
])
683679
);
684680

685681
setOriginalNode(varStatement, node);

tests/baselines/reference/awaitAndYieldInProperty.js

+18-22
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,27 @@ async function* test(x: Promise<string>) {
1919

2020
//// [awaitAndYieldInProperty.js]
2121
async function* test(x) {
22-
var _a, _b, _c, _d, _e;
23-
let C = /** @class */ (() => {
24-
var _e, _f, _g, _h;
25-
class C {
22+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
23+
class C {
24+
constructor() {
25+
this[_a] = await x;
26+
this[_c] = yield 2;
27+
}
28+
}
29+
_a = await x, _b = await x, _c = yield 1, _d = yield 3;
30+
C[_b] = await x;
31+
C[_d] = yield 4;
32+
return _j = class {
2633
constructor() {
2734
this[_e] = await x;
2835
this[_g] = yield 2;
2936
}
30-
}
31-
_e = await x, _f = await x, _g = yield 1, _h = yield 3;
32-
C[_f] = await x;
33-
C[_h] = yield 4;
34-
return C;
35-
})();
36-
return _e = class {
37-
constructor() {
38-
this[_a] = await x;
39-
this[_c] = yield 2;
40-
}
4137
},
42-
_a = await x,
43-
_b = await x,
44-
_c = yield 1,
45-
_d = yield 3,
46-
_e[_b] = await x,
47-
_e[_d] = yield 4,
48-
_e;
38+
_e = await x,
39+
_f = await x,
40+
_g = yield 1,
41+
_h = yield 3,
42+
_j[_f] = await x,
43+
_j[_h] = yield 4,
44+
_j;
4945
}

tests/baselines/reference/classDeclarationCheckUsedBeforeDefinitionInItself.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ class C3 {
44
}
55

66
//// [classDeclarationCheckUsedBeforeDefinitionInItself.js]
7-
let C3 = /** @class */ (() => {
8-
class C3 {
9-
}
10-
C3.intance = new C3(); // ok
11-
return C3;
12-
})();
7+
class C3 {
8+
}
9+
C3.intance = new C3(); // ok

tests/baselines/reference/computedPropertyNames12_ES6.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@ class C {
1717
}
1818

1919
//// [computedPropertyNames12_ES6.js]
20+
var _a, _b, _c;
2021
var s;
2122
var n;
2223
var a;
23-
let C = /** @class */ (() => {
24-
var _a, _b, _c;
25-
class C {
26-
constructor() {
27-
this[_a] = n;
28-
this[_b] = 2;
29-
this[`hello bye`] = 0;
30-
}
24+
class C {
25+
constructor() {
26+
this[_a] = n;
27+
this[_b] = 2;
28+
this[`hello bye`] = 0;
3129
}
32-
_a = n, s + s, _b = s + n, +s, _c = `hello ${a} bye`;
33-
C[_c] = 0;
34-
return C;
35-
})();
30+
}
31+
_a = n, s + s, _b = s + n, +s, _c = `hello ${a} bye`;
32+
C[_c] = 0;

tests/baselines/reference/computedPropertyNamesWithStaticProperty.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ class C {
1111
}
1212

1313
//// [computedPropertyNamesWithStaticProperty.js]
14-
let C = /** @class */ (() => {
15-
class C {
16-
get [C.staticProp]() {
17-
return "hello";
18-
}
19-
set [C.staticProp](x) {
20-
var y = x;
21-
}
22-
[C.staticProp]() { }
14+
class C {
15+
get [C.staticProp]() {
16+
return "hello";
2317
}
24-
C.staticProp = 10;
25-
return C;
26-
})();
18+
set [C.staticProp](x) {
19+
var y = x;
20+
}
21+
[C.staticProp]() { }
22+
}
23+
C.staticProp = 10;

tests/baselines/reference/decoratedClassExportsCommonJS1.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
1414
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;
1515
return c > 3 && r && Object.defineProperty(target, key, r), r;
1616
};
17+
var Testing123_1;
1718
Object.defineProperty(exports, "__esModule", { value: true });
1819
exports.Testing123 = void 0;
19-
let Testing123 = /** @class */ (() => {
20-
var Testing123_1;
21-
let Testing123 = Testing123_1 = class Testing123 {
22-
};
23-
Testing123.prop1 = Testing123_1.prop0;
24-
Testing123 = Testing123_1 = __decorate([
25-
Something({ v: () => Testing123_1 })
26-
], Testing123);
27-
return Testing123;
28-
})();
20+
let Testing123 = Testing123_1 = class Testing123 {
21+
};
22+
Testing123.prop1 = Testing123_1.prop0;
23+
Testing123 = Testing123_1 = __decorate([
24+
Something({ v: () => Testing123_1 })
25+
], Testing123);
2926
exports.Testing123 = Testing123;

tests/baselines/reference/decoratedClassExportsCommonJS2.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
1212
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;
1313
return c > 3 && r && Object.defineProperty(target, key, r), r;
1414
};
15+
var Testing123_1;
1516
Object.defineProperty(exports, "__esModule", { value: true });
1617
exports.Testing123 = void 0;
17-
let Testing123 = /** @class */ (() => {
18-
var Testing123_1;
19-
let Testing123 = Testing123_1 = class Testing123 {
20-
};
21-
Testing123 = Testing123_1 = __decorate([
22-
Something({ v: () => Testing123_1 })
23-
], Testing123);
24-
return Testing123;
25-
})();
18+
let Testing123 = Testing123_1 = class Testing123 {
19+
};
20+
Testing123 = Testing123_1 = __decorate([
21+
Something({ v: () => Testing123_1 })
22+
], Testing123);
2623
exports.Testing123 = Testing123;

tests/baselines/reference/decoratedClassExportsSystem1.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@ System.register([], function (exports_1, context_1) {
1616
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;
1717
return c > 3 && r && Object.defineProperty(target, key, r), r;
1818
};
19-
var Testing123;
19+
var Testing123_1, Testing123;
2020
var __moduleName = context_1 && context_1.id;
2121
return {
2222
setters: [],
2323
execute: function () {
24-
Testing123 = /** @class */ (() => {
25-
var Testing123_1;
26-
let Testing123 = Testing123_1 = class Testing123 {
27-
};
28-
Testing123.prop1 = Testing123_1.prop0;
29-
Testing123 = Testing123_1 = __decorate([
30-
Something({ v: () => Testing123_1 })
31-
], Testing123);
32-
return Testing123;
33-
})();
24+
Testing123 = Testing123_1 = class Testing123 {
25+
};
26+
Testing123.prop1 = Testing123_1.prop0;
27+
Testing123 = Testing123_1 = __decorate([
28+
Something({ v: () => Testing123_1 })
29+
], Testing123);
3430
exports_1("Testing123", Testing123);
3531
}
3632
};

tests/baselines/reference/decoratedClassExportsSystem2.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,16 @@ System.register([], function (exports_1, context_1) {
1313
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;
1414
return c > 3 && r && Object.defineProperty(target, key, r), r;
1515
};
16-
var Testing123;
16+
var Testing123_1, Testing123;
1717
var __moduleName = context_1 && context_1.id;
1818
return {
1919
setters: [],
2020
execute: function () {
21-
Testing123 = /** @class */ (() => {
22-
var Testing123_1;
23-
let Testing123 = Testing123_1 = class Testing123 {
24-
};
25-
Testing123 = Testing123_1 = __decorate([
26-
Something({ v: () => Testing123_1 })
27-
], Testing123);
28-
return Testing123;
29-
})();
21+
Testing123 = Testing123_1 = class Testing123 {
22+
};
23+
Testing123 = Testing123_1 = __decorate([
24+
Something({ v: () => Testing123_1 })
25+
], Testing123);
3026
exports_1("Testing123", Testing123);
3127
}
3228
};

tests/baselines/reference/decoratedClassFromExternalModule.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
1717
return c > 3 && r && Object.defineProperty(target, key, r), r;
1818
};
1919
function decorate(target) { }
20-
let Decorated = /** @class */ (() => {
21-
let Decorated = class Decorated {
22-
};
23-
Decorated = __decorate([
24-
decorate
25-
], Decorated);
26-
return Decorated;
27-
})();
20+
let Decorated = class Decorated {
21+
};
22+
Decorated = __decorate([
23+
decorate
24+
], Decorated);
2825
export default Decorated;
2926
//// [undecorated.js]
3027
export {};

tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.js

+10-16
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ define(["require", "exports"], function (require, exports) {
2424
"use strict";
2525
Object.defineProperty(exports, "__esModule", { value: true });
2626
var decorator;
27-
let Foo = /** @class */ (() => {
28-
let Foo = class Foo {
29-
};
30-
Foo = __decorate([
31-
decorator
32-
], Foo);
33-
return Foo;
34-
})();
27+
let Foo = class Foo {
28+
};
29+
Foo = __decorate([
30+
decorator
31+
], Foo);
3532
exports.default = Foo;
3633
});
3734
//// [b.js]
@@ -45,13 +42,10 @@ define(["require", "exports"], function (require, exports) {
4542
"use strict";
4643
Object.defineProperty(exports, "__esModule", { value: true });
4744
var decorator;
48-
let default_1 = /** @class */ (() => {
49-
let default_1 = class {
50-
};
51-
default_1 = __decorate([
52-
decorator
53-
], default_1);
54-
return default_1;
55-
})();
45+
let default_1 = class {
46+
};
47+
default_1 = __decorate([
48+
decorator
49+
], default_1);
5650
exports.default = default_1;
5751
});

tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.js

+10-16
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
2323
};
2424
Object.defineProperty(exports, "__esModule", { value: true });
2525
var decorator;
26-
let Foo = /** @class */ (() => {
27-
let Foo = class Foo {
28-
};
29-
Foo = __decorate([
30-
decorator
31-
], Foo);
32-
return Foo;
33-
})();
26+
let Foo = class Foo {
27+
};
28+
Foo = __decorate([
29+
decorator
30+
], Foo);
3431
exports.default = Foo;
3532
//// [b.js]
3633
"use strict";
@@ -42,12 +39,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4239
};
4340
Object.defineProperty(exports, "__esModule", { value: true });
4441
var decorator;
45-
let default_1 = /** @class */ (() => {
46-
let default_1 = class {
47-
};
48-
default_1 = __decorate([
49-
decorator
50-
], default_1);
51-
return default_1;
52-
})();
42+
let default_1 = class {
43+
};
44+
default_1 = __decorate([
45+
decorator
46+
], default_1);
5347
exports.default = default_1;

tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js

+10-16
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,11 @@ System.register([], function (exports_1, context_1) {
2626
return {
2727
setters: [],
2828
execute: function () {
29-
Foo = /** @class */ (() => {
30-
let Foo = class Foo {
31-
};
32-
Foo = __decorate([
33-
decorator
34-
], Foo);
35-
return Foo;
36-
})();
29+
Foo = class Foo {
30+
};
31+
Foo = __decorate([
32+
decorator
33+
], Foo);
3734
exports_1("default", Foo);
3835
}
3936
};
@@ -52,14 +49,11 @@ System.register([], function (exports_1, context_1) {
5249
return {
5350
setters: [],
5451
execute: function () {
55-
default_1 = /** @class */ (() => {
56-
let default_1 = class {
57-
};
58-
default_1 = __decorate([
59-
decorator
60-
], default_1);
61-
return default_1;
62-
})();
52+
default_1 = class {
53+
};
54+
default_1 = __decorate([
55+
decorator
56+
], default_1);
6357
exports_1("default", default_1);
6458
}
6559
};

0 commit comments

Comments
 (0)