Skip to content

Commit 879fd4d

Browse files
authored
Revert "Reverse order of decorator-injected initializers (microsoft#54269)"
This reverts commit b14264a.
1 parent e49a15f commit 879fd4d

11 files changed

+28
-58
lines changed

src/compiler/factory/emitHelpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,10 @@ export const esDecorateHelper: UnscopedEmitHelper = {
761761
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
762762
if (_ = accept(result.get)) descriptor.get = _;
763763
if (_ = accept(result.set)) descriptor.set = _;
764-
if (_ = accept(result.init)) initializers.unshift(_);
764+
if (_ = accept(result.init)) initializers.push(_);
765765
}
766766
else if (_ = accept(result)) {
767-
if (kind === "field") initializers.unshift(_);
767+
if (kind === "field") initializers.push(_);
768768
else descriptor[key] = _;
769769
}
770770
}

src/testRunner/unittests/evaluation/esDecorators.ts

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,11 +1729,12 @@ describe("unittests:: evaluation:: esDecorators", () => {
17291729
`;
17301730
assert.strictEqual(C.x, 2);
17311731
});
1732-
it("multiple initializer pipe-throughs applied in order", () => {
1732+
it("multiple initializer pipe-throughs applied in reverse order", () => {
17331733
const { C } = exec`
1734+
function initializer(x) { return x + 1; }
17341735
export class C {
1735-
@((t, c) => x => [...x, 2])
17361736
@((t, c) => x => [...x, 3])
1737+
@((t, c) => x => [...x, 2])
17371738
static x: number[] = [1];
17381739
}
17391740
`;
@@ -1796,11 +1797,12 @@ describe("unittests:: evaluation:: esDecorators", () => {
17961797
`;
17971798
assert.strictEqual(C.x, 2);
17981799
});
1799-
it("multiple init pipe-throughs applied in order", () => {
1800+
it("multiple initializer pipe-throughs applied in reverse order", () => {
18001801
const { C } = exec`
1802+
function initializer(x) { return x + 1; }
18011803
export class C {
1802-
@((t, c) => ({ init: x => [...x, 2] }))
18031804
@((t, c) => ({ init: x => [...x, 3] }))
1805+
@((t, c) => ({ init: x => [...x, 2] }))
18041806
static accessor x: number[] = [1];
18051807
}
18061808
`;
@@ -1859,38 +1861,6 @@ describe("unittests:: evaluation:: esDecorators", () => {
18591861
assert.throws(() => main("abc"));
18601862
});
18611863
});
1862-
it("accessor 'init' evaluation order (#54267)", () => {
1863-
const { main } = exec`
1864-
function minusTwo({ set }: any, ctx: any) {
1865-
return {
1866-
set(v) { set.call(this, v - 2); },
1867-
init(v) { return v - 2; },
1868-
};
1869-
}
1870-
1871-
function timesFour({ set }: any, ctx: any) {
1872-
return {
1873-
set(v) { set.call(this, v * 4); },
1874-
init(v) { return v * 4; }
1875-
};
1876-
}
1877-
1878-
class C {
1879-
@minusTwo @timesFour accessor x = 5;
1880-
}
1881-
1882-
export const main = () => {
1883-
const obj = new C();
1884-
const afterInit = obj.x;
1885-
obj.x = 5;
1886-
const afterSet = obj.x;
1887-
return { afterInit, afterSet };
1888-
};
1889-
`;
1890-
const { afterInit, afterSet } = main();
1891-
assert.strictEqual(afterInit, 12);
1892-
assert.strictEqual(afterSet, 12);
1893-
});
18941864
});
18951865

