Skip to content

Commit a689bee

Browse files
committed
1 parent 128fc28 commit a689bee

File tree

3 files changed

+249
-110
lines changed

3 files changed

+249
-110
lines changed

README.md

+88-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,94 @@ You can use `node run.mjs` after `npm install` to run and update the tests below
1515

1616
### esbuild (`esbuild@0.21.0`)
1717

18-
✅ All checks passed
18+
<details>
19+
<summary>❌ 16 checks failed (click for details)</summary>
20+
21+
```
22+
❌ Field decorators: Shim (instance field)
23+
Code: this instanceof Foo2
24+
Expected: true
25+
Observed: false
26+
27+
❌ Field decorators: Shim (instance field)
28+
Code: this instanceof Foo2
29+
Expected: true
30+
Observed: false
31+
32+
❌ Field decorators: Shim (instance field)
33+
Code: log + ""
34+
Expected: "false,false,123,true,false,"
35+
Observed: "false,false,123,false,false,"
36+
37+
❌ Field decorators: Shim (static field)
38+
Code: this
39+
Expected: class
40+
Observed: [object global]
41+
42+
❌ Field decorators: Shim (static field)
43+
Code: this
44+
Expected: class
45+
Observed: [object global]
46+
47+
❌ Field decorators: Shim (static field)
48+
Code: log + ""
49+
Expected: "false,false,123,true,false,"
50+
Observed: "false,false,123,false,false,"
51+
52+
❌ Field decorators: Shim (private instance field)
53+
Code: this instanceof Foo2
54+
Expected: true
55+
Observed: false
56+
57+
❌ Field decorators: Shim (private instance field)
58+
Code: this instanceof Foo2
59+
Expected: true
60+
Observed: false
61+
62+
❌ Field decorators: Shim (private instance field)
63+
Code: log + ""
64+
Expected: "false,false,123,true,false,"
65+
Observed: "false,false,123,false,false,"
66+
67+
❌ Field decorators: Shim (private static field)
68+
Code: this
69+
Expected: class
70+
Observed: [object global]
71+
72+
❌ Field decorators: Shim (private static field)
73+
Code: this
74+
Expected: class
75+
Observed: [object global]
76+
77+
❌ Field decorators: Shim (private static field)
78+
Code: log + ""
79+
Expected: "false,false,123,true,false,"
80+
Observed: "false,false,123,false,false,"
81+
82+
❌ Auto-accessor decorators: Shim (instance auto-accessor)
83+
Code: this instanceof Foo2
84+
Expected: true
85+
Observed: false
86+
87+
❌ Auto-accessor decorators: Shim (static auto-accessor)
88+
Code: this
89+
Expected: class
90+
Observed: [object global]
91+
92+
❌ Auto-accessor decorators: Shim (private instance auto-accessor)
93+
Code: this instanceof Foo2
94+
Expected: true
95+
Observed: false
96+
97+
❌ Auto-accessor decorators: Shim (private static auto-accessor)
98+
Code: this
99+
Expected: class
100+
Observed: [object global]
101+
102+
❌ 16 checks failed
103+
```
104+
105+
</details>
19106

20107
### Babel (`@babel/plugin-proposal-decorators@7.24.1`)
21108

decorator-tests.js

