Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix decorator evaluation private environment (#16325)
* enable field-initializers-after-methods-private test * refactor: extract computed key memoisation * handle computed static field in decorated class * handle this and super call when moving computed key assignments * handle other functional context * fix: insert non-static class in the key of the wrapper This change ensures that 1) non static computed key will share the same function context when moved into the non-static class 2) evaluations of decorators and computed keys will always precede static computed keys, given that they have been moved into computed key assignments before * inject computed keys elements to the last non-comptued elements so that we can still preserve the production params [yield], [await] inherited from the outer scope * reorg complex AST factories * add new test cases * copy test cases to 2023-11-misc--to-es-2015 * update test outputs * rewrite findLast usage for legacy node support * make old node happy * fix: use temp class fields to host decorator expr * add class-in-for-loop test * fix: skip decorators and key when replacing super within a class method * copy tests to es2015 * address review comments * fix ts errors * enable the lastPublicElement insertion point for other decorator versions * update test output * ensure typescript test works in both Babel 8 and Babel 7 * make old node happy * workaround pushContainer AST sync issue * small tweaks - rename some routines - improve originalClassPath access, to avoid a full traversal - add more jsdoc coments * output: inject computed key assignments in the first public element * update test output
- Loading branch information
Showing
209 changed files
with
3,756 additions
and
1,761 deletions.
There are no files selected for viewing
449 changes: 368 additions & 81 deletions
449
packages/babel-helper-create-class-features-plugin/src/decorators.ts
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
3 changes: 2 additions & 1 deletion
3
...gin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/context-name/output.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
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
64 changes: 21 additions & 43 deletions
64
...l-decorators/test/fixtures/2021-12-classes--to-es2015/expressions-static-blocks/output.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 |
---|---|---|
@@ -1,73 +1,51 @@ | ||
var _initClass, _A, _temp, _initClass2, _C, _temp2, _initClass3, _D, _temp3, _initClass4, _decorated_class, _temp4, _Class2, _initClass5, _G, _temp5, _initClass6, _decorated_class2, _temp6, _Class3, _initClass7, _H, _temp7, _initClass8, _K, _temp8; | ||
let _A2, _C2, _D2, _ref, _G2, _ref2, _H2, _K2; | ||
var _initClass, _A, _Class, _A3, _initClass2, _C, _Class2, _C3, _initClass3, _D, _Class3, _D3, _initClass4, _decorated_class, _Class4, _Class5, _initClass5, _G, _Class6, _G3, _initClass6, _decorated_class2, _Class7, _Class8, _initClass7, _H, _Class9, _H3, _initClass8, _K, _Class10, _K3; | ||
const dec = () => {}; | ||
const A = (new (_temp = class extends babelHelpers.identity { | ||
const A = (new (_A2 = (_A3 = class A {}, [_A, _initClass] = babelHelpers.applyDecs(_A3, [], [dec]), _A3), (_Class = class extends babelHelpers.identity { | ||
constructor() { | ||
super(_A), (() => {})(), _initClass(); | ||
} | ||
}, (_A2 => { | ||
class A {} | ||
_A2 = A; | ||
[_A, _initClass] = babelHelpers.applyDecs(_A2, [], [dec]); | ||
})(), _temp)(), _A); | ||
const B = (new (_temp2 = class extends babelHelpers.identity { | ||
}, babelHelpers.defineProperty(_Class, _A2, void 0), _Class))(), _A); | ||
const B = (new (_C2 = (_C3 = class C {}, [_C, _initClass2] = babelHelpers.applyDecs(_C3, [], [dec]), _C3), (_Class2 = class extends babelHelpers.identity { | ||
constructor() { | ||
super(_C), (() => {})(), _initClass2(); | ||
} | ||
}, (_C2 => { | ||
class C {} | ||
_C2 = C; | ||
[_C, _initClass2] = babelHelpers.applyDecs(_C2, [], [dec]); | ||
})(), _temp2)(), _C); | ||
const D = (new (_temp3 = class extends babelHelpers.identity { | ||
}, babelHelpers.defineProperty(_Class2, _C2, void 0), _Class2))(), _C); | ||
const D = (new (_D2 = (_D3 = class D {}, [_D, _initClass3] = babelHelpers.applyDecs(_D3, [], [dec]), _D3), (_Class3 = class extends babelHelpers.identity { | ||
constructor() { | ||
super(_D), (() => {})(), _initClass3(); | ||
} | ||
}, (_D2 => { | ||
class D {} | ||
_D2 = D; | ||
[_D, _initClass3] = babelHelpers.applyDecs(_D2, [], [dec]); | ||
})(), _temp3)(), _D); | ||
const E = ((new (_temp4 = class extends babelHelpers.identity { | ||
}, babelHelpers.defineProperty(_Class3, _D2, void 0), _Class3))(), _D); | ||
const E = ((new (_ref = (_Class5 = class _ref {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs(_Class5, [], [dec]), _Class5), (_Class4 = class extends babelHelpers.identity { | ||
constructor() { | ||
super(_decorated_class), (() => {})(), _initClass4(); | ||
} | ||
}, (_Class2 = class {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs(_Class2, [], [dec])), _temp4)(), _decorated_class), 123); | ||
const F = [(new (_temp5 = class extends babelHelpers.identity { | ||
}, babelHelpers.defineProperty(_Class4, _ref, void 0), _Class4))(), _decorated_class), 123); | ||
const F = [(new (_G2 = (_G3 = class G {}, [_G, _initClass5] = babelHelpers.applyDecs(_G3, [], [dec]), _G3), (_Class6 = class extends babelHelpers.identity { | ||
constructor() { | ||
super(_G), (() => {})(), _initClass5(); | ||
} | ||
}, (_G2 => { | ||
class G {} | ||
_G2 = G; | ||
[_G, _initClass5] = babelHelpers.applyDecs(_G2, [], [dec]); | ||
})(), _temp5)(), _G), (new (_temp6 = class extends babelHelpers.identity { | ||
}, babelHelpers.defineProperty(_Class6, _G2, void 0), _Class6))(), _G), (new (_ref2 = (_Class8 = class _ref2 {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs(_Class8, [], [dec]), _Class8), (_Class7 = class extends babelHelpers.identity { | ||
constructor() { | ||
super(_decorated_class2), (() => {})(), _initClass6(); | ||
} | ||
}, (_Class3 = class {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs(_Class3, [], [dec])), _temp6)(), _decorated_class2)]; | ||
const H = (new (_temp7 = class extends babelHelpers.identity { | ||
}, babelHelpers.defineProperty(_Class7, _ref2, void 0), _Class7))(), _decorated_class2)]; | ||
const H = (new (_H2 = (_H3 = class H extends I {}, [_H, _initClass7] = babelHelpers.applyDecs(_H3, [], [dec]), _H3), (_Class9 = class extends babelHelpers.identity { | ||
constructor() { | ||
super(_H), (() => {})(), _initClass7(); | ||
} | ||
}, (_H2 => { | ||
class H extends I {} | ||
_H2 = H; | ||
[_H, _initClass7] = babelHelpers.applyDecs(_H2, [], [dec]); | ||
})(), _temp7)(), _H); | ||
const J = (new (_temp8 = class extends babelHelpers.identity { | ||
}, babelHelpers.defineProperty(_Class9, _H2, void 0), _Class9))(), _H); | ||
const J = (new (_K2 = (_K3 = class K extends L {}, [_K, _initClass8] = babelHelpers.applyDecs(_K3, [], [dec]), _K3), (_Class10 = class extends babelHelpers.identity { | ||
constructor() { | ||
super(_K), (() => {})(), _initClass8(); | ||
} | ||
}, (_K2 => { | ||
class K extends L {} | ||
_K2 = K; | ||
[_K, _initClass8] = babelHelpers.applyDecs(_K2, [], [dec]); | ||
})(), _temp8)(), _K); | ||
}, babelHelpers.defineProperty(_Class10, _K2, void 0), _Class10))(), _K); | ||
function classFactory() { | ||
var _initClass9, _decorated_class3, _temp9, _Class5; | ||
return new (_temp9 = class extends babelHelpers.identity { | ||
let _ref3; | ||
var _initClass9, _decorated_class3, _Class11, _Class12; | ||
return new (_ref3 = (_Class12 = class _ref3 {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs(_Class12, [], [dec]), _Class12), (_Class11 = class extends babelHelpers.identity { | ||
constructor() { | ||
super(_decorated_class3), (() => {})(), _initClass9(); | ||
} | ||
}, (_Class5 = class {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs(_Class5, [], [dec])), _temp9)(), _decorated_class3; | ||
}, babelHelpers.defineProperty(_Class11, _ref3, void 0), _Class11))(), _decorated_class3; | ||
} |
19 changes: 6 additions & 13 deletions
19
...lugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.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 |
---|---|---|
@@ -1,24 +1,17 @@ | ||
var _initClass, _temp, _initClass2, _temp2; | ||
let _Foo2, _Bar2; | ||
var _initClass, _Class, _Foo3, _initClass2, _Class2, _Bar3; | ||
const dec = () => {}; | ||
let _Foo; | ||
new (_temp = class extends babelHelpers.identity { | ||
new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs(_Foo3, [], [dec]), _Foo3), (_Class = class extends babelHelpers.identity { | ||
constructor() { | ||
(super(_Foo), babelHelpers.defineProperty(this, "field", 123)), _initClass(); | ||
} | ||
}, (_Foo2 => { | ||
class Foo {} | ||
_Foo2 = Foo; | ||
[_Foo, _initClass] = babelHelpers.applyDecs(_Foo2, [], [dec]); | ||
})(), _temp)(); | ||
}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); | ||
let _Bar; | ||
new (_temp2 = class extends babelHelpers.identity { | ||
new (_Bar2 = (_Bar3 = class Bar extends _Foo {}, [_Bar, _initClass2] = babelHelpers.applyDecs(_Bar3, [], [dec]), _Bar3), (_Class2 = class extends babelHelpers.identity { | ||
constructor() { | ||
(super(_Bar), babelHelpers.defineProperty(this, "field", ((() => { | ||
this.otherField = 456; | ||
})(), 123))), _initClass2(); | ||
} | ||
}, (_Bar2 => { | ||
class Bar extends _Foo {} | ||
_Bar2 = Bar; | ||
[_Bar, _initClass2] = babelHelpers.applyDecs(_Bar2, [], [dec]); | ||
})(), _temp2)(); | ||
}, babelHelpers.defineProperty(_Class2, _Bar2, void 0), _Class2))(); |
27 changes: 12 additions & 15 deletions
27
...xtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.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
11 changes: 4 additions & 7 deletions
11
...sal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.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 |
---|---|---|
@@ -1,16 +1,13 @@ | ||
var _initClass, _temp; | ||
let _Foo2; | ||
var _initClass, _Class, _Foo3; | ||
const dec = () => {}; | ||
let _Foo; | ||
new (_temp = class extends babelHelpers.identity { | ||
new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs(_Foo3, [], [dec]), _Foo3), (_Class = class extends babelHelpers.identity { | ||
constructor() { | ||
(super(_Foo), babelHelpers.defineProperty(this, "field", ((() => { | ||
this; | ||
})(), this))), (() => { | ||
this; | ||
})(), _initClass(); | ||
} | ||
}, (_Foo2 => { | ||
class Foo {} | ||
_Foo2 = Foo; | ||
[_Foo, _initClass] = babelHelpers.applyDecs(_Foo2, [], [dec]); | ||
})(), _temp)(); | ||
}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); |
11 changes: 4 additions & 7 deletions
11
...plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
var _initClass, _temp; | ||
let _Foo2; | ||
var _initClass, _Class, _Foo3; | ||
const dec = () => {}; | ||
let _Foo; | ||
new (_temp = class extends babelHelpers.identity { | ||
new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs(_Foo3, [], [dec]), _Foo3), (_Class = class extends babelHelpers.identity { | ||
constructor() { | ||
(super(_Foo), babelHelpers.defineProperty(this, "foo", new _Foo())), _initClass(); | ||
} | ||
}, (_Foo2 => { | ||
class Foo {} | ||
_Foo2 = Foo; | ||
[_Foo, _initClass] = babelHelpers.applyDecs(_Foo2, [], [dec]); | ||
})(), _temp)(); | ||
}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); | ||
const foo = new _Foo(); |
Oops, something went wrong.