@babel/plugin-transform-for-of
Advanced tools
Comparing version 7.12.13 to 7.13.0
@@ -17,22 +17,33 @@ "use strict"; | ||
var _default = (0, _helperPluginUtils.declare)((api, options) => { | ||
var _options$assumeArray, _options$allowArrayLi, _api$assumption; | ||
api.assertVersion(7); | ||
const { | ||
loose, | ||
assumeArray, | ||
allowArrayLike | ||
} = options; | ||
{ | ||
const { | ||
assumeArray, | ||
allowArrayLike, | ||
loose | ||
} = options; | ||
if (loose === true && assumeArray === true) { | ||
throw new Error(`The loose and assumeArray options cannot be used together in @babel/plugin-transform-for-of`); | ||
} | ||
if (loose === true && assumeArray === true) { | ||
throw new Error(`The loose and assumeArray options cannot be used together in @babel/plugin-transform-for-of`); | ||
} | ||
if (assumeArray === true && allowArrayLike === true) { | ||
throw new Error(`The assumeArray and allowArrayLike options cannot be used together in @babel/plugin-transform-for-of`); | ||
if (assumeArray === true && allowArrayLike === true) { | ||
throw new Error(`The assumeArray and allowArrayLike options cannot be used together in @babel/plugin-transform-for-of`); | ||
} | ||
if (allowArrayLike && /^7\.\d\./.test(api.version)) { | ||
throw new Error(`The allowArrayLike is only supported when using @babel/core@^7.10.0`); | ||
} | ||
} | ||
const iterableIsArray = (_options$assumeArray = options.assumeArray) != null ? _options$assumeArray : !options.loose && api.assumption("iterableIsArray"); | ||
const arrayLikeIsIterable = (_options$allowArrayLi = options.allowArrayLike) != null ? _options$allowArrayLi : api.assumption("arrayLikeIsIterable"); | ||
const skipteratorClosing = (_api$assumption = api.assumption("skipForOfIteratorClosing")) != null ? _api$assumption : options.loose; | ||
if (allowArrayLike && /^7\.\d\./.test(api.version)) { | ||
throw new Error(`The allowArrayLike is only supported when using @babel/core@^7.10.0`); | ||
if (iterableIsArray && arrayLikeIsIterable) { | ||
throw new Error(`The "iterableIsArray" and "arrayLikeIsIterable" assumptions are not compatible.`); | ||
} | ||
if (assumeArray) { | ||
if (iterableIsArray) { | ||
return { | ||
@@ -93,13 +104,11 @@ name: "transform-for-of", | ||
const buildForOfArray = (0, _core.template)(` | ||
const buildForOfArray = (0, _core.template)` | ||
for (var KEY = 0, NAME = ARR; KEY < NAME.length; KEY++) BODY; | ||
`); | ||
const buildForOfLoose = _core.template.statements(` | ||
for (var ITERATOR_HELPER = CREATE_ITERATOR_HELPER(OBJECT, ALLOW_ARRAY_LIKE), STEP_KEY; | ||
`; | ||
const buildForOfNoIteratorClosing = _core.template.statements` | ||
for (var ITERATOR_HELPER = CREATE_ITERATOR_HELPER(OBJECT, ARRAY_LIKE_IS_ITERABLE), STEP_KEY; | ||
!(STEP_KEY = ITERATOR_HELPER()).done;) BODY; | ||
`); | ||
const buildForOf = _core.template.statements(` | ||
var ITERATOR_HELPER = CREATE_ITERATOR_HELPER(OBJECT, ALLOW_ARRAY_LIKE), STEP_KEY; | ||
`; | ||
const buildForOf = _core.template.statements` | ||
var ITERATOR_HELPER = CREATE_ITERATOR_HELPER(OBJECT, ARRAY_LIKE_IS_ITERABLE), STEP_KEY; | ||
try { | ||
@@ -112,6 +121,5 @@ for (ITERATOR_HELPER.s(); !(STEP_KEY = ITERATOR_HELPER.n()).done;) BODY; | ||
} | ||
`); | ||
const builder = loose ? { | ||
build: buildForOfLoose, | ||
`; | ||
const builder = skipteratorClosing ? { | ||
build: buildForOfNoIteratorClosing, | ||
helper: "createForOfIteratorHelperLoose", | ||
@@ -169,3 +177,3 @@ getContainer: nodes => nodes | ||
if (!state.availableHelper(builder.helper)) { | ||
(0, _noHelperImplementation.default)(loose, path, state); | ||
(0, _noHelperImplementation.default)(skipteratorClosing, path, state); | ||
return; | ||
@@ -196,3 +204,3 @@ } | ||
ITERATOR_HELPER: scope.generateUidIdentifier("iterator"), | ||
ALLOW_ARRAY_LIKE: allowArrayLike ? _core.types.booleanLiteral(true) : null, | ||
ARRAY_LIKE_IS_ITERABLE: arrayLikeIsIterable ? _core.types.booleanLiteral(true) : null, | ||
STEP_KEY: _core.types.identifier(stepKey), | ||
@@ -199,0 +207,0 @@ OBJECT: node.right, |
{ | ||
"name": "@babel/plugin-transform-for-of", | ||
"version": "7.12.13", | ||
"version": "7.13.0", | ||
"description": "Compile ES2015 for...of to ES5", | ||
@@ -20,3 +20,3 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "^7.12.13" | ||
"@babel/helper-plugin-utils": "^7.13.0" | ||
}, | ||
@@ -27,5 +27,5 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "7.12.13", | ||
"@babel/core": "7.13.0", | ||
"@babel/helper-plugin-test-runner": "7.12.13" | ||
} | ||
} |
14755
331