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
Fix decorator evaluation private environment #16325
Merged
JLHwung
merged 27 commits into
babel:main
from
JLHwung:fix-decorator-evaluation-private-environment
Mar 6, 2024
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
198e865
enable field-initializers-after-methods-private test
JLHwung 06aea1a
refactor: extract computed key memoisation
JLHwung c30a189
handle computed static field in decorated class
JLHwung 782505c
handle this and super call when moving computed key assignments
JLHwung 6dd3198
handle other functional context
JLHwung 2d34eeb
fix: insert non-static class in the key of the wrapper
JLHwung 125a837
inject computed keys elements to the last non-comptued elements
JLHwung efbce42
reorg complex AST factories
JLHwung 7714626
add new test cases
JLHwung 4ce976c
copy test cases to 2023-11-misc--to-es-2015
JLHwung 713ad4c
update test outputs
JLHwung bf86824
rewrite findLast usage for legacy node support
JLHwung fff405f
make old node happy
JLHwung f4314e5
fix: use temp class fields to host decorator expr
JLHwung 2cd5bcc
add class-in-for-loop test
JLHwung 707b91c
fix: skip decorators and key when replacing super within a class method
JLHwung f62c5c2
copy tests to es2015
JLHwung 6969fd4
address review comments
JLHwung 4c9c493
fix ts errors
JLHwung bdee20d
enable the lastPublicElement insertion point for other decorator vers…
JLHwung d33d87b
update test output
JLHwung 7ad03e3
ensure typescript test works in both Babel 8 and Babel 7
JLHwung ccb441a
make old node happy
JLHwung 9073384
workaround pushContainer AST sync issue
JLHwung af8caa6
small tweaks
JLHwung e856f3c
output: inject computed key assignments in the first public element
JLHwung 20426d6
update test output
JLHwung File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we revert this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is intentional as it will fix an integration issue with the class properties transform. For context see https://github.com/babel/babel/pull/10029/files#r287785963
In this REPL example
when we apply the decorators, static block and class properties plugin, it should print
0,1,2,3,4
but currently it prints4,4,4,4,4
.I can add a new test case for this issue.
If the output size is the concern, I can open a new PR to register all variable as the
let
binding, as it will introduce much more test output changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please add a test!
Regarding to output size, we should first aim at correctness and then optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I didn't notice this was a bug fix, I thought the increased size didn't matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2cd5bcc