@babel/plugin-transform-block-scoping
Advanced tools
Comparing version 7.10.4 to 7.10.5
@@ -12,10 +12,4 @@ "use strict"; | ||
var _values = _interopRequireDefault(require("lodash/values")); | ||
var _extend = _interopRequireDefault(require("lodash/extend")); | ||
var _core = require("@babel/core"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const DONE = new WeakSet(); | ||
@@ -56,3 +50,3 @@ | ||
const assign = _core.types.assignmentExpression("=", decl.id, decl.init || scope.buildUndefinedNode()); | ||
const assign = _core.types.assignmentExpression("=", _core.types.cloneNode(decl.id), decl.init || scope.buildUndefinedNode()); | ||
@@ -185,3 +179,3 @@ assign._ignoreBlockScopingTDZ = true; | ||
ReferencedIdentifier(path, state) { | ||
const ref = state.letReferences[path.node.name]; | ||
const ref = state.letReferences.get(path.node.name); | ||
if (!ref) return; | ||
@@ -237,3 +231,3 @@ const localBinding = path.scope.getBindingIdentifier(path.node.name); | ||
for (const name of Object.keys(path.getBindingIdentifiers())) { | ||
if (state.outsideReferences[name] !== path.scope.getBindingIdentifier(name)) { | ||
if (state.outsideReferences.get(name) !== path.scope.getBindingIdentifier(name)) { | ||
continue; | ||
@@ -330,5 +324,5 @@ } | ||
this.block = blockPath.node; | ||
this.outsideLetReferences = Object.create(null); | ||
this.outsideLetReferences = new Map(); | ||
this.hasLetReferences = false; | ||
this.letReferences = Object.create(null); | ||
this.letReferences = new Map(); | ||
this.body = []; | ||
@@ -401,4 +395,4 @@ | ||
for (const key of Object.keys(letRefs)) { | ||
const ref = letRefs[key]; | ||
for (const key of letRefs.keys()) { | ||
const ref = letRefs.get(key); | ||
const binding = blockScope.getBinding(ref.name); | ||
@@ -427,4 +421,4 @@ if (!binding) continue; | ||
for (const key of Object.keys(letRefs)) { | ||
const ref = letRefs[key]; | ||
for (const key of letRefs.keys()) { | ||
const ref = letRefs.get(key); | ||
@@ -442,4 +436,4 @@ if (scope.parentHasBinding(key) || scope.hasGlobal(key)) { | ||
for (const key of Object.keys(outsideLetRefs)) { | ||
const ref = letRefs[key]; | ||
for (const key of outsideLetRefs.keys()) { | ||
const ref = letRefs.get(key); | ||
@@ -461,11 +455,11 @@ if (isInLoop(this.blockPath) && blockPathScope.hasOwnBinding(key)) { | ||
if (this.loop) { | ||
for (const name of Object.keys(outsideRefs)) { | ||
const id = outsideRefs[name]; | ||
for (const name of [...outsideRefs.keys()]) { | ||
const id = outsideRefs.get(name); | ||
if (this.scope.hasGlobal(id.name) || this.scope.parentHasBinding(id.name)) { | ||
delete outsideRefs[id.name]; | ||
delete this.letReferences[id.name]; | ||
outsideRefs.delete(id.name); | ||
this.letReferences.delete(id.name); | ||
this.scope.rename(id.name); | ||
this.letReferences[id.name] = id; | ||
outsideRefs[id.name] = id; | ||
this.letReferences.set(id.name, id); | ||
outsideRefs.set(id.name, id); | ||
} | ||
@@ -477,3 +471,3 @@ } | ||
this.hoistVarDeclarations(); | ||
const args = (0, _values.default)(outsideRefs).map(id => _core.types.cloneNode(id)); | ||
const args = Array.from(outsideRefs.values(), node => _core.types.cloneNode(node)); | ||
const params = args.map(id => _core.types.cloneNode(id)); | ||
@@ -583,3 +577,8 @@ const isSwitch = this.blockPath.isSwitchStatement(); | ||
declarators.push(init); | ||
(0, _extend.default)(this.outsideLetReferences, _core.types.getBindingIdentifiers(init)); | ||
const names = _core.types.getBindingIdentifiers(init); | ||
for (const name of Object.keys(names)) { | ||
this.outsideLetReferences.set(name, names[name]); | ||
} | ||
} | ||
@@ -630,3 +629,6 @@ } | ||
(0, _extend.default)(this.letReferences, keys); | ||
for (const key of Object.keys(keys)) { | ||
this.letReferences.set(key, keys[key]); | ||
} | ||
this.hasLetReferences = true; | ||
@@ -698,45 +700,14 @@ } | ||
const body = this.body; | ||
let retCheck; | ||
const has = this.has; | ||
const cases = []; | ||
if (has.hasReturn) { | ||
retCheck = buildRetCheck({ | ||
RETURN: _core.types.identifier(ret) | ||
}); | ||
} | ||
if (has.hasBreakContinue) { | ||
for (const key of Object.keys(has.map)) { | ||
cases.push(_core.types.switchCase(_core.types.stringLiteral(key), [has.map[key]])); | ||
body.push(_core.types.ifStatement(_core.types.binaryExpression("===", _core.types.identifier(ret), _core.types.stringLiteral(key)), has.map[key])); | ||
} | ||
} | ||
if (has.hasReturn) { | ||
cases.push(_core.types.switchCase(null, [retCheck])); | ||
} | ||
if (cases.length === 1) { | ||
const single = cases[0]; | ||
body.push(_core.types.ifStatement(_core.types.binaryExpression("===", _core.types.identifier(ret), single.test), single.consequent[0])); | ||
} else { | ||
if (this.loop) { | ||
for (let i = 0; i < cases.length; i++) { | ||
const caseConsequent = cases[i].consequent[0]; | ||
if (_core.types.isBreakStatement(caseConsequent) && !caseConsequent.label) { | ||
if (!this.loopLabel) { | ||
this.loopLabel = this.scope.generateUidIdentifier("loop"); | ||
} | ||
caseConsequent.label = _core.types.cloneNode(this.loopLabel); | ||
} | ||
} | ||
} | ||
body.push(_core.types.switchStatement(_core.types.identifier(ret), cases)); | ||
} | ||
} else { | ||
if (has.hasReturn) { | ||
body.push(retCheck); | ||
} | ||
if (has.hasReturn) { | ||
body.push(buildRetCheck({ | ||
RETURN: _core.types.identifier(ret) | ||
})); | ||
} | ||
@@ -743,0 +714,0 @@ } |
@@ -27,3 +27,3 @@ "use strict"; | ||
function isReference(node, scope, state) { | ||
const declared = state.letReferences[node.name]; | ||
const declared = state.letReferences.get(node.name); | ||
if (!declared) return false; | ||
@@ -30,0 +30,0 @@ return scope.getBindingIdentifier(node.name) === declared; |
{ | ||
"name": "@babel/plugin-transform-block-scoping", | ||
"version": "7.10.4", | ||
"version": "7.10.5", | ||
"description": "Compile ES2015 block scoping (const and let) to ES5", | ||
@@ -16,4 +16,3 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "^7.10.4", | ||
"lodash": "^4.17.13" | ||
"@babel/helper-plugin-utils": "^7.10.4" | ||
}, | ||
@@ -27,6 +26,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.10.4", | ||
"@babel/core": "^7.10.5", | ||
"@babel/helper-plugin-test-runner": "^7.10.4" | ||
}, | ||
"gitHead": "7fd40d86a0d03ff0e9c3ea16b29689945433d4df" | ||
"gitHead": "f7964a9ac51356f7df6404a25b27ba1cffba1ba7" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2
0
24596
642
- Removedlodash@^4.17.13
- Removedlodash@4.17.21(transitive)