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
Improve array destructuring spec compliance #15183
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e9a06d5
Empty array destructuring shouldn't call `next()`
SuperSodaSea a165501
Add missing variable declaration
SuperSodaSea 575d0cc
Should call `return()`
SuperSodaSea b8bc947
Simplify code
SuperSodaSea 6936cde
Fix compare
SuperSodaSea 6f41ba0
Fix code
SuperSodaSea 6820861
Add tests for #15154 and #15168
SuperSodaSea b0c4eac
Should check result of `iterator.return()`
SuperSodaSea 42d95d5
Fix #15168 test
SuperSodaSea 94f03b9
`next` should only eval once
SuperSodaSea 4f951f3
Simplify `iterableToArrayLimitLoose`
SuperSodaSea e952071
Merge branch 'main' into fix/15168
SuperSodaSea f53c65d
Merge branch 'main' into fix/15168
SuperSodaSea 1f404cb
Move helpers to a separate file
nicolo-ribaudo e7e040f
Update fixtures
nicolo-ribaudo 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
23 changes: 23 additions & 0 deletions
23
...el-plugin-transform-destructuring/test/fixtures/destructuring/empty-array-pattern/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,23 @@ | ||
expect(function () { | ||
var [] = null; | ||
}).toThrow("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
|
||
expect(function () { | ||
var [] = 42; | ||
}).toThrow("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
|
||
expect(function () { | ||
var [] = {}; | ||
}).toThrow("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
|
||
expect(function () { | ||
var [] = { [Symbol.iterator]: function() {} }; | ||
}).toThrow("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
|
||
var [] = []; | ||
var [] = [0, 1, 2]; | ||
var [] = "foo"; | ||
var [] = (function*() { throw new Error("Should not throw"); })(); | ||
var [] = { [Symbol.iterator]: function() { return {}; } } | ||
var [] = { [Symbol.iterator]: function() { return function() {}; } } | ||
var [] = { [Symbol.iterator]: async function*() {} } |
12 changes: 12 additions & 0 deletions
12
...l-plugin-transform-destructuring/test/fixtures/destructuring/empty-array-pattern/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,12 @@ | ||
var [] = null; | ||
var [] = 42; | ||
var [] = {}; | ||
var [] = { [Symbol.iterator]: function() {} }; | ||
|
||
var [] = []; | ||
var [] = [0, 1, 2]; | ||
var [] = "foo"; | ||
var [] = (function*() { throw new Error("Should not throw"); })(); | ||
var [] = { [Symbol.iterator]: function() { return {}; } } | ||
var [] = { [Symbol.iterator]: function() { return function() {}; } } | ||
var [] = { [Symbol.iterator]: async function*() {} } |
53 changes: 53 additions & 0 deletions
53
...-plugin-transform-destructuring/test/fixtures/destructuring/empty-array-pattern/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,53 @@ | ||
var _ref = null, | ||
_ref2 = babelHelpers.slicedToArray(_ref, 0); | ||
var _ = 42, | ||
_ref3 = babelHelpers.slicedToArray(_, 0); | ||
var _ref4 = {}, | ||
_ref5 = babelHelpers.slicedToArray(_ref4, 0); | ||
var _Symbol$iterator = { | ||
[Symbol.iterator]: function () {} | ||
}, | ||
_Symbol$iterator2 = babelHelpers.slicedToArray(_Symbol$iterator, 0); | ||
var _ref6 = [0, 1, 2]; | ||
var _foo = "foo", | ||
_foo2 = babelHelpers.slicedToArray(_foo, 0); | ||
var _ref7 = /*#__PURE__*/babelHelpers.regeneratorRuntime().mark(function _callee() { | ||
return babelHelpers.regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
throw new Error("Should not throw"); | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})(), | ||
_ref8 = babelHelpers.slicedToArray(_ref7, 0); | ||
var _Symbol$iterator3 = { | ||
[Symbol.iterator]: function () { | ||
return {}; | ||
} | ||
}, | ||
_Symbol$iterator4 = babelHelpers.slicedToArray(_Symbol$iterator3, 0); | ||
var _Symbol$iterator5 = { | ||
[Symbol.iterator]: function () { | ||
return function () {}; | ||
} | ||
}, | ||
_Symbol$iterator6 = babelHelpers.slicedToArray(_Symbol$iterator5, 0); | ||
var _Symbol$iterator7 = { | ||
[Symbol.iterator]: /*#__PURE__*/babelHelpers.regeneratorRuntime().mark(function _callee2() { | ||
return babelHelpers.regeneratorRuntime().async(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, null, Promise); | ||
}) | ||
}, | ||
_Symbol$iterator8 = babelHelpers.slicedToArray(_Symbol$iterator7, 0); |
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
2 changes: 1 addition & 1 deletion
2
packages/babel-plugin-transform-modules-commonjs/test/fixtures/regression/T7199/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
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
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.
I'm from mobile so this code might be completely wrong, but does it work?
We should try keeping these helpers as small as possible :)
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 change it to this:
Does this looks good?
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.
Oh, that seems to be not working since the order of
_n = true
is changed... I'll revert the change.