Implement iterableIsArray and arrayLikeIsIterable assumptions#12489
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/34972/ |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 1e64d8f:
|
- transform-destructuring - transform-for-of - transform-spread
- transform-destructuring - transform-for-of - transform-spread
1e64d8f to
a029176
Compare
JLHwung
left a comment
There was a problem hiding this comment.
Are we going to rename allowArrayLike to arrayLikeIsIterable in Babel 8?
|
If we keep it yes; I'm not sure if it's it worth to keep it around given the new |
| const arrayOnlySpread = loose; | ||
| const iterableIsArray = api.assumption("iterableIsArray") ?? options.loose; | ||
| const arrayLikeIsIterable = | ||
| options.allowArrayLike ?? api.assumption("arrayLikeIsIterable"); |
| const { loose, allowArrayLike } = options; | ||
| const iterableIsArray = api.assumption("iterableIsArray") ?? options.loose; | ||
| const arrayLikeIsIterable = | ||
| options.allowArrayLike ?? api.assumption("arrayLikeIsIterable"); |
There was a problem hiding this comment.
The reason for swapping the order here is that, while loose is generic (and thus it's good to keep it as a fallback value), this option was explicitly designed for this assumption and it has a quite specific name. Thus I followed the "locality principle": since they have the same specificity, the option closer to the plugin has the precedence.
I wasn't 100% sure of doing this, so I'm open to change it to match loose's behavior if no one else thinks that options.allowArrayLike should take precedence.
There was a problem hiding this comment.
It makes sense to me that when options.allowArrayLike is specified, that it should take precedence over api.assumption("arrayLikeIsIterable").
- `mutableTemplateObject` and `ignoreToPrimitiveHint` (#12408) - `setClassMethods` (#12407) - `setComputedProperties` (#12490) - `ignoreFunctionLength` (#12491) - `noDocumentAll` (#12481) - `iterableIsArray` and `arrayLikeIsIterable` (#12489) - `pureGetters` (#12504) - `skipForOfIteratorClosing` (#12496) - `objectRestNoSymbols`, `setSpreadProperties` and `pureGetters` (#12505) - `noNewArrows` (#12613, #12793) - `setPublicClassFields` and `privateFieldsAsProperties` (#12497) - `constantReexports` and `enumerableModuleMeta` (#12618) - `constantSuper`, `superIsCallableConstructor` and `noClassCalls` (#12726) Co-authored-by: Justin Ridgewell <justin@ridgewell.name> Co-authored-by: Huáng Jùnliàng <JLHwung@users.noreply.github.com>
- `mutableTemplateObject` and `ignoreToPrimitiveHint` (#12408) - `setClassMethods` (#12407) - `setComputedProperties` (#12490) - `ignoreFunctionLength` (#12491) - `noDocumentAll` (#12481) - `iterableIsArray` and `arrayLikeIsIterable` (#12489) - `pureGetters` (#12504) - `skipForOfIteratorClosing` (#12496) - `objectRestNoSymbols`, `setSpreadProperties` and `pureGetters` (#12505) - `noNewArrows` (#12613, #12793) - `setPublicClassFields` and `privateFieldsAsProperties` (#12497) - `constantReexports` and `enumerableModuleMeta` (#12618) - `constantSuper`, `superIsCallableConstructor` and `noClassCalls` (#12726) Co-authored-by: Justin Ridgewell <justin@ridgewell.name> Co-authored-by: Huáng Jùnliàng <JLHwung@users.noreply.github.com>
- `mutableTemplateObject` and `ignoreToPrimitiveHint` (#12408) - `setClassMethods` (#12407) - `setComputedProperties` (#12490) - `ignoreFunctionLength` (#12491) - `noDocumentAll` (#12481) - `iterableIsArray` and `arrayLikeIsIterable` (#12489) - `pureGetters` (#12504) - `skipForOfIteratorClosing` (#12496) - `objectRestNoSymbols`, `setSpreadProperties` and `pureGetters` (#12505) - `noNewArrows` (#12613, #12793) - `setPublicClassFields` and `privateFieldsAsProperties` (#12497) - `constantReexports` and `enumerableModuleMeta` (#12618) - `constantSuper`, `superIsCallableConstructor` and `noClassCalls` (#12726) Co-authored-by: Justin Ridgewell <justin@ridgewell.name> Co-authored-by: Huáng Jùnliàng <JLHwung@users.noreply.github.com>
Main PR: #12219
RFC: babel/rfcs#5
Picking the correct defaults was hard in this PR, so please check if what I did makes sense.