Skip to content

Baseline changes for ESNext Class Property Transformation #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ var C = /** @class */ (function () {
}
return C;
}());
_a = a_1.x;
exports.C = C;
_a = a_1.x;
//// [c.js]
"use strict";
var __extends = (this && this.__extends) || (function () {
Expand Down Expand Up @@ -64,8 +64,8 @@ var D = /** @class */ (function (_super) {
}
return D;
}(b_1.C));
_a = a_1.x;
exports.D = D;
_a = a_1.x;


//// [a.d.ts]
Expand Down
145 changes: 73 additions & 72 deletions tests/baselines/reference/decoratorsOnComputedProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ 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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this baseline change?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TypeScript transformer handles the experimental decorator transformation. This made pulling out the property transformation from the TypeScript transformer difficult because there are computed property names that have to be used in both the original property declaration/assignment and in the call to the decorator helper function (and non-trivial computed property name expressions shouldn't be executed more than once).

I reconciled this by transforming the computed property names (not the actual property declaration/initializer) in the TypeScript transformer when they need to be used more than once by code generated by the TypeScript transformer.

The _a, _b, _c, _d variables are now hoisted in the ESnext transformer (they are class aliases which are emitted when a static property initializer references the name of its own class).
The other hoisted variables store computed property names for the decorated properties (created by the TypeScript transformer).

return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21;
var _a, _b, _c, _d;
var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21;
function x(o, k) { }
let i = 0;
function foo() { return ++i + ""; }
Expand All @@ -209,11 +210,11 @@ class A {
this[Symbol.iterator] = null;
this["property4"] = 2;
this[Symbol.match] = null;
this[_b] = null;
this[_d] = null;
this[_f] = null;
this[_h] = null;
}
}
foo(), _a = foo(), _b = foo(), _c = fieldNameB, _d = fieldNameC;
foo(), _e = foo(), _f = foo(), _g = fieldNameB, _h = fieldNameC;
__decorate([
x
], A.prototype, "property", void 0);
Expand All @@ -228,42 +229,42 @@ __decorate([
], A.prototype, Symbol.iterator, void 0);
__decorate([
x
], A.prototype, _a, void 0);
], A.prototype, _e, void 0);
__decorate([
x
], A.prototype, _b, void 0);
], A.prototype, _f, void 0);
__decorate([
x
], A.prototype, _c, void 0);
], A.prototype, _g, void 0);
__decorate([
x
], A.prototype, _d, void 0);
void (_j = class B {
], A.prototype, _h, void 0);
void (_a = class B {
constructor() {
this["property2"] = 2;
this[Symbol.iterator] = null;
this["property4"] = 2;
this[Symbol.match] = null;
this[_f] = null;
this[_h] = null;
this[_k] = null;
this[_m] = null;
}
},
foo(),
_e = foo(),
_f = foo(),
_g = fieldNameB,
_h = fieldNameC,
_j);
_j = foo(),
_k = foo(),
_l = fieldNameB,
_m = fieldNameC,
_a);
class C {
constructor() {
this["property2"] = 2;
this[Symbol.iterator] = null;
this["property4"] = 2;
this[Symbol.match] = null;
this[_l] = null;
this[_o] = null;
this[_p] = null;
this[_r] = null;
}
[(foo(), _k = foo(), _l = foo(), _m = fieldNameB, _o = fieldNameC, "some" + "method")]() { }
[(foo(), _o = foo(), _p = foo(), _q = fieldNameB, _r = fieldNameC, "some" + "method")]() { }
}
__decorate([
x
Expand All @@ -279,39 +280,39 @@ __decorate([
], C.prototype, Symbol.iterator, void 0);
__decorate([
x
], C.prototype, _k, void 0);
], C.prototype, _o, void 0);
__decorate([
x
], C.prototype, _l, void 0);
], C.prototype, _p, void 0);
__decorate([
x
], C.prototype, _m, void 0);
], C.prototype, _q, void 0);
__decorate([
x
], C.prototype, _o, void 0);
], C.prototype, _r, void 0);
void class D {
constructor() {
this["property2"] = 2;
this[Symbol.iterator] = null;
this["property4"] = 2;
this[Symbol.match] = null;
this[_q] = null;
this[_s] = null;
this[_t] = null;
this[_v] = null;
}
[(foo(), _p = foo(), _q = foo(), _r = fieldNameB, _s = fieldNameC, "some" + "method")]() { }
[(foo(), _s = foo(), _t = foo(), _u = fieldNameB, _v = fieldNameC, "some" + "method")]() { }
};
class E {
constructor() {
this["property2"] = 2;
this[Symbol.iterator] = null;
this["property4"] = 2;
this[Symbol.match] = null;
this[_u] = null;
this[_w] = null;
this[_x] = null;
this[_z] = null;
}
[(foo(), _t = foo(), _u = foo(), "some" + "method")]() { }
[(foo(), _w = foo(), _x = foo(), "some" + "method")]() { }
}
_v = fieldNameB, _w = fieldNameC;
_y = fieldNameB, _z = fieldNameC;
__decorate([
x
], E.prototype, "property", void 0);
Expand All @@ -326,43 +327,43 @@ __decorate([
], E.prototype, Symbol.iterator, void 0);
__decorate([
x
], E.prototype, _t, void 0);
], E.prototype, _w, void 0);
__decorate([
x
], E.prototype, _u, void 0);
], E.prototype, _x, void 0);
__decorate([
x
], E.prototype, _v, void 0);
], E.prototype, _y, void 0);
__decorate([
x
], E.prototype, _w, void 0);
void (_1 = class F {
], E.prototype, _z, void 0);
void (_b = class F {
constructor() {
this["property2"] = 2;
this[Symbol.iterator] = null;
this["property4"] = 2;
this[Symbol.match] = null;
this[_y] = null;
this[_0] = null;
this[_1] = null;
this[_3] = null;
}
[(foo(), _x = foo(), _y = foo(), "some" + "method")]() { }
[(foo(), _0 = foo(), _1 = foo(), "some" + "method")]() { }
},
_z = fieldNameB,
_0 = fieldNameC,
_1);
_2 = fieldNameB,
_3 = fieldNameC,
_b);
class G {
constructor() {
this["property2"] = 2;
this[Symbol.iterator] = null;
this["property4"] = 2;
this[Symbol.match] = null;
this[_3] = null;
this[_5] = null;
this[_7] = null;
}
[(foo(), _2 = foo(), _3 = foo(), "some" + "method")]() { }
[(_4 = fieldNameB, "some" + "method2")]() { }
[(foo(), _4 = foo(), _5 = foo(), "some" + "method")]() { }
[(_6 = fieldNameB, "some" + "method2")]() { }
}
_5 = fieldNameC;
_7 = fieldNameC;
__decorate([
x
], G.prototype, "property", void 0);
Expand All @@ -377,43 +378,43 @@ __decorate([
], G.prototype, Symbol.iterator, void 0);
__decorate([
x
], G.prototype, _2, void 0);
], G.prototype, _4, void 0);
__decorate([
x
], G.prototype, _3, void 0);
], G.prototype, _5, void 0);
__decorate([
x
], G.prototype, _4, void 0);
], G.prototype, _6, void 0);
__decorate([
x
], G.prototype, _5, void 0);
void (_10 = class H {
], G.prototype, _7, void 0);
void (_c = class H {
constructor() {
this["property2"] = 2;
this[Symbol.iterator] = null;
this["property4"] = 2;
this[Symbol.match] = null;
this[_7] = null;
this[_9] = null;
this[_11] = null;
}
[(foo(), _6 = foo(), _7 = foo(), "some" + "method")]() { }
[(_8 = fieldNameB, "some" + "method2")]() { }
[(foo(), _8 = foo(), _9 = foo(), "some" + "method")]() { }
[(_10 = fieldNameB, "some" + "method2")]() { }
},
_9 = fieldNameC,
_10);
_11 = fieldNameC,
_c);
class I {
constructor() {
this["property2"] = 2;
this[Symbol.iterator] = null;
this["property4"] = 2;
this[Symbol.match] = null;
this[_12] = null;
this[_15] = null;
this[_13] = null;
this[_16] = null;
}
[(foo(), _11 = foo(), _12 = foo(), _13 = "some" + "method")]() { }
[(_14 = fieldNameB, "some" + "method2")]() { }
[(foo(), _12 = foo(), _13 = foo(), _14 = "some" + "method")]() { }
[(_15 = fieldNameB, "some" + "method2")]() { }
}
_15 = fieldNameC;
_16 = fieldNameC;
__decorate([
x
], I.prototype, "property", void 0);
Expand All @@ -426,32 +427,32 @@ __decorate([
__decorate([
x
], I.prototype, Symbol.iterator, void 0);
__decorate([
x
], I.prototype, _11, void 0);
__decorate([
x
], I.prototype, _12, void 0);
__decorate([
x
], I.prototype, _13, null);
], I.prototype, _13, void 0);
__decorate([
x
], I.prototype, _14, void 0);
], I.prototype, _14, null);
__decorate([
x
], I.prototype, _15, void 0);
void (_21 = class J {
__decorate([
x
], I.prototype, _16, void 0);
void (_d = class J {
constructor() {
this["property2"] = 2;
this[Symbol.iterator] = null;
this["property4"] = 2;
this[Symbol.match] = null;
this[_17] = null;
this[_20] = null;
this[_18] = null;
this[_21] = null;
}
[(foo(), _16 = foo(), _17 = foo(), _18 = "some" + "method")]() { }
[(_19 = fieldNameB, "some" + "method2")]() { }
[(foo(), _17 = foo(), _18 = foo(), _19 = "some" + "method")]() { }
[(_20 = fieldNameB, "some" + "method2")]() { }
},
_20 = fieldNameC,
_21);
_21 = fieldNameC,
_d);
2 changes: 2 additions & 0 deletions tests/baselines/reference/dynamicNamesErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ const y = Symbol();
const z = Symbol();
const w = Symbol();
class ClassMemberVisibility {
static [x];
static [y]() { return 0; }
static get [z]() { return 0; }
static set [w](value) { }
[x];
[y]() { return 0; }
get [z]() { return 0; }
set [w](value) { }
Copy link

@mheiber mheiber Sep 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intentional semantic change here

Expand Down
4 changes: 1 addition & 3 deletions tests/baselines/reference/importCallExpression4ESNext.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export function foo() { return "foo"; }
export function backup() { return "backup"; }
//// [2.js]
class C {
constructor() {
this.myModule = import("./0");
}
myModule = import("./0");
method() {
const loadAsync = import("./0");
this.myModule.then(Zero => {
Expand Down
12 changes: 5 additions & 7 deletions tests/baselines/reference/importCallExpressionAsyncESNext.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ export const obj = {
}
};
export class cl2 {
constructor() {
this.p = {
m: async () => {
const req = await import('./test'); // FOUR
}
};
}
p = {
m: async () => {
const req = await import('./test'); // FOUR
}
};
}
export const l = async () => {
const req = await import('./test'); // FIVE
Expand Down
8 changes: 2 additions & 6 deletions tests/baselines/reference/importCallExpressionInAMD4.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class C {
constructor() {
this.myModule = new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); });
}
myModule = new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); });
method() {
const loadAsync = new Promise((resolve_2, reject_2) => { require(["./0"], resolve_2, reject_2); });
this.myModule.then(Zero => {
Expand All @@ -78,9 +76,7 @@ define(["require", "exports"], function (require, exports) {
}
}
class D {
constructor() {
this.myModule = new Promise((resolve_4, reject_4) => { require(["./0"], resolve_4, reject_4); });
}
myModule = new Promise((resolve_4, reject_4) => { require(["./0"], resolve_4, reject_4); });
method() {
const loadAsync = new Promise((resolve_5, reject_5) => { require(["./0"], resolve_5, reject_5); });
this.myModule.then(Zero => {
Expand Down
Loading