-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support mutated outer decorated class binding (#16387)
* fix: support mutated outer decorated class binding * enable es2015 test and add todo item * make node 6 happy
- Loading branch information
Showing
9 changed files
with
1,041 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
...osal-decorators/test/fixtures/2023-11-misc--to-es2015/outer-class-binding-mutated/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
{ | ||
"class binding in plain class, decorated field, and computed keys" | ||
const errs = []; | ||
const fns = []; | ||
const capture = function (fn) { | ||
fns.push(fn); | ||
return () => {} | ||
} | ||
const assertUninitialized = function (fn) { | ||
try { | ||
fn(); | ||
} catch (err) { | ||
errs.push(err); | ||
} finally { | ||
return () => {} | ||
} | ||
} | ||
|
||
capture(() => K); | ||
assertUninitialized(() => K); | ||
|
||
class K { | ||
@capture(() => K) @assertUninitialized(() => K) [(capture(() => K), assertUninitialized(() => K))] | ||
} | ||
|
||
const E = ReferenceError; | ||
expect(errs.map(e => e.constructor)).toEqual([E, E, E]); | ||
|
||
const C = K; | ||
// expect(fns.map(fn => fn())).toEqual([C, C, C]); | ||
// todo: remove these three and enable the assertions above when we properly handle class tdz | ||
expect(fns[0]()).toEqual(C); | ||
expect(fns[1]).toThrow(E); | ||
expect(fns[2]).toThrow(E); | ||
|
||
K = null; | ||
|
||
// expect(fns.map(fn => fn())).toEqual([null, C, C]); | ||
// todo: remove these three and enable the assertions above when we properly handle class tdz | ||
expect(fns[0]()).toEqual(null); | ||
expect(fns[1]).toThrow(E); | ||
expect(fns[2]).toThrow(E); | ||
} | ||
|
||
{ | ||
"class binding in decorated class, decorated field, and computed keys" | ||
const errs = []; | ||
const fns = []; | ||
const capture = function (fn) { | ||
fns.push(fn); | ||
return () => {} | ||
} | ||
const assertUninitialized = function (fn) { | ||
try { | ||
fn(); | ||
} catch (err) { | ||
errs.push(err); | ||
} finally { | ||
return () => {} | ||
} | ||
} | ||
|
||
@capture(() => K) | ||
@assertUninitialized(() => K) | ||
class K { | ||
//todo: add the assertUninitialized decorator when we properly implement class tdz | ||
@capture(() => K) [capture(() => K)] | ||
} | ||
|
||
const E = ReferenceError; | ||
expect(errs.map(e => e.constructor)).toEqual([E]); | ||
|
||
const C = K; | ||
expect(fns.map(fn => fn())).toEqual([C, C, C]); | ||
|
||
[K = null] = []; | ||
|
||
expect(fns.map(fn => fn())).toEqual([null, C, C]); | ||
} | ||
|
||
{ | ||
"class binding in decorated class, decorated static field, and computed keys" | ||
const errs = []; | ||
const fns = []; | ||
const capture = function (fn) { | ||
fns.push(fn); | ||
return () => {} | ||
} | ||
const assertUninitialized = function (fn) { | ||
try { | ||
fn(); | ||
} catch (err) { | ||
errs.push(err); | ||
} finally { | ||
return () => {} | ||
} | ||
} | ||
|
||
@capture(() => K) | ||
@assertUninitialized(() => K) | ||
class K { | ||
//todo: add the assertUninitialized decorator when we properly implement class tdz | ||
@capture(() => K) static [capture(() => K)] | ||
} | ||
|
||
const E = ReferenceError; | ||
expect(errs.map(e => e.constructor)).toEqual([E]); | ||
|
||
const C = K; | ||
expect(fns.map(fn => fn())).toEqual([C, C, C]); | ||
|
||
({ K = null } = {}); | ||
|
||
expect(fns.map(fn => fn())).toEqual([null, C, C]); | ||
} | ||
|
||
{ | ||
"class binding in decorated class, decorated static method, and computed keys with await"; | ||
(async () => { | ||
const errs = []; | ||
const fns = []; | ||
const capture = function (fn) { | ||
fns.push(fn); | ||
return () => {} | ||
} | ||
const assertUninitialized = function (fn) { | ||
try { | ||
fn(); | ||
} catch (err) { | ||
errs.push(err); | ||
} finally { | ||
return () => {} | ||
} | ||
} | ||
|
||
@capture(await (() => K)) | ||
@assertUninitialized(await (() => K)) | ||
class K { | ||
//todo: add the assertUninitialized decorator when we properly implement class tdz | ||
@capture(await (() => K)) static [capture(await (() => K))]() {} | ||
} | ||
|
||
const E = ReferenceError; | ||
expect(errs.map(e => e.constructor)).toEqual([E]); | ||
|
||
const C = K; | ||
expect(fns.map(fn => fn())).toEqual([C, C, C]); | ||
|
||
[K] = [null]; | ||
|
||
expect(fns.map(fn => fn())).toEqual([null, C, C]); | ||
})() | ||
} |
Oops, something went wrong.