Skip to content

Commit

Permalink
Cherry-pick 79f1ec3
Browse files Browse the repository at this point in the history
From #38719
  • Loading branch information
sandersn committed May 21, 2020
1 parent c019c83 commit 4ac4d9a
Show file tree
Hide file tree
Showing 75 changed files with 1,047 additions and 1,296 deletions.
12 changes: 4 additions & 8 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ namespace ts {
IsNamedExternalExport = 1 << 4,
IsDefaultExternalExport = 1 << 5,
IsDerivedClass = 1 << 6,
UseImmediatelyInvokedFunctionExpression = 1 << 7,

HasAnyDecorators = HasConstructorDecorators | HasMemberDecorators,
NeedsName = HasStaticInitializedProperties | HasMemberDecorators,
UseImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties,
MayNeedImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties,
IsExported = IsExportOfNamespace | IsDefaultExternalExport | IsNamedExternalExport,
}

Expand Down Expand Up @@ -595,6 +596,7 @@ namespace ts {
if (isExportOfNamespace(node)) facts |= ClassFacts.IsExportOfNamespace;
else if (isDefaultExternalModuleExport(node)) facts |= ClassFacts.IsDefaultExternalExport;
else if (isNamedExternalModuleExport(node)) facts |= ClassFacts.IsNamedExternalExport;
if (languageVersion <= ScriptTarget.ES5 && (facts & ClassFacts.MayNeedImmediatelyInvokedFunctionExpression)) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression;
return facts;
}

Expand Down Expand Up @@ -665,12 +667,6 @@ namespace ts {
const iife = createImmediatelyInvokedArrowFunction(statements);
setEmitFlags(iife, EmitFlags.TypeScriptClassWrapper);

// Class comment is already added by the ES2015 transform when targeting ES5 or below.
// Only add if targetting ES2015+ to prevent duplicates
if (languageVersion > ScriptTarget.ES5) {
addSyntheticLeadingComment(iife, SyntaxKind.MultiLineCommentTrivia, "* @class ");
}

const varStatement = createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList([
Expand All @@ -679,7 +675,7 @@ namespace ts {
/*type*/ undefined,
iife
)
], languageVersion > ScriptTarget.ES5 ? NodeFlags.Let : undefined)
])
);

