@babel/plugin-transform-block-scoping
Advanced tools
Comparing version 7.18.4 to 7.18.6
@@ -103,3 +103,3 @@ "use strict"; | ||
const buildRetCheck = (0, _core.template)(` | ||
const buildRetCheck = _core.template.statement(` | ||
if (typeof RETURN === "object") return RETURN.v; | ||
@@ -110,3 +110,7 @@ `); | ||
if (!_core.types.isVariableDeclaration(node)) return false; | ||
if (node[_core.types.BLOCK_SCOPED_SYMBOL]) return true; | ||
if (node[_core.types.BLOCK_SCOPED_SYMBOL]) { | ||
return true; | ||
} | ||
if (node.kind !== "let" && node.kind !== "const") return false; | ||
@@ -301,3 +305,3 @@ return true; | ||
state.hasBreakContinue = true; | ||
state.map[loopText] = node; | ||
state.map.set(loopText, node); | ||
replace = _core.types.stringLiteral(loopText); | ||
@@ -521,3 +525,3 @@ } | ||
const params = args.map(id => _core.types.cloneNode(id)); | ||
const isSwitch = this.blockPath.isSwitchStatement(); | ||
const isSwitch = block.type === "SwitchStatement"; | ||
@@ -635,4 +639,2 @@ const fn = _core.types.functionExpression(null, params, _core.types.blockStatement(isSwitch ? [block] : block.body)); | ||
const addDeclarationsFromChild = (path, node) => { | ||
node = node || path.node; | ||
if (_core.types.isClassDeclaration(node) || _core.types.isFunctionDeclaration(node) || isBlockScoped(node)) { | ||
@@ -643,3 +645,3 @@ if (isBlockScoped(node)) { | ||
if (node.declarations) { | ||
if (node.type === "VariableDeclaration") { | ||
for (let i = 0; i < node.declarations.length; i++) { | ||
@@ -658,11 +660,3 @@ declarators.push(node.declarations[i]); | ||
if (block.body) { | ||
const declarPaths = this.blockPath.get("body"); | ||
for (let i = 0; i < block.body.length; i++) { | ||
addDeclarationsFromChild(declarPaths[i]); | ||
} | ||
} | ||
if (block.cases) { | ||
if (block.type === "SwitchStatement") { | ||
const declarPaths = this.blockPath.get("cases"); | ||
@@ -678,2 +672,8 @@ | ||
} | ||
} else { | ||
const declarPaths = this.blockPath.get("body"); | ||
for (let i = 0; i < block.body.length; i++) { | ||
addDeclarationsFromChild(declarPaths[i], declarPaths[i].node); | ||
} | ||
} | ||
@@ -718,3 +718,3 @@ | ||
isLoop: !!this.loop, | ||
map: {}, | ||
map: new Map(), | ||
loopIgnored: new WeakSet() | ||
@@ -760,4 +760,4 @@ }; | ||
if (has.hasBreakContinue) { | ||
for (const key of Object.keys(has.map)) { | ||
body.push(_core.types.ifStatement(_core.types.binaryExpression("===", _core.types.identifier(ret), _core.types.stringLiteral(key)), has.map[key])); | ||
for (const key of has.map.keys()) { | ||
body.push(_core.types.ifStatement(_core.types.binaryExpression("===", _core.types.identifier(ret), _core.types.stringLiteral(key)), has.map.get(key))); | ||
} | ||
@@ -764,0 +764,0 @@ } |
{ | ||
"name": "@babel/plugin-transform-block-scoping", | ||
"version": "7.18.4", | ||
"version": "7.18.6", | ||
"description": "Compile ES2015 block scoping (const and let) to ES5", | ||
@@ -17,3 +17,3 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "^7.17.12" | ||
"@babel/helper-plugin-utils": "^7.18.6" | ||
}, | ||
@@ -27,5 +27,5 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.18.2", | ||
"@babel/helper-plugin-test-runner": "^7.16.7", | ||
"@babel/traverse": "^7.18.2" | ||
"@babel/core": "^7.18.6", | ||
"@babel/helper-plugin-test-runner": "^7.18.6", | ||
"@babel/traverse": "^7.18.6" | ||
}, | ||
@@ -35,3 +35,4 @@ "engines": { | ||
}, | ||
"author": "The Babel Team (https://babel.dev/team)" | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
"type": "commonjs" | ||
} |
27239