@babel/plugin-transform-block-scoping
Advanced tools
+73
-103
@@ -8,44 +8,12 @@ "use strict"; | ||
| function _helperPluginUtils() { | ||
| const data = require("@babel/helper-plugin-utils"); | ||
| var _helperPluginUtils = require("@babel/helper-plugin-utils"); | ||
| _helperPluginUtils = function () { | ||
| return data; | ||
| }; | ||
| return data; | ||
| } | ||
| var _tdz = require("./tdz"); | ||
| function _values() { | ||
| const data = _interopRequireDefault(require("lodash/values")); | ||
| var _values = _interopRequireDefault(require("lodash/values")); | ||
| _values = function () { | ||
| return data; | ||
| }; | ||
| var _extend = _interopRequireDefault(require("lodash/extend")); | ||
| return data; | ||
| } | ||
| var _core = require("@babel/core"); | ||
| function _extend() { | ||
| const data = _interopRequireDefault(require("lodash/extend")); | ||
| _extend = function () { | ||
| return data; | ||
| }; | ||
| return data; | ||
| } | ||
| function _core() { | ||
| const data = require("@babel/core"); | ||
| _core = function () { | ||
| return data; | ||
| }; | ||
| return data; | ||
| } | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -55,3 +23,3 @@ | ||
| var _default = (0, _helperPluginUtils().declare)((api, opts) => { | ||
| var _default = (0, _helperPluginUtils.declare)((api, opts) => { | ||
| api.assertVersion(7); | ||
@@ -89,6 +57,6 @@ const { | ||
| const assign = _core().types.assignmentExpression("=", decl.id, decl.init || scope.buildUndefinedNode()); | ||
| const assign = _core.types.assignmentExpression("=", decl.id, decl.init || scope.buildUndefinedNode()); | ||
| assign._ignoreBlockScopingTDZ = true; | ||
| nodes.push(_core().types.expressionStatement(assign)); | ||
| nodes.push(_core.types.expressionStatement(assign)); | ||
| decl.init = this.addHelper("temporalUndefined"); | ||
@@ -100,3 +68,3 @@ } | ||
| if (path.isCompletionRecord()) { | ||
| nodes.push(_core().types.expressionStatement(scope.buildUndefinedNode())); | ||
| nodes.push(_core.types.expressionStatement(scope.buildUndefinedNode())); | ||
| } | ||
@@ -142,6 +110,6 @@ | ||
| function ignoreBlock(path) { | ||
| return _core().types.isLoop(path.parent) || _core().types.isCatchClause(path.parent); | ||
| return _core.types.isLoop(path.parent) || _core.types.isCatchClause(path.parent); | ||
| } | ||
| const buildRetCheck = (0, _core().template)(` | ||
| const buildRetCheck = (0, _core.template)(` | ||
| if (typeof RETURN === "object") return RETURN.v; | ||
@@ -151,4 +119,4 @@ `); | ||
| function isBlockScoped(node) { | ||
| if (!_core().types.isVariableDeclaration(node)) return false; | ||
| if (node[_core().types.BLOCK_SCOPED_SYMBOL]) return true; | ||
| if (!_core.types.isVariableDeclaration(node)) return false; | ||
| if (node[_core.types.BLOCK_SCOPED_SYMBOL]) return true; | ||
| if (node.kind !== "let" && node.kind !== "const") return false; | ||
@@ -168,3 +136,3 @@ return true; | ||
| if (isInLoop(path) && !_core().types.isFor(parent)) { | ||
| if (isInLoop(path) && !_core.types.isFor(parent)) { | ||
| for (let i = 0; i < node.declarations.length; i++) { | ||
@@ -176,3 +144,3 @@ const declar = node.declarations[i]; | ||
| node[_core().types.BLOCK_SCOPED_SYMBOL] = true; | ||
| node[_core.types.BLOCK_SCOPED_SYMBOL] = true; | ||
| node.kind = "var"; | ||
@@ -192,3 +160,3 @@ | ||
| function isVar(node) { | ||
| return _core().types.isVariableDeclaration(node, { | ||
| return _core.types.isVariableDeclaration(node, { | ||
| kind: "var" | ||
@@ -198,3 +166,3 @@ }) && !isBlockScoped(node); | ||
| const letReferenceBlockVisitor = _core().traverse.visitors.merge([{ | ||
| const letReferenceBlockVisitor = _core.traverse.visitors.merge([{ | ||
| Loop: { | ||
@@ -223,3 +191,3 @@ enter(path, state) { | ||
| const letReferenceFunctionVisitor = _core().traverse.visitors.merge([{ | ||
| const letReferenceFunctionVisitor = _core.traverse.visitors.merge([{ | ||
| ReferencedIdentifier(path, state) { | ||
@@ -249,3 +217,3 @@ const ref = state.letReferences[path.node.name]; | ||
| } else { | ||
| node.init = _core().types.sequenceExpression(nodes); | ||
| node.init = _core.types.sequenceExpression(nodes); | ||
| } | ||
@@ -259,3 +227,3 @@ } | ||
| } else if (isVar(node, parent)) { | ||
| path.replaceWithMultiple(self.pushDeclar(node).map(expr => _core().types.expressionStatement(expr))); | ||
| path.replaceWithMultiple(self.pushDeclar(node).map(expr => _core.types.expressionStatement(expr))); | ||
| } else if (path.isFunction()) { | ||
@@ -293,5 +261,5 @@ return path.skip(); | ||
| function loopNodeTo(node) { | ||
| if (_core().types.isBreakStatement(node)) { | ||
| if (_core.types.isBreakStatement(node)) { | ||
| return "break"; | ||
| } else if (_core().types.isContinueStatement(node)) { | ||
| } else if (_core.types.isContinueStatement(node)) { | ||
| return "continue"; | ||
@@ -340,3 +308,3 @@ } | ||
| if (state.ignoreLabeless) return; | ||
| if (_core().types.isBreakStatement(node) && state.inSwitchCase) return; | ||
| if (_core.types.isBreakStatement(node) && state.inSwitchCase) return; | ||
| } | ||
@@ -346,3 +314,3 @@ | ||
| state.map[loopText] = node; | ||
| replace = _core().types.stringLiteral(loopText); | ||
| replace = _core.types.stringLiteral(loopText); | ||
| } | ||
@@ -352,10 +320,10 @@ | ||
| state.hasReturn = true; | ||
| replace = _core().types.objectExpression([_core().types.objectProperty(_core().types.identifier("v"), node.argument || scope.buildUndefinedNode())]); | ||
| replace = _core.types.objectExpression([_core.types.objectProperty(_core.types.identifier("v"), node.argument || scope.buildUndefinedNode())]); | ||
| } | ||
| if (replace) { | ||
| replace = _core().types.returnStatement(replace); | ||
| replace = _core.types.returnStatement(replace); | ||
| replace[this.LOOP_IGNORE] = true; | ||
| path.skip(); | ||
| path.replaceWith(_core().types.inherits(replace, node)); | ||
| path.replaceWith(_core.types.inherits(replace, node)); | ||
| } | ||
@@ -382,3 +350,3 @@ } | ||
| this.loopParent = loopPath.parent; | ||
| this.loopLabel = _core().types.isLabeledStatement(this.loopParent) && this.loopParent.label; | ||
| this.loopLabel = _core.types.isLabeledStatement(this.loopParent) && this.loopParent.label; | ||
| this.loopPath = loopPath; | ||
@@ -396,3 +364,3 @@ this.loop = loopPath.node; | ||
| if (_core().types.isFunction(this.parent) || _core().types.isProgram(this.block)) { | ||
| if (_core.types.isFunction(this.parent) || _core.types.isProgram(this.block)) { | ||
| this.updateScopeInfo(); | ||
@@ -412,4 +380,4 @@ return; | ||
| if (this.loopLabel && !_core().types.isLabeledStatement(this.loopParent)) { | ||
| return _core().types.labeledStatement(this.loopLabel, this.loop); | ||
| if (this.loopLabel && !_core.types.isLabeledStatement(this.loopParent)) { | ||
| return _core.types.labeledStatement(this.loopLabel, this.loop); | ||
| } | ||
@@ -429,11 +397,11 @@ } | ||
| const throwNode = _core().types.callExpression(readOnlyError, [_core().types.stringLiteral(name)]); | ||
| const throwNode = _core.types.callExpression(readOnlyError, [_core.types.stringLiteral(name)]); | ||
| if (violation.isAssignmentExpression()) { | ||
| violation.get("right").replaceWith(_core().types.sequenceExpression([throwNode, violation.get("right").node])); | ||
| violation.get("right").replaceWith(_core.types.sequenceExpression([throwNode, violation.get("right").node])); | ||
| } else if (violation.isUpdateExpression()) { | ||
| violation.replaceWith(_core().types.sequenceExpression([throwNode, violation.node])); | ||
| violation.replaceWith(_core.types.sequenceExpression([throwNode, violation.node])); | ||
| } else if (violation.isForXStatement()) { | ||
| violation.ensureBlock(); | ||
| violation.node.body.body.unshift(_core().types.expressionStatement(throwNode)); | ||
| violation.node.body.body.unshift(_core.types.expressionStatement(throwNode)); | ||
| } | ||
@@ -445,4 +413,4 @@ } | ||
| updateScopeInfo(wrappedInClosure) { | ||
| const scope = this.scope; | ||
| const parentScope = scope.getFunctionParent() || scope.getProgramParent(); | ||
| const blockScope = this.blockPath.scope; | ||
| const parentScope = blockScope.getFunctionParent() || blockScope.getProgramParent(); | ||
| const letRefs = this.letReferences; | ||
@@ -452,3 +420,3 @@ | ||
| const ref = letRefs[key]; | ||
| const binding = scope.getBinding(ref.name); | ||
| const binding = blockScope.getBinding(ref.name); | ||
| if (!binding) continue; | ||
@@ -460,5 +428,7 @@ | ||
| if (wrappedInClosure) { | ||
| scope.removeBinding(ref.name); | ||
| if (blockScope.hasOwnBinding(ref.name)) { | ||
| blockScope.removeBinding(ref.name); | ||
| } | ||
| } else { | ||
| scope.moveBindingTo(ref.name, parentScope); | ||
| blockScope.moveBindingTo(ref.name, parentScope); | ||
| } | ||
@@ -522,27 +492,27 @@ } | ||
| this.hoistVarDeclarations(); | ||
| const args = (0, _values().default)(outsideRefs).map(id => _core().types.cloneNode(id)); | ||
| const params = args.map(id => _core().types.cloneNode(id)); | ||
| const args = (0, _values.default)(outsideRefs).map(id => _core.types.cloneNode(id)); | ||
| const params = args.map(id => _core.types.cloneNode(id)); | ||
| const isSwitch = this.blockPath.isSwitchStatement(); | ||
| const fn = _core().types.functionExpression(null, params, _core().types.blockStatement(isSwitch ? [block] : block.body)); | ||
| const fn = _core.types.functionExpression(null, params, _core.types.blockStatement(isSwitch ? [block] : block.body)); | ||
| this.addContinuations(fn); | ||
| let call = _core().types.callExpression(_core().types.nullLiteral(), args); | ||
| let call = _core.types.callExpression(_core.types.nullLiteral(), args); | ||
| let basePath = ".callee"; | ||
| const hasYield = _core().traverse.hasType(fn.body, "YieldExpression", _core().types.FUNCTION_TYPES); | ||
| const hasYield = _core.traverse.hasType(fn.body, "YieldExpression", _core.types.FUNCTION_TYPES); | ||
| if (hasYield) { | ||
| fn.generator = true; | ||
| call = _core().types.yieldExpression(call, true); | ||
| call = _core.types.yieldExpression(call, true); | ||
| basePath = ".argument" + basePath; | ||
| } | ||
| const hasAsync = _core().traverse.hasType(fn.body, "AwaitExpression", _core().types.FUNCTION_TYPES); | ||
| const hasAsync = _core.traverse.hasType(fn.body, "AwaitExpression", _core.types.FUNCTION_TYPES); | ||
| if (hasAsync) { | ||
| fn.async = true; | ||
| call = _core().types.awaitExpression(call); | ||
| call = _core.types.awaitExpression(call); | ||
| basePath = ".argument" + basePath; | ||
@@ -556,3 +526,3 @@ } | ||
| const ret = this.scope.generateUid("ret"); | ||
| this.body.push(_core().types.variableDeclaration("var", [_core().types.variableDeclarator(_core().types.identifier(ret), call)])); | ||
| this.body.push(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(_core.types.identifier(ret), call)])); | ||
| placeholderPath = "declarations.0.init" + basePath; | ||
@@ -562,3 +532,3 @@ index = this.body.length - 1; | ||
| } else { | ||
| this.body.push(_core().types.expressionStatement(call)); | ||
| this.body.push(_core.types.expressionStatement(call)); | ||
| placeholderPath = "expression" + basePath; | ||
@@ -588,4 +558,4 @@ index = this.body.length - 1; | ||
| const loopId = this.scope.generateUid("loop"); | ||
| const p = this.loopPath.insertBefore(_core().types.variableDeclaration("var", [_core().types.variableDeclarator(_core().types.identifier(loopId), fn)])); | ||
| placeholder.replaceWith(_core().types.identifier(loopId)); | ||
| const p = this.loopPath.insertBefore(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(_core.types.identifier(loopId), fn)])); | ||
| placeholder.replaceWith(_core.types.identifier(loopId)); | ||
| fnPath = p[0].get("declarations.0.init"); | ||
@@ -613,8 +583,8 @@ } else { | ||
| const newParamName = this.scope.generateUid(param.name); | ||
| fn.params[i] = _core().types.identifier(newParamName); | ||
| fn.params[i] = _core.types.identifier(newParamName); | ||
| this.scope.rename(paramName, newParamName, fn); | ||
| state.returnStatements.forEach(returnStatement => { | ||
| returnStatement.insertBefore(_core().types.expressionStatement(_core().types.assignmentExpression("=", _core().types.identifier(paramName), _core().types.identifier(newParamName)))); | ||
| returnStatement.insertBefore(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.identifier(paramName), _core.types.identifier(newParamName)))); | ||
| }); | ||
| fn.body.body.push(_core().types.expressionStatement(_core().types.assignmentExpression("=", _core().types.identifier(paramName), _core().types.identifier(newParamName)))); | ||
| fn.body.body.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.identifier(paramName), _core.types.identifier(newParamName)))); | ||
| } | ||
@@ -632,3 +602,3 @@ } | ||
| declarators.push(init); | ||
| (0, _extend().default)(this.outsideLetReferences, _core().types.getBindingIdentifiers(init)); | ||
| (0, _extend.default)(this.outsideLetReferences, _core.types.getBindingIdentifiers(init)); | ||
| } | ||
@@ -640,3 +610,3 @@ } | ||
| if (_core().types.isClassDeclaration(node) || _core().types.isFunctionDeclaration(node) || isBlockScoped(node)) { | ||
| if (_core.types.isClassDeclaration(node) || _core.types.isFunctionDeclaration(node) || isBlockScoped(node)) { | ||
| if (isBlockScoped(node)) { | ||
@@ -649,3 +619,3 @@ convertBlockScopedToVar(path, node, block, this.scope); | ||
| if (_core().types.isLabeledStatement(node)) { | ||
| if (_core.types.isLabeledStatement(node)) { | ||
| addDeclarationsFromChild(path.get("body"), node.body); | ||
@@ -679,5 +649,5 @@ } | ||
| const keys = _core().types.getBindingIdentifiers(declar, false, true); | ||
| const keys = _core.types.getBindingIdentifiers(declar, false, true); | ||
| (0, _extend().default)(this.letReferences, keys); | ||
| (0, _extend.default)(this.letReferences, keys); | ||
| this.hasLetReferences = true; | ||
@@ -726,9 +696,9 @@ } | ||
| const names = _core().types.getBindingIdentifiers(node); | ||
| const names = _core.types.getBindingIdentifiers(node); | ||
| for (const name of Object.keys(names)) { | ||
| declars.push(_core().types.variableDeclarator(names[name])); | ||
| declars.push(_core.types.variableDeclarator(names[name])); | ||
| } | ||
| this.body.push(_core().types.variableDeclaration(node.kind, declars)); | ||
| this.body.push(_core.types.variableDeclaration(node.kind, declars)); | ||
| const replace = []; | ||
@@ -740,5 +710,5 @@ | ||
| const expr = _core().types.assignmentExpression("=", _core().types.cloneNode(declar.id), _core().types.cloneNode(declar.init)); | ||
| const expr = _core.types.assignmentExpression("=", _core.types.cloneNode(declar.id), _core.types.cloneNode(declar.init)); | ||
| replace.push(_core().types.inherits(expr, declar)); | ||
| replace.push(_core.types.inherits(expr, declar)); | ||
| } | ||
@@ -757,3 +727,3 @@ | ||
| retCheck = buildRetCheck({ | ||
| RETURN: _core().types.identifier(ret) | ||
| RETURN: _core.types.identifier(ret) | ||
| }); | ||
@@ -764,7 +734,7 @@ } | ||
| for (const key of Object.keys(has.map)) { | ||
| cases.push(_core().types.switchCase(_core().types.stringLiteral(key), [has.map[key]])); | ||
| cases.push(_core.types.switchCase(_core.types.stringLiteral(key), [has.map[key]])); | ||
| } | ||
| if (has.hasReturn) { | ||
| cases.push(_core().types.switchCase(null, [retCheck])); | ||
| cases.push(_core.types.switchCase(null, [retCheck])); | ||
| } | ||
@@ -774,3 +744,3 @@ | ||
| const single = cases[0]; | ||
| body.push(_core().types.ifStatement(_core().types.binaryExpression("===", _core().types.identifier(ret), single.test), single.consequent[0])); | ||
| body.push(_core.types.ifStatement(_core.types.binaryExpression("===", _core.types.identifier(ret), single.test), single.consequent[0])); | ||
| } else { | ||
@@ -781,3 +751,3 @@ if (this.loop) { | ||
| if (_core().types.isBreakStatement(caseConsequent) && !caseConsequent.label) { | ||
| if (_core.types.isBreakStatement(caseConsequent) && !caseConsequent.label) { | ||
| if (!this.loopLabel) { | ||
@@ -787,3 +757,3 @@ this.loopLabel = this.scope.generateUidIdentifier("loop"); | ||
| caseConsequent.label = _core().types.cloneNode(this.loopLabel); | ||
| caseConsequent.label = _core.types.cloneNode(this.loopLabel); | ||
| } | ||
@@ -793,3 +763,3 @@ } | ||
| body.push(_core().types.switchStatement(_core().types.identifier(ret), cases)); | ||
| body.push(_core.types.switchStatement(_core.types.identifier(ret), cases)); | ||
| } | ||
@@ -796,0 +766,0 @@ } else { |
+5
-13
@@ -8,12 +8,4 @@ "use strict"; | ||
| function _core() { | ||
| const data = require("@babel/core"); | ||
| var _core = require("@babel/core"); | ||
| _core = function () { | ||
| return data; | ||
| }; | ||
| return data; | ||
| } | ||
| function getTDZStatus(refPath, bindingPath) { | ||
@@ -32,3 +24,3 @@ const executionStatus = bindingPath._guessExecutionStatusRelativeTo(refPath); | ||
| function buildTDZAssert(node, state) { | ||
| return _core().types.callExpression(state.addHelper("temporalRef"), [node, _core().types.stringLiteral(node.name)]); | ||
| return _core.types.callExpression(state.addHelper("temporalRef"), [node, _core.types.stringLiteral(node.name)]); | ||
| } | ||
@@ -66,3 +58,3 @@ | ||
| if (parent._ignoreBlockScopingTDZ) return; | ||
| path.parentPath.replaceWith(_core().types.sequenceExpression([assert, parent])); | ||
| path.parentPath.replaceWith(_core.types.sequenceExpression([assert, parent])); | ||
| } else { | ||
@@ -72,3 +64,3 @@ path.replaceWith(assert); | ||
| } else if (status === "inside") { | ||
| path.replaceWith(_core().template.ast`${state.addHelper("tdz")}("${node.name}")`); | ||
| path.replaceWith(_core.template.ast`${state.addHelper("tdz")}("${node.name}")`); | ||
| } | ||
@@ -98,3 +90,3 @@ }, | ||
| nodes.push(node); | ||
| path.replaceWithMultiple(nodes.map(n => _core().types.expressionStatement(n))); | ||
| path.replaceWithMultiple(nodes.map(n => _core.types.expressionStatement(n))); | ||
| } | ||
@@ -101,0 +93,0 @@ } |
+3
-3
| { | ||
| "name": "@babel/plugin-transform-block-scoping", | ||
| "version": "7.6.2", | ||
| "version": "7.6.3", | ||
| "description": "Compile ES2015 block scoping (const and let) to ES5", | ||
@@ -22,6 +22,6 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-block-scoping", | ||
| "devDependencies": { | ||
| "@babel/core": "^7.6.2", | ||
| "@babel/core": "^7.6.3", | ||
| "@babel/helper-plugin-test-runner": "^7.0.0" | ||
| }, | ||
| "gitHead": "b9cb4af953afb1a5aeed9b18526192ab15bb45c1" | ||
| "gitHead": "d329156ebc17da01382acb83e212cb4328534ebc" | ||
| } |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
25566
-2.05%666
-4.03%