-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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: Decorators when super()
exists and protoInit
is not needed
#16385
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
24 changes: 24 additions & 0 deletions
24
...ages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/super/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,24 @@ | ||
function decorate() { | ||
return function (target, context) {} | ||
} | ||
|
||
class Test { | ||
@decorate() | ||
accessor foo = 42; | ||
|
||
constructor() { | ||
} | ||
} | ||
|
||
new Test() | ||
|
||
class TestChild extends Test { | ||
@decorate() | ||
accessor bar = 1; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
} | ||
|
||
const r = new TestChild(); | ||
25 changes: 25 additions & 0 deletions
25
...ges/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/super/input.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,25 @@ | ||
function decorate() { | ||
return function (target, context) {} | ||
} | ||
|
||
class Test { | ||
@decorate() | ||
accessor foo = 42; | ||
|
||
constructor() { | ||
console.log('hello'); | ||
} | ||
} | ||
|
||
new Test() | ||
|
||
class TestChild extends Test { | ||
@decorate() | ||
accessor bar = 1; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
} | ||
|
||
const r = new TestChild(); |
37 changes: 37 additions & 0 deletions
37
...es/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/super/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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var _Test, _TestChild; | ||
let _init_foo, _init_extra_foo, _init_bar, _init_extra_bar; | ||
function decorate() { | ||
return function (target, context) {}; | ||
} | ||
var _A = /*#__PURE__*/new WeakMap(); | ||
class Test { | ||
get foo() { | ||
return babelHelpers.classPrivateFieldGet2(_A, this); | ||
} | ||
set foo(v) { | ||
babelHelpers.classPrivateFieldSet2(_A, this, v); | ||
} | ||
constructor() { | ||
babelHelpers.classPrivateFieldInitSpec(this, _A, _init_foo(this, 42)); | ||
_init_extra_foo(this); | ||
console.log('hello'); | ||
} | ||
} | ||
_Test = Test; | ||
[_init_foo, _init_extra_foo] = babelHelpers.applyDecs2311(_Test, [], [[decorate(), 1, "foo"]]).e; | ||
new Test(); | ||
var _A2 = /*#__PURE__*/new WeakMap(); | ||
class TestChild extends Test { | ||
get bar() { | ||
return babelHelpers.classPrivateFieldGet2(_A2, this); | ||
} | ||
set bar(v) { | ||
babelHelpers.classPrivateFieldSet2(_A2, this, v); | ||
} | ||
constructor() { | ||
(super(), babelHelpers.classPrivateFieldInitSpec(this, _A2, _init_bar(this, 1)), this), _init_extra_bar(this); | ||
} | ||
} | ||
_TestChild = TestChild; | ||
[_init_bar, _init_extra_bar] = babelHelpers.applyDecs2311(_TestChild, [], [[decorate(), 1, "bar"]], 0, void 0, Test).e; | ||
const r = new TestChild(); |
24 changes: 24 additions & 0 deletions
24
packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/super/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,24 @@ | ||
function decorate() { | ||
return function (target, context) {} | ||
} | ||
|
||
class Test { | ||
@decorate() | ||
accessor foo = 42; | ||
|
||
constructor() { | ||
} | ||
} | ||
|
||
new Test() | ||
|
||
class TestChild extends Test { | ||
@decorate() | ||
accessor bar = 1; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
} | ||
|
||
const r = new TestChild(); |
25 changes: 25 additions & 0 deletions
25
packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/super/input.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,25 @@ | ||
function decorate() { | ||
return function (target, context) {} | ||
} | ||
|
||
class Test { | ||
@decorate() | ||
accessor foo = 42; | ||
|
||
constructor() { | ||
console.log('hello'); | ||
} | ||
} | ||
|
||
new Test() | ||
|
||
class TestChild extends Test { | ||
@decorate() | ||
accessor bar = 1; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
} | ||
|
||
const r = new TestChild(); |
37 changes: 37 additions & 0 deletions
37
packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/super/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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
let _init_foo, _init_extra_foo, _init_bar, _init_extra_bar; | ||
function decorate() { | ||
return function (target, context) {}; | ||
} | ||
class Test { | ||
static { | ||
[_init_foo, _init_extra_foo] = babelHelpers.applyDecs2311(this, [], [[decorate(), 1, "foo"]]).e; | ||
} | ||
#A = _init_foo(this, 42); | ||
get foo() { | ||
return this.#A; | ||
} | ||
set foo(v) { | ||
this.#A = v; | ||
} | ||
constructor() { | ||
_init_extra_foo(this); | ||
console.log('hello'); | ||
} | ||
} | ||
new Test(); | ||
class TestChild extends Test { | ||
static { | ||
[_init_bar, _init_extra_bar] = babelHelpers.applyDecs2311(this, [], [[decorate(), 1, "bar"]], 0, void 0, Test).e; | ||
} | ||
#A = _init_bar(this, 1); | ||
get bar() { | ||
return this.#A; | ||
} | ||
set bar(v) { | ||
this.#A = v; | ||
} | ||
constructor() { | ||
super(), _init_extra_bar(this); | ||
} | ||
} | ||
const r = new TestChild(); |
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.
In contrast with
initProto-existing-derived-constructor
, can you rename this test toinitField-existing-derived-constructor
?I suggest we also add some behaviour assertions like we have done in that test.
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.
I tried porting all the tests but unfortunately couldn't get them all to work so I just added a simple test.🤦♂️
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 you push the new tests? Even if they are failing, we can still investigate for sure.
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.
I pushed it, but it doesn't show up on github, I will try force pushing.🤔
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.
I re-added all the tests, but I'm not sure if I tested the behavior well, thanks for the review!