18961866
const nodeVersion = new ts.Version(process.versions.node);
@@ -2192,11 +2162,11 @@ describe("unittests:: evaluation:: esDecorators", () => {
21922162
// order and applied to the replacement class:
21932163
"static block evaluation",
21942164
"static field initializer evaluation",
2195-
"static field injected initializer evaluation 1",
21962165
"static field injected initializer evaluation 2",
2166+
"static field injected initializer evaluation 1",
21972167
"static auto-accessor initializer evaluation",
2198-
"static auto-accessor injected initializer evaluation 1",
21992168
"static auto-accessor injected initializer evaluation 2",
2169+
"static auto-accessor injected initializer evaluation 1",
22002170
// NOTE: at this point, static private fields will be installed (TODO: on the replacement class)
22012171

22022172
// finally, class extra initializers are applied in the order they were added (i.e., methods before fields,
@@ -2238,11 +2208,11 @@ describe("unittests:: evaluation:: esDecorators", () => {
22382208
// next, instance initializers (i.e., fields, auto-accessors, and static blocks) are evaluated in document
22392209
// order:
22402210
"instance field initializer evaluation",
2241-
"instance field injected initializer evaluation 1",
22422211
"instance field injected initializer evaluation 2",
2212+
"instance field injected initializer evaluation 1",
22432213
"instance auto-accessor initializer evaluation",
2244-
"instance auto-accessor injected initializer evaluation 1",
22452214
"instance auto-accessor injected initializer evaluation 2",
2215+
"instance auto-accessor injected initializer evaluation 1",
22462216
// NOTE: at this point, instance private fields will be installed.
22472217

22482218
// finally, statements in the constructor after the call to `super()` are evaluated:

tests/baselines/reference/esDecorators-classDeclaration-commonjs-classNamespaceMerge.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
3131
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
3232
if (_ = accept(result.get)) descriptor.get = _;
3333
if (_ = accept(result.set)) descriptor.set = _;
34-
if (_ = accept(result.init)) initializers.unshift(_);
34+
if (_ = accept(result.init)) initializers.push(_);
3535
}
3636
else if (_ = accept(result)) {
37-
if (kind === "field") initializers.unshift(_);
37+
if (kind === "field") initializers.push(_);
3838
else descriptor[key] = _;
3939
}
4040
}

tests/baselines/reference/esDecorators-classDeclaration-commonjs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
2727
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
2828
if (_ = accept(result.get)) descriptor.get = _;
2929
if (_ = accept(result.set)) descriptor.set = _;
30-
if (_ = accept(result.init)) initializers.unshift(_);
30+
if (_ = accept(result.init)) initializers.push(_);
3131
}
3232
else if (_ = accept(result)) {
33-
if (kind === "field") initializers.unshift(_);
33+
if (kind === "field") initializers.push(_);
3434
else descriptor[key] = _;
3535
}
3636
}

tests/baselines/reference/esDecorators-classDeclaration-sourceMap(target=es2015).js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/esDecorators-classDeclaration-sourceMap(target=es2015).js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/esDecorators-classDeclaration-sourceMap(target=es2015).sourcemap.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ sourceFile:esDecorators-classDeclaration-sourceMap.ts
2525
>>> if (result === null || typeof result !== "object") throw new TypeError("Object expected");
2626
>>> if (_ = accept(result.get)) descriptor.get = _;
2727
>>> if (_ = accept(result.set)) descriptor.set = _;
28-
>>> if (_ = accept(result.init)) initializers.unshift(_);
28+
>>> if (_ = accept(result.init)) initializers.push(_);
2929
>>> }
3030
>>> else if (_ = accept(result)) {
31-
>>> if (kind === "field") initializers.unshift(_);
31+
>>> if (kind === "field") initializers.push(_);
3232
>>> else descriptor[key] = _;
3333
>>> }
3434
>>> }

tests/baselines/reference/esDecorators-classDeclaration-sourceMap(target=es2022).js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/esDecorators-classDeclaration-sourceMap(target=es2022).js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/esDecorators-classDeclaration-sourceMap(target=es2022).sourcemap.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ sourceFile:esDecorators-classDeclaration-sourceMap.ts
2525
>>> if (result === null || typeof result !== "object") throw new TypeError("Object expected");
2626
>>> if (_ = accept(result.get)) descriptor.get = _;
2727
>>> if (_ = accept(result.set)) descriptor.set = _;
28-
>>> if (_ = accept(result.init)) initializers.unshift(_);
28+
>>> if (_ = accept(result.init)) initializers.push(_);
2929
>>> }
3030
>>> else if (_ = accept(result)) {
31-
>>> if (kind === "field") initializers.unshift(_);
31+
>>> if (kind === "field") initializers.push(_);
3232
>>> else descriptor[key] = _;
3333
>>> }
3434
>>> }

0 commit comments

Comments
 (0)