+82-56
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,10 @@ const tests = {
916916
'Field decorators: Shim (instance field)': () => {
917917
let log = [];
918918
const dec = (value, ctx) => {
919-
return (x) => log.push(x);
919+
return function (x) {
920+
assertEq(() => this instanceof Foo, true);
921+
return log.push('foo' in this, 'bar' in this, x);
922+
};
920923
};
921924
class Foo {
922925
@dec
@@ -926,40 +929,43 @@ const tests = {
926929
}
927930
assertEq(() => log + '', '');
928931
var obj = new Foo;
929-
assertEq(() => obj.foo, 1);
930-
assertEq(() => obj.bar, 2);
931-
assertEq(() => log + '', '123,');
932-
var obj = new Foo;
933932
assertEq(() => obj.foo, 3);
934-
assertEq(() => obj.bar, 4);
935-
assertEq(() => log + '', '123,,123,');
933+
assertEq(() => obj.bar, 6);
934+
assertEq(() => log + '', 'false,false,123,true,false,');
936935
},
937936
'Field decorators: Shim (static field)': () => {
937+
let foo;
938938
let log = [];
939939
const dec = (value, ctx) => {
940-
return (x) => log.push(x);
941-
};
942-
const fn = (foo, bar) => {
943-
class Foo {
944-
@dec
945-
static foo = 123;
946-
@dec
947-
static bar;
948-
}
949-
assertEq(() => Foo.foo, foo);
950-
assertEq(() => Foo.bar, bar);
940+
return function (x) {
941+
assertEq(() => this, foo);
942+
return log.push('foo' in this, 'bar' in this, x);
943+
};
951944
};
952945
assertEq(() => log + '', '');
953-
fn(1, 2);
954-
assertEq(() => log + '', '123,');
955-
fn(3, 4);
956-
assertEq(() => log + '', '123,,123,');
946+
class Foo {
947+
static {
948+
foo = Foo;
949+
}
950+
@dec
951+
static foo = 123;
952+
@dec
953+
static bar;
954+
}
955+
assertEq(() => Foo.foo, 3);
956+
assertEq(() => Foo.bar, 6);
957+
assertEq(() => log + '', 'false,false,123,true,false,');
957958
},
958959
'Field decorators: Shim (private instance field)': () => {
959960
let log = [];
960961
const dec = (value, ctx) => {
961-
return (x) => log.push(x);
962+
return function (x) {
963+
assertEq(() => this instanceof Foo, true);
964+
return log.push(has$foo(this), has$bar(this), x);
965+
};
962966
};
967+
let has$foo;
968+
let has$bar;
963969
let get$foo;
964970
let get$bar;
965971
class Foo {
@@ -968,46 +974,48 @@ const tests = {
968974
@dec
969975
#bar;
970976
static {
977+
has$foo = x => #foo in x;
978+
has$bar = x => #bar in x;
971979
get$foo = x => x.#foo;
972980
get$bar = x => x.#bar;
973981
}
974982
}
975983
assertEq(() => log + '', '');
976984
var obj = new Foo;
977-
assertEq(() => get$foo(obj), 1);
978-
assertEq(() => get$bar(obj), 2);
979-
assertEq(() => log + '', '123,');
980-
var obj = new Foo;
981985
assertEq(() => get$foo(obj), 3);
982-
assertEq(() => get$bar(obj), 4);
983-
assertEq(() => log + '', '123,,123,');
986+
assertEq(() => get$bar(obj), 6);
987+
assertEq(() => log + '', 'false,false,123,true,false,');
984988
},
985989
'Field decorators: Shim (private static field)': () => {
990+
let foo;
986991
let log = [];
987992
const dec = (value, ctx) => {
988-
return (x) => log.push(x);
989-
};
990-
const fn = (foo, bar) => {
991-
let get$foo;
992-
let get$bar;
993-
class Foo {
994-
@dec
995-
static #foo = 123;
996-
@dec
997-
static #bar;
998-
static {
999-
get$foo = x => x.#foo;
1000-
get$bar = x => x.#bar;
1001-
}
1002-
}
1003-
assertEq(() => get$foo(Foo), foo);
1004-
assertEq(() => get$bar(Foo), bar);
993+
return function (x) {
994+
assertEq(() => this, foo);
995+
return log.push(has$foo(this), has$bar(this), x);
996+
};
1005997
};
1006998
assertEq(() => log + '', '');
1007-
fn(1, 2);
1008-
assertEq(() => log + '', '123,');
1009-
fn(3, 4);
1010-
assertEq(() => log + '', '123,,123,');
999+
let has$foo;
1000+
let has$bar;
1001+
let get$foo;
1002+
let get$bar;
1003+
class Foo {
1004+
static {
1005+
foo = Foo;
1006+
has$foo = x => #foo in x;
1007+
has$bar = x => #bar in x;
1008+
get$foo = x => x.#foo;
1009+
get$bar = x => x.#bar;
1010+
}
1011+
@dec
1012+
static #foo = 123;
1013+
@dec
1014+
static #bar;
1015+
}
1016+
assertEq(() => get$foo(Foo), 3);
1017+
assertEq(() => get$bar(Foo), 6);
1018+
assertEq(() => log + '', 'false,false,123,true,false,');
10111019
},
10121020
'Field decorators: Order (instance field)': () => {
10131021
const log = [];
@@ -2386,7 +2394,10 @@ const tests = {
23862394
let get;
23872395
let set;
23882396
const dec = (target, ctx) => {
2389-
const init = (x) => x + 1;
2397+
function init(x) {
2398+
assertEq(() => this instanceof Foo, true);
2399+
return x + 1;
2400+
}
23902401
get = function () { return target.get.call(this) * 10; };
23912402
set = function (x) { target.set.call(this, x * 2); };
23922403
return { get, set, init };
@@ -2403,15 +2414,22 @@ const tests = {
24032414
assertEq(() => obj.foo, (321 * 2) * 10);
24042415
},
24052416
'Auto-accessor decorators: Shim (static auto-accessor)': () => {
2417+
let foo;
24062418
let get;
24072419
let set;
24082420
const dec = (target, ctx) => {
2409-
const init = (x) => x + 1;
2421+
function init(x) {
2422+
assertEq(() => this, foo);
2423+
return x + 1;
2424+
}
24102425
get = function () { return target.get.call(this) * 10; };
24112426
set = function (x) { target.set.call(this, x * 2); };
24122427
return { get, set, init };
24132428
};
24142429
class Foo {
2430+
static {
2431+
foo = Foo;
2432+
}
24152433
@dec
24162434
static accessor foo = 123;
24172435
}
@@ -2425,7 +2443,10 @@ const tests = {
24252443
let get;
24262444
let set;
24272445
const dec = (target, ctx) => {
2428-
const init = (x) => x + 1;
2446+
function init(x) {
2447+
assertEq(() => this instanceof Foo, true);
2448+
return x + 1;
2449+
}
24292450
get = function () { return target.get.call(this) * 10; };
24302451
set = function (x) { target.set.call(this, x * 2); };
24312452
return { get, set, init };
@@ -2446,23 +2467,28 @@ const tests = {
24462467
assertEq(() => get$foo(obj), (321 * 2) * 10);
24472468
},
24482469
'Auto-accessor decorators: Shim (private static auto-accessor)': () => {
2470+
let foo;
24492471
let get;
24502472
let set;
24512473
const dec = (target, ctx) => {
2452-
const init = (x) => x + 1;
2474+
function init(x) {
2475+
assertEq(() => this, foo);
2476+
return x + 1;
2477+
}
24532478
get = function () { return target.get.call(this) * 10; };
24542479
set = function (x) { target.set.call(this, x * 2); };
24552480
return { get, set, init };
24562481
};
24572482
let get$foo;
24582483
let set$foo;
24592484
class Foo {
2460-
@dec
2461-
static accessor #foo = 123;
24622485
static {
2486+
foo = Foo;
24632487
get$foo = x => x.#foo;
24642488
set$foo = (x, y) => { x.#foo = y; };
24652489
}
2490+
@dec
2491+
static accessor #foo = 123;
24662492
}
24672493
assertEq(() => get$foo(Foo), (123 + 1) * 10);
24682494
assertEq(() => set$foo(Foo, 321), undefined);

0 commit comments

Comments
 (0)