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: Throw error when compiling super()
in arrow functions with default / rest parameters
#15163
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
073b3b0
Fix: Throw when super in arrow with default / rest
SuperSodaSea c66111b
Add allowInsertArrowWithRest and improve throw
SuperSodaSea db066ab
Merge branch 'main' into fix/15148
SuperSodaSea fd549b3
Update packages/babel-traverse/src/path/conversion.ts
SuperSodaSea 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
6 changes: 6 additions & 0 deletions
6
.../babel-plugin-transform-arrow-functions/test/fixtures/arrow-functions/super-call/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,6 @@ | ||
class Bar extends Foo { | ||
constructor() { | ||
let f = () => super(); | ||
f(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...el-plugin-transform-arrow-functions/test/fixtures/arrow-functions/super-call/options.json
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,4 @@ | ||
{ | ||
"plugins": ["transform-arrow-functions"], | ||
"throws": "When using '@babel/plugin-transform-arrow-functions', it's not possible to compile `super()` in an arrow function without compiling classes.\nPlease add '@babel/plugin-transform-classes' to your Babel configuration." | ||
} |
6 changes: 6 additions & 0 deletions
6
.../babel-plugin-transform-arrow-functions/test/fixtures/arrow-functions/super-prop/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,6 @@ | ||
class Bar extends Foo { | ||
constructor() { | ||
let f = () => super.x; | ||
f(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...el-plugin-transform-arrow-functions/test/fixtures/arrow-functions/super-prop/options.json
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,4 @@ | ||
{ | ||
"plugins": ["transform-arrow-functions"], | ||
"throws": "When using '@babel/plugin-transform-arrow-functions', it's not possible to compile `super.prop` in an arrow function without compiling classes.\nPlease add '@babel/plugin-transform-classes' to your Babel configuration." | ||
} |
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
6 changes: 6 additions & 0 deletions
6
...nsform-parameters/test/fixtures/parameters/arrow-default-super-no-classes-plugin/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,6 @@ | ||
class Bar extends Foo { | ||
constructor() { | ||
let f = (x = super()) => x; | ||
f(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...rm-parameters/test/fixtures/parameters/arrow-default-super-no-classes-plugin/options.json
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,4 @@ | ||
{ | ||
"plugins": ["transform-parameters"], | ||
"throws": "When using '@babel/plugin-transform-parameters', it's not possible to compile `super()` in an arrow function with default or rest parameters without compiling classes.\nPlease add '@babel/plugin-transform-classes' to your Babel configuration." | ||
} |
6 changes: 6 additions & 0 deletions
6
...transform-parameters/test/fixtures/parameters/arrow-rest-super-no-classes-plugin/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,6 @@ | ||
class Bar extends Foo { | ||
constructor() { | ||
let f = (...args) => super(...args); | ||
f(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...sform-parameters/test/fixtures/parameters/arrow-rest-super-no-classes-plugin/options.json
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,4 @@ | ||
{ | ||
"plugins": ["transform-parameters"], | ||
"throws": "When using '@babel/plugin-transform-parameters', it's not possible to compile `super()` in an arrow function with default or rest parameters without compiling classes.\nPlease add '@babel/plugin-transform-classes' to your Babel configuration." | ||
} |
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
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.
Note that the input here is very similar to how we would transform
super()
:babel/packages/babel-traverse/test/arrow-transform.js
Lines 53 to 71 in 9862d42
My gut is that it should have been fixed in how we generate the super call:
babel/packages/babel-traverse/src/path/conversion.ts
Line 652 in 9862d42
We already have an arrow function check when constructing
supercall
,babel/packages/babel-traverse/src/path/conversion.ts
Lines 287 to 291 in 9862d42
somehow it does not throw, probably because
allowInsertArrow
is not properly passed.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.
Perhaps we can add
allowInsertArrow: false
here?babel/packages/babel-plugin-transform-parameters/src/index.ts
Lines 48 to 49 in 073b3b0
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 to add
allowInsertArrow: false
and it fails on #13939 related tests...:thinking:Maybe we need something like
allowInsertArrowWithRest
?