setOriginalNode(varStatement, node);
Expand Down
40 changes: 18 additions & 22 deletions tests/baselines/reference/awaitAndYieldInProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,27 @@ async function* test(x: Promise<string>) {

//// [awaitAndYieldInProperty.js]
async function* test(x) {
var _a, _b, _c, _d, _e;
let C = /** @class */ (() => {
var _e, _f, _g, _h;
class C {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
class C {
constructor() {
this[_a] = await x;
this[_c] = yield 2;
}
}
_a = await x, _b = await x, _c = yield 1, _d = yield 3;
C[_b] = await x;
C[_d] = yield 4;
return _j = class {
constructor() {
this[_e] = await x;
this[_g] = yield 2;
}
}
_e = await x, _f = await x, _g = yield 1, _h = yield 3;
C[_f] = await x;
C[_h] = yield 4;
return C;
})();
return _e = class {
constructor() {
this[_a] = await x;
this[_c] = yield 2;
}
},
_a = await x,
_b = await x,
_c = yield 1,
_d = yield 3,
_e[_b] = await x,
_e[_d] = yield 4,
_e;
_e = await x,
_f = await x,
_g = yield 1,
_h = yield 3,
_j[_f] = await x,
_j[_h] = yield 4,
_j;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ class C3 {
}

//// [classDeclarationCheckUsedBeforeDefinitionInItself.js]
let C3 = /** @class */ (() => {
class C3 {
}
C3.intance = new C3(); // ok
return C3;
})();
class C3 {
}
C3.intance = new C3(); // ok
21 changes: 9 additions & 12 deletions tests/baselines/reference/computedPropertyNames12_ES6.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@ class C {
}

//// [computedPropertyNames12_ES6.js]
var _a, _b, _c;
var s;
var n;
var a;
let C = /** @class */ (() => {
var _a, _b, _c;
class C {
constructor() {
this[_a] = n;
this[_b] = 2;
this[`hello bye`] = 0;
}
class C {
constructor() {
this[_a] = n;
this[_b] = 2;
this[`hello bye`] = 0;
}
_a = n, s + s, _b = s + n, +s, _c = `hello ${a} bye`;
C[_c] = 0;
return C;
})();
}
_a = n, s + s, _b = s + n, +s, _c = `hello ${a} bye`;
C[_c] = 0;
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ class C {
}

//// [computedPropertyNamesWithStaticProperty.js]
let C = /** @class */ (() => {
class C {
get [C.staticProp]() {
return "hello";
}
set [C.staticProp](x) {
var y = x;
}
[C.staticProp]() { }
class C {
get [C.staticProp]() {
return "hello";
}
C.staticProp = 10;
return C;
})();
set [C.staticProp](x) {
var y = x;
}
[C.staticProp]() { }
}
C.staticProp = 10;
17 changes: 7 additions & 10 deletions tests/baselines/reference/decoratedClassExportsCommonJS1.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
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 Testing123_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Testing123 = void 0;
let Testing123 = /** @class */ (() => {
var Testing123_1;
let Testing123 = Testing123_1 = class Testing123 {
};
Testing123.prop1 = Testing123_1.prop0;
Testing123 = Testing123_1 = __decorate([
Something({ v: () => Testing123_1 })
], Testing123);
return Testing123;
})();
let Testing123 = Testing123_1 = class Testing123 {
};
Testing123.prop1 = Testing123_1.prop0;
Testing123 = Testing123_1 = __decorate([
Something({ v: () => Testing123_1 })
], Testing123);
exports.Testing123 = Testing123;
15 changes: 6 additions & 9 deletions tests/baselines/reference/decoratedClassExportsCommonJS2.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
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 Testing123_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Testing123 = void 0;
let Testing123 = /** @class */ (() => {
var Testing123_1;
let Testing123 = Testing123_1 = class Testing123 {
};
Testing123 = Testing123_1 = __decorate([
Something({ v: () => Testing123_1 })
], Testing123);
return Testing123;
})();
let Testing123 = Testing123_1 = class Testing123 {
};
Testing123 = Testing123_1 = __decorate([
Something({ v: () => Testing123_1 })
], Testing123);
exports.Testing123 = Testing123;
18 changes: 7 additions & 11 deletions tests/baselines/reference/decoratedClassExportsSystem1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@ System.register([], function (exports_1, context_1) {
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 Testing123;
var Testing123_1, Testing123;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
Testing123 = /** @class */ (() => {
var Testing123_1;
let Testing123 = Testing123_1 = class Testing123 {
};
Testing123.prop1 = Testing123_1.prop0;
Testing123 = Testing123_1 = __decorate([
Something({ v: () => Testing123_1 })
], Testing123);
return Testing123;
})();
Testing123 = Testing123_1 = class Testing123 {
};
Testing123.prop1 = Testing123_1.prop0;
Testing123 = Testing123_1 = __decorate([
Something({ v: () => Testing123_1 })
], Testing123);
exports_1("Testing123", Testing123);
}
};
Expand Down
16 changes: 6 additions & 10 deletions tests/baselines/reference/decoratedClassExportsSystem2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@ System.register([], function (exports_1, context_1) {
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 Testing123;
var Testing123_1, Testing123;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
Testing123 = /** @class */ (() => {
var Testing123_1;
let Testing123 = Testing123_1 = class Testing123 {
};
Testing123 = Testing123_1 = __decorate([
Something({ v: () => Testing123_1 })
], Testing123);
return Testing123;
})();
Testing123 = Testing123_1 = class Testing123 {
};
Testing123 = Testing123_1 = __decorate([
Something({ v: () => Testing123_1 })
], Testing123);
exports_1("Testing123", Testing123);
}
};
Expand Down
13 changes: 5 additions & 8 deletions tests/baselines/reference/decoratedClassFromExternalModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
function decorate(target) { }
let Decorated = /** @class */ (() => {
let Decorated = class Decorated {
};
Decorated = __decorate([
decorate
], Decorated);
return Decorated;
})();
let Decorated = class Decorated {
};
Decorated = __decorate([
decorate
], Decorated);
export default Decorated;
//// [undecorated.js]
26 changes: 10 additions & 16 deletions tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var decorator;
let Foo = /** @class */ (() => {
let Foo = class Foo {
};
Foo = __decorate([
decorator
], Foo);
return Foo;
})();
let Foo = class Foo {
};
Foo = __decorate([
decorator
], Foo);
exports.default = Foo;
});
//// [b.js]
Expand All @@ -45,13 +42,10 @@ define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var decorator;
let default_1 = /** @class */ (() => {
let default_1 = class {
};
default_1 = __decorate([
decorator
], default_1);
return default_1;
})();
let default_1 = class {
};
default_1 = __decorate([
decorator
], default_1);
exports.default = default_1;
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
};
Object.defineProperty(exports, "__esModule", { value: true });
var decorator;
let Foo = /** @class */ (() => {
let Foo = class Foo {
};
Foo = __decorate([
decorator
], Foo);
return Foo;
})();
let Foo = class Foo {
};
Foo = __decorate([
decorator
], Foo);
exports.default = Foo;
//// [b.js]
"use strict";
Expand All @@ -42,12 +39,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
};
Object.defineProperty(exports, "__esModule", { value: true });
var decorator;
let default_1 = /** @class */ (() => {
let default_1 = class {
};
default_1 = __decorate([
decorator
], default_1);
return default_1;
})();
let default_1 = class {
};
default_1 = __decorate([
decorator
], default_1);
exports.default = default_1;
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ System.register([], function (exports_1, context_1) {
return {
setters: [],
execute: function () {
Foo = /** @class */ (() => {
let Foo = class Foo {
};
Foo = __decorate([
decorator
], Foo);
return Foo;
})();
Foo = class Foo {
};
Foo = __decorate([
decorator
], Foo);
exports_1("default", Foo);
}
};
Expand All @@ -52,14 +49,11 @@ System.register([], function (exports_1, context_1) {
return {
setters: [],
execute: function () {
default_1 = /** @class */ (() => {
let default_1 = class {
};
default_1 = __decorate([
decorator
], default_1);
return default_1;
})();
default_1 = class {
};
default_1 = __decorate([
decorator
], default_1);
exports_1("default", default_1);
}
};
Expand Down
Loading

0 comments on commit 4ac4d9a

Please sign in to comment.