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
Move the generator body to a gen IIFE when compiling its params #15081
Merged
Merged
Changes from all commits
Commits
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
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
packages/babel-plugin-transform-parameters/test/fixtures/parameters/generator/input.ts
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 @@ | ||
function* fn(a, [], b = 2) { | ||
yield a; | ||
yield arguments; | ||
yield this; | ||
return b; | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-transform-parameters/test/fixtures/parameters/generator/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,3 @@ | ||
{ | ||
"plugins": ["transform-parameters"] | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/babel-plugin-transform-parameters/test/fixtures/parameters/generator/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,12 @@ | ||
function fn(a, _ref) { | ||
var _arguments = arguments, | ||
_this = this; | ||
let [] = _ref; | ||
let b = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; | ||
return function* () { | ||
yield a; | ||
yield _arguments; | ||
yield _this; | ||
return b; | ||
}(); | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/babel-preset-env/test/fixtures/plugins-integration/issue-15012/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,13 @@ | ||
function* f([]) {} | ||
|
||
expect(() => f()).toThrow(); | ||
|
||
let called = false; | ||
let run = false; | ||
function* g(x = (called = true)) { | ||
run = true; | ||
} | ||
|
||
g(); | ||
expect(called).toBe(true); | ||
expect(run).toBe(false); |
3 changes: 3 additions & 0 deletions
3
packages/babel-preset-env/test/fixtures/plugins-integration/issue-15012/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,3 @@ | ||
function* f([]) {} | ||
|
||
function* g(x = fn()) {} |
3 changes: 3 additions & 0 deletions
3
packages/babel-preset-env/test/fixtures/plugins-integration/issue-15012/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,3 @@ | ||
{ | ||
"presets": ["env"] | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/babel-preset-env/test/fixtures/plugins-integration/issue-15012/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,28 @@ | ||
function f(_ref) { | ||
var _ref2 = babelHelpers.toArray(_ref); | ||
return /*#__PURE__*/babelHelpers.regeneratorRuntime().mark(function _callee() { | ||
return babelHelpers.regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})(); | ||
} | ||
function g() { | ||
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : fn(); | ||
return /*#__PURE__*/babelHelpers.regeneratorRuntime().mark(function _callee2() { | ||
return babelHelpers.regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
})(); | ||
} |
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.
Should the wrapper be a generator? So that
fn.constructor
still work after transpiled.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.
No, because a generator would start paused.
yield* fn()
already works, becausefn()
returns an instance ofGeneratorFunction
, which is iterable.fn.constructor
is notGeneratorFunction
anymore, but there are already many cases where the prototype of a function is not correct and this is just another one.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.
Another reason will be that yield expression is not allowed in formal parameters.