@babel/plugin-transform-block-scoping
Advanced tools
Comparing version 7.20.11 to 7.20.14
@@ -9,3 +9,2 @@ "use strict"; | ||
var _core = require("@babel/core"); | ||
const annexB33FunctionsVisitor = { | ||
@@ -20,3 +19,2 @@ VariableDeclaration(path) { | ||
}, | ||
BlockStatement(path) { | ||
@@ -23,0 +21,0 @@ if (isStrict(path)) return; |
@@ -26,4 +26,3 @@ "use strict"; | ||
name: "transform-block-scoping", | ||
visitor: _core.traverse.visitors.merge([ | ||
_annexB_3_.annexB33FunctionsVisitor, { | ||
visitor: _core.traverse.visitors.merge([_annexB_3_.annexB33FunctionsVisitor, { | ||
Loop(path, state) { | ||
@@ -59,3 +58,2 @@ const isForStatement = path.isForStatement(); | ||
if ((_bodyScope = bodyScope) != null && _bodyScope.hasOwnBinding(name)) continue; | ||
let binding = headScope.getOwnBinding(name); | ||
@@ -74,5 +72,5 @@ if (!binding) { | ||
captured.push(name); | ||
} else if (headScope.parent.hasBinding(name)) { | ||
} else if (headScope.parent.hasBinding(name) || headScope.parent.hasGlobal(name)) { | ||
const newName = headScope.generateUid(name); | ||
headPath.scope.rename(name, newName); | ||
headScope.rename(name, newName); | ||
name = newName; | ||
@@ -146,15 +144,9 @@ } | ||
const blockScope = path.scope; | ||
let varScope = blockScope.getFunctionParent(); | ||
let isProgramScope = false; | ||
if (!varScope) { | ||
varScope = blockScope.getProgramParent(); | ||
isProgramScope = true; | ||
} | ||
const varScope = blockScope.getFunctionParent() || blockScope.getProgramParent(); | ||
if (varScope !== blockScope) { | ||
for (const name of bindingNames) { | ||
let newName = name; | ||
if ( | ||
blockScope.parent.hasBinding(name, { | ||
if (blockScope.parent.hasBinding(name, { | ||
noUids: true | ||
}) || blockScope.parent.hasGlobal(name) || isProgramScope && varScope.hasGlobal(name)) { | ||
}) || blockScope.parent.hasGlobal(name)) { | ||
newName = blockScope.generateUid(name); | ||
@@ -187,4 +179,3 @@ blockScope.rename(name, newName); | ||
if (!_core.types.isVariableDeclaration(node)) return false; | ||
if ( | ||
node[_core.types.BLOCK_SCOPED_SYMBOL]) { | ||
if (node[_core.types.BLOCK_SCOPED_SYMBOL]) { | ||
return true; | ||
@@ -191,0 +182,0 @@ } |
@@ -182,3 +182,2 @@ "use strict"; | ||
if (updaterNode) fn.body.body.push(updaterNode); | ||
const [varPath] = loopPath.insertBefore(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(_core.types.identifier(id), fn)])); | ||
@@ -185,0 +184,0 @@ const bodyStmts = []; |
@@ -37,7 +37,5 @@ "use strict"; | ||
} else if (["&&=", "||=", "??="].includes(operator)) { | ||
violation.replaceWith(_core.types.logicalExpression( | ||
operator.slice(0, -1), left, _core.types.sequenceExpression([right, throwNode]))); | ||
violation.replaceWith(_core.types.logicalExpression(operator.slice(0, -1), left, _core.types.sequenceExpression([right, throwNode]))); | ||
} else { | ||
violation.replaceWith(_core.types.sequenceExpression([_core.types.binaryExpression( | ||
operator.slice(0, -1), left, right), throwNode])); | ||
violation.replaceWith(_core.types.sequenceExpression([_core.types.binaryExpression(operator.slice(0, -1), left, right), throwNode])); | ||
} | ||
@@ -68,4 +66,3 @@ } else if (violation.isUpdateExpression()) { | ||
skipTDZChecks.add(clone); | ||
return _core.types.callExpression(state.addHelper("temporalRef"), [ | ||
clone, _core.types.stringLiteral(node.name)]); | ||
return _core.types.callExpression(state.addHelper("temporalRef"), [clone, _core.types.stringLiteral(node.name)]); | ||
} else { | ||
@@ -72,0 +69,0 @@ return _core.types.callExpression(state.addHelper("tdz"), [_core.types.stringLiteral(node.name)]); |
{ | ||
"name": "@babel/plugin-transform-block-scoping", | ||
"version": "7.20.11", | ||
"version": "7.20.14", | ||
"description": "Compile ES2015 block scoping (const and let) to ES5", | ||
@@ -26,5 +26,5 @@ "repository": { | ||
"devDependencies": { | ||
"@babel/core": "^7.20.7", | ||
"@babel/core": "^7.20.12", | ||
"@babel/helper-plugin-test-runner": "^7.18.6", | ||
"@babel/traverse": "^7.20.10" | ||
"@babel/traverse": "^7.20.13" | ||
}, | ||
@@ -31,0 +31,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
83605
676