@babel/plugin-transform-block-scoping
Advanced tools
Comparing version 7.0.0-beta.46 to 7.0.0-beta.47
418
lib/index.js
@@ -9,3 +9,3 @@ "use strict"; | ||
function _helperPluginUtils() { | ||
var data = require("@babel/helper-plugin-utils"); | ||
const data = require("@babel/helper-plugin-utils"); | ||
@@ -22,3 +22,3 @@ _helperPluginUtils = function _helperPluginUtils() { | ||
function _values() { | ||
var data = _interopRequireDefault(require("lodash/values")); | ||
const data = _interopRequireDefault(require("lodash/values")); | ||
@@ -33,3 +33,3 @@ _values = function _values() { | ||
function _extend() { | ||
var data = _interopRequireDefault(require("lodash/extend")); | ||
const data = _interopRequireDefault(require("lodash/extend")); | ||
@@ -44,3 +44,3 @@ _extend = function _extend() { | ||
function _core() { | ||
var data = require("@babel/core"); | ||
const data = require("@babel/core"); | ||
@@ -56,17 +56,17 @@ _core = function _core() { | ||
var DONE = new WeakSet(); | ||
const DONE = new WeakSet(); | ||
var _default = (0, _helperPluginUtils().declare)(function (api, opts) { | ||
var _default = (0, _helperPluginUtils().declare)((api, opts) => { | ||
api.assertVersion(7); | ||
var _opts$throwIfClosureR = opts.throwIfClosureRequired, | ||
throwIfClosureRequired = _opts$throwIfClosureR === void 0 ? false : _opts$throwIfClosureR, | ||
_opts$tdz = opts.tdz, | ||
tdzEnabled = _opts$tdz === void 0 ? false : _opts$tdz; | ||
const _opts$throwIfClosureR = opts.throwIfClosureRequired, | ||
throwIfClosureRequired = _opts$throwIfClosureR === void 0 ? false : _opts$throwIfClosureR, | ||
_opts$tdz = opts.tdz, | ||
tdzEnabled = _opts$tdz === void 0 ? false : _opts$tdz; | ||
if (typeof throwIfClosureRequired !== "boolean") { | ||
throw new Error(".throwIfClosureRequired must be a boolean, or undefined"); | ||
throw new Error(`.throwIfClosureRequired must be a boolean, or undefined`); | ||
} | ||
if (typeof tdzEnabled !== "boolean") { | ||
throw new Error(".throwIfClosureRequired must be a boolean, or undefined"); | ||
throw new Error(`.throwIfClosureRequired must be a boolean, or undefined`); | ||
} | ||
@@ -76,6 +76,6 @@ | ||
visitor: { | ||
VariableDeclaration: function VariableDeclaration(path) { | ||
var node = path.node, | ||
parent = path.parent, | ||
scope = path.scope; | ||
VariableDeclaration(path) { | ||
const node = path.node, | ||
parent = path.parent, | ||
scope = path.scope; | ||
if (!isBlockScoped(node)) return; | ||
@@ -85,9 +85,9 @@ convertBlockScopedToVar(path, null, parent, scope, true); | ||
if (node._tdzThis) { | ||
var nodes = [node]; | ||
const nodes = [node]; | ||
for (var i = 0; i < node.declarations.length; i++) { | ||
var decl = node.declarations[i]; | ||
for (let i = 0; i < node.declarations.length; i++) { | ||
const decl = node.declarations[i]; | ||
if (decl.init) { | ||
var assign = _core().types.assignmentExpression("=", decl.id, decl.init); | ||
const assign = _core().types.assignmentExpression("=", decl.id, decl.init); | ||
@@ -110,22 +110,26 @@ assign._ignoreBlockScopingTDZ = true; | ||
}, | ||
Loop: function Loop(path, state) { | ||
var parent = path.parent, | ||
scope = path.scope; | ||
Loop(path, state) { | ||
const parent = path.parent, | ||
scope = path.scope; | ||
path.ensureBlock(); | ||
var blockScoping = new BlockScoping(path, path.get("body"), parent, scope, throwIfClosureRequired, tdzEnabled, state); | ||
var replace = blockScoping.run(); | ||
const blockScoping = new BlockScoping(path, path.get("body"), parent, scope, throwIfClosureRequired, tdzEnabled, state); | ||
const replace = blockScoping.run(); | ||
if (replace) path.replaceWith(replace); | ||
}, | ||
CatchClause: function CatchClause(path, state) { | ||
var parent = path.parent, | ||
scope = path.scope; | ||
var blockScoping = new BlockScoping(null, path.get("body"), parent, scope, throwIfClosureRequired, tdzEnabled, state); | ||
CatchClause(path, state) { | ||
const parent = path.parent, | ||
scope = path.scope; | ||
const blockScoping = new BlockScoping(null, path.get("body"), parent, scope, throwIfClosureRequired, tdzEnabled, state); | ||
blockScoping.run(); | ||
}, | ||
"BlockStatement|SwitchStatement|Program": function BlockStatementSwitchStatementProgram(path, state) { | ||
"BlockStatement|SwitchStatement|Program"(path, state) { | ||
if (!ignoreBlock(path)) { | ||
var blockScoping = new BlockScoping(null, path, path.parent, path.scope, throwIfClosureRequired, tdzEnabled, state); | ||
const blockScoping = new BlockScoping(null, path, path.parent, path.scope, throwIfClosureRequired, tdzEnabled, state); | ||
blockScoping.run(); | ||
} | ||
} | ||
} | ||
@@ -141,3 +145,5 @@ }; | ||
var buildRetCheck = (0, _core().template)("\n if (typeof RETURN === \"object\") return RETURN.v;\n"); | ||
const buildRetCheck = (0, _core().template)(` | ||
if (typeof RETURN === "object") return RETURN.v; | ||
`); | ||
@@ -152,13 +158,7 @@ function isBlockScoped(node) { | ||
function isInLoop(path) { | ||
var loopOrFunctionParent = path.find(function (path) { | ||
return path.isLoop() || path.isFunction(); | ||
}); | ||
const loopOrFunctionParent = path.find(path => path.isLoop() || path.isFunction()); | ||
return loopOrFunctionParent && loopOrFunctionParent.isLoop(); | ||
} | ||
function convertBlockScopedToVar(path, node, parent, scope, moveBindingsToParent) { | ||
if (moveBindingsToParent === void 0) { | ||
moveBindingsToParent = false; | ||
} | ||
function convertBlockScopedToVar(path, node, parent, scope, moveBindingsToParent = false) { | ||
if (!node) { | ||
@@ -169,4 +169,4 @@ node = path.node; | ||
if (isInLoop(path) && !_core().types.isFor(parent)) { | ||
for (var i = 0; i < node.declarations.length; i++) { | ||
var declar = node.declarations[i]; | ||
for (let i = 0; i < node.declarations.length; i++) { | ||
const declar = node.declarations[i]; | ||
declar.init = declar.init || scope.buildUndefinedNode(); | ||
@@ -180,7 +180,7 @@ } | ||
if (moveBindingsToParent) { | ||
var parentScope = scope.getFunctionParent() || scope.getProgramParent(); | ||
var ids = path.getBindingIdentifiers(); | ||
const parentScope = scope.getFunctionParent() || scope.getProgramParent(); | ||
const ids = path.getBindingIdentifiers(); | ||
for (var name in ids) { | ||
var binding = scope.getOwnBinding(name); | ||
for (const name in ids) { | ||
const binding = scope.getOwnBinding(name); | ||
if (binding) binding.kind = "var"; | ||
@@ -198,12 +198,15 @@ scope.moveBindingTo(name, parentScope); | ||
var letReferenceBlockVisitor = _core().traverse.visitors.merge([{ | ||
const letReferenceBlockVisitor = _core().traverse.visitors.merge([{ | ||
Loop: { | ||
enter: function enter(path, state) { | ||
enter(path, state) { | ||
state.loopDepth++; | ||
}, | ||
exit: function exit(path, state) { | ||
exit(path, state) { | ||
state.loopDepth--; | ||
} | ||
}, | ||
Function: function Function(path, state) { | ||
Function(path, state) { | ||
if (state.loopDepth > 0) { | ||
@@ -215,22 +218,24 @@ path.traverse(letReferenceFunctionVisitor, state); | ||
} | ||
}, _tdz.visitor]); | ||
var letReferenceFunctionVisitor = _core().traverse.visitors.merge([{ | ||
ReferencedIdentifier: function ReferencedIdentifier(path, state) { | ||
var ref = state.letReferences[path.node.name]; | ||
const letReferenceFunctionVisitor = _core().traverse.visitors.merge([{ | ||
ReferencedIdentifier(path, state) { | ||
const ref = state.letReferences[path.node.name]; | ||
if (!ref) return; | ||
var localBinding = path.scope.getBindingIdentifier(path.node.name); | ||
const localBinding = path.scope.getBindingIdentifier(path.node.name); | ||
if (localBinding && localBinding !== ref) return; | ||
state.closurify = true; | ||
} | ||
}, _tdz.visitor]); | ||
var hoistVarDeclarationsVisitor = { | ||
enter: function enter(path, self) { | ||
var node = path.node, | ||
parent = path.parent; | ||
const hoistVarDeclarationsVisitor = { | ||
enter(path, self) { | ||
const node = path.node, | ||
parent = path.parent; | ||
if (path.isForStatement()) { | ||
if (isVar(node.init, node)) { | ||
var nodes = self.pushDeclar(node.init); | ||
const nodes = self.pushDeclar(node.init); | ||
@@ -249,5 +254,3 @@ if (nodes.length === 1) { | ||
} else if (isVar(node, parent)) { | ||
path.replaceWithMultiple(self.pushDeclar(node).map(function (expr) { | ||
return _core().types.expressionStatement(expr); | ||
})); | ||
path.replaceWithMultiple(self.pushDeclar(node).map(expr => _core().types.expressionStatement(expr))); | ||
} else if (path.isFunction()) { | ||
@@ -257,15 +260,18 @@ return path.skip(); | ||
} | ||
}; | ||
var loopLabelVisitor = { | ||
LabeledStatement: function LabeledStatement(_ref, state) { | ||
var node = _ref.node; | ||
const loopLabelVisitor = { | ||
LabeledStatement({ | ||
node | ||
}, state) { | ||
state.innerLabels.push(node.label.name); | ||
} | ||
}; | ||
var continuationVisitor = { | ||
enter: function enter(path, state) { | ||
const continuationVisitor = { | ||
enter(path, state) { | ||
if (path.isAssignmentExpression() || path.isUpdateExpression()) { | ||
var bindings = path.getBindingIdentifiers(); | ||
const bindings = path.getBindingIdentifiers(); | ||
for (var name in bindings) { | ||
for (const name in bindings) { | ||
if (state.outsideReferences[name] !== path.scope.getBindingIdentifier(name)) { | ||
@@ -281,2 +287,3 @@ continue; | ||
} | ||
}; | ||
@@ -292,5 +299,5 @@ | ||
var loopVisitor = { | ||
Loop: function Loop(path, state) { | ||
var oldIgnoreLabeless = state.ignoreLabeless; | ||
const loopVisitor = { | ||
Loop(path, state) { | ||
const oldIgnoreLabeless = state.ignoreLabeless; | ||
state.ignoreLabeless = true; | ||
@@ -301,7 +308,9 @@ path.traverse(loopVisitor, state); | ||
}, | ||
Function: function Function(path) { | ||
Function(path) { | ||
path.skip(); | ||
}, | ||
SwitchCase: function SwitchCase(path, state) { | ||
var oldInSwitchCase = state.inSwitchCase; | ||
SwitchCase(path, state) { | ||
const oldInSwitchCase = state.inSwitchCase; | ||
state.inSwitchCase = true; | ||
@@ -312,9 +321,10 @@ path.traverse(loopVisitor, state); | ||
}, | ||
"BreakStatement|ContinueStatement|ReturnStatement": function BreakStatementContinueStatementReturnStatement(path, state) { | ||
var node = path.node, | ||
parent = path.parent, | ||
scope = path.scope; | ||
"BreakStatement|ContinueStatement|ReturnStatement"(path, state) { | ||
const node = path.node, | ||
parent = path.parent, | ||
scope = path.scope; | ||
if (node[this.LOOP_IGNORE]) return; | ||
var replace; | ||
var loopText = loopNodeTo(node); | ||
let replace; | ||
let loopText = loopNodeTo(node); | ||
@@ -327,3 +337,3 @@ if (loopText) { | ||
loopText = loopText + "|" + node.label.name; | ||
loopText = `${loopText}|${node.label.name}`; | ||
} else { | ||
@@ -351,6 +361,7 @@ if (state.ignoreLabeless) return; | ||
} | ||
}; | ||
var BlockScoping = function () { | ||
function BlockScoping(loopPath, blockPath, parent, scope, throwIfClosureRequired, tdzEnabled, state) { | ||
class BlockScoping { | ||
constructor(loopPath, blockPath, parent, scope, throwIfClosureRequired, tdzEnabled, state) { | ||
this.parent = parent; | ||
@@ -376,9 +387,7 @@ this.scope = scope; | ||
var _proto = BlockScoping.prototype; | ||
_proto.run = function run() { | ||
var block = this.block; | ||
run() { | ||
const block = this.block; | ||
if (DONE.has(block)) return; | ||
DONE.add(block); | ||
var needsClosure = this.getLetReferences(); | ||
const needsClosure = this.getLetReferences(); | ||
this.checkConstants(); | ||
@@ -404,10 +413,10 @@ | ||
} | ||
}; | ||
} | ||
_proto.checkConstants = function checkConstants() { | ||
var scope = this.scope; | ||
var state = this.state; | ||
checkConstants() { | ||
const scope = this.scope; | ||
const state = this.state; | ||
for (var name in scope.bindings) { | ||
var binding = scope.bindings[name]; | ||
for (const name in scope.bindings) { | ||
const binding = scope.bindings[name]; | ||
if (binding.kind !== "const") continue; | ||
@@ -417,6 +426,6 @@ var _arr = binding.constantViolations; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var violation = _arr[_i]; | ||
var readOnlyError = state.addHelper("readOnlyError"); | ||
const violation = _arr[_i]; | ||
const readOnlyError = state.addHelper("readOnlyError"); | ||
var throwNode = _core().types.callExpression(readOnlyError, [_core().types.stringLiteral(name)]); | ||
const throwNode = _core().types.callExpression(readOnlyError, [_core().types.stringLiteral(name)]); | ||
@@ -433,12 +442,12 @@ if (violation.isAssignmentExpression()) { | ||
} | ||
}; | ||
} | ||
_proto.updateScopeInfo = function updateScopeInfo(wrappedInClosure) { | ||
var scope = this.scope; | ||
var parentScope = scope.getFunctionParent() || scope.getProgramParent(); | ||
var letRefs = this.letReferences; | ||
updateScopeInfo(wrappedInClosure) { | ||
const scope = this.scope; | ||
const parentScope = scope.getFunctionParent() || scope.getProgramParent(); | ||
const letRefs = this.letReferences; | ||
for (var key in letRefs) { | ||
var ref = letRefs[key]; | ||
var binding = scope.getBinding(ref.name); | ||
for (const key in letRefs) { | ||
const ref = letRefs[key]; | ||
const binding = scope.getBinding(ref.name); | ||
if (!binding) continue; | ||
@@ -456,10 +465,10 @@ | ||
} | ||
}; | ||
} | ||
_proto.remap = function remap() { | ||
var letRefs = this.letReferences; | ||
var scope = this.scope; | ||
remap() { | ||
const letRefs = this.letReferences; | ||
const scope = this.scope; | ||
for (var key in letRefs) { | ||
var ref = letRefs[key]; | ||
for (const key in letRefs) { | ||
const ref = letRefs[key]; | ||
@@ -476,5 +485,5 @@ if (scope.parentHasBinding(key) || scope.hasGlobal(key)) { | ||
} | ||
}; | ||
} | ||
_proto.wrapClosure = function wrapClosure() { | ||
wrapClosure() { | ||
if (this.throwIfClosureRequired) { | ||
@@ -484,8 +493,8 @@ throw this.blockPath.buildCodeFrameError("Compiling let/const in this block would add a closure " + "(throwIfClosureRequired)."); | ||
var block = this.block; | ||
var outsideRefs = this.outsideLetReferences; | ||
const block = this.block; | ||
const outsideRefs = this.outsideLetReferences; | ||
if (this.loop) { | ||
for (var name in outsideRefs) { | ||
var id = outsideRefs[name]; | ||
for (const name in outsideRefs) { | ||
const id = outsideRefs[name]; | ||
@@ -504,19 +513,15 @@ if (this.scope.hasGlobal(id.name) || this.scope.parentHasBinding(id.name)) { | ||
this.hoistVarDeclarations(); | ||
var args = (0, _values().default)(outsideRefs).map(function (id) { | ||
return _core().types.cloneNode(id); | ||
}); | ||
var params = args.map(function (id) { | ||
return _core().types.cloneNode(id); | ||
}); | ||
var isSwitch = this.blockPath.isSwitchStatement(); | ||
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(); | ||
var 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); | ||
var call = _core().types.callExpression(_core().types.nullLiteral(), args); | ||
let call = _core().types.callExpression(_core().types.nullLiteral(), args); | ||
var basePath = ".callee"; | ||
let basePath = ".callee"; | ||
var hasYield = _core().traverse.hasType(fn.body, "YieldExpression", _core().types.FUNCTION_TYPES); | ||
const hasYield = _core().traverse.hasType(fn.body, "YieldExpression", _core().types.FUNCTION_TYPES); | ||
@@ -529,3 +534,3 @@ if (hasYield) { | ||
var hasAsync = _core().traverse.hasType(fn.body, "AwaitExpression", _core().types.FUNCTION_TYPES); | ||
const hasAsync = _core().traverse.hasType(fn.body, "AwaitExpression", _core().types.FUNCTION_TYPES); | ||
@@ -538,7 +543,7 @@ if (hasAsync) { | ||
var placeholderPath; | ||
var index; | ||
let placeholderPath; | ||
let index; | ||
if (this.has.hasReturn || this.has.hasBreakContinue) { | ||
var ret = this.scope.generateUid("ret"); | ||
const ret = this.scope.generateUid("ret"); | ||
this.body.push(_core().types.variableDeclaration("var", [_core().types.variableDeclarator(_core().types.identifier(ret), call)])); | ||
@@ -554,9 +559,9 @@ placeholderPath = "declarations.0.init" + basePath; | ||
var callPath; | ||
let callPath; | ||
if (isSwitch) { | ||
var _blockPath = this.blockPath, | ||
parentPath = _blockPath.parentPath, | ||
listKey = _blockPath.listKey, | ||
key = _blockPath.key; | ||
const _this$blockPath = this.blockPath, | ||
parentPath = _this$blockPath.parentPath, | ||
listKey = _this$blockPath.listKey, | ||
key = _this$blockPath.key; | ||
this.blockPath.replaceWithMultiple(this.body); | ||
@@ -569,8 +574,8 @@ callPath = parentPath.get(listKey)[key + index]; | ||
var placeholder = callPath.get(placeholderPath); | ||
var fnPath; | ||
const placeholder = callPath.get(placeholderPath); | ||
let fnPath; | ||
if (this.loop) { | ||
var loopId = this.scope.generateUid("loop"); | ||
var p = this.loopPath.insertBefore(_core().types.variableDeclaration("var", [_core().types.variableDeclarator(_core().types.identifier(loopId), fn)])); | ||
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)); | ||
@@ -584,8 +589,6 @@ fnPath = p[0].get("declarations.0.init"); | ||
fnPath.unwrapFunctionEnvironment(); | ||
}; | ||
} | ||
_proto.addContinuations = function addContinuations(fn) { | ||
var _this = this; | ||
var state = { | ||
addContinuations(fn) { | ||
const state = { | ||
reassignments: {}, | ||
@@ -597,34 +600,22 @@ returnStatements: [], | ||
var _loop = function _loop(i) { | ||
var param = fn.params[i]; | ||
if (!state.reassignments[param.name]) return "continue"; | ||
var paramName = param.name; | ||
var newParamName = _this.scope.generateUid(param.name); | ||
for (let i = 0; i < fn.params.length; i++) { | ||
const param = fn.params[i]; | ||
if (!state.reassignments[param.name]) continue; | ||
const paramName = param.name; | ||
const newParamName = this.scope.generateUid(param.name); | ||
fn.params[i] = _core().types.identifier(newParamName); | ||
_this.scope.rename(paramName, newParamName, fn); | ||
state.returnStatements.forEach(function (returnStatement) { | ||
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)))); | ||
}); | ||
fn.body.body.push(_core().types.expressionStatement(_core().types.assignmentExpression("=", _core().types.identifier(paramName), _core().types.identifier(newParamName)))); | ||
}; | ||
for (var i = 0; i < fn.params.length; i++) { | ||
var _ret = _loop(i); | ||
if (_ret === "continue") continue; | ||
} | ||
}; | ||
} | ||
_proto.getLetReferences = function getLetReferences() { | ||
var _this2 = this; | ||
getLetReferences() { | ||
const block = this.block; | ||
let declarators = []; | ||
var block = this.block; | ||
var declarators = []; | ||
if (this.loop) { | ||
var init = this.loop.left || this.loop.init; | ||
const init = this.loop.left || this.loop.init; | ||
@@ -637,3 +628,3 @@ if (isBlockScoped(init)) { | ||
var addDeclarationsFromChild = function addDeclarationsFromChild(path, node) { | ||
const addDeclarationsFromChild = (path, node) => { | ||
node = node || path.node; | ||
@@ -643,3 +634,3 @@ | ||
if (isBlockScoped(node)) { | ||
convertBlockScopedToVar(path, node, block, _this2.scope); | ||
convertBlockScopedToVar(path, node, block, this.scope); | ||
} | ||
@@ -656,5 +647,5 @@ | ||
if (block.body) { | ||
var declarPaths = this.blockPath.get("body"); | ||
const declarPaths = this.blockPath.get("body"); | ||
for (var i = 0; i < block.body.length; i++) { | ||
for (let i = 0; i < block.body.length; i++) { | ||
addDeclarationsFromChild(declarPaths[i]); | ||
@@ -665,10 +656,10 @@ } | ||
if (block.cases) { | ||
var _declarPaths = this.blockPath.get("cases"); | ||
const declarPaths = this.blockPath.get("cases"); | ||
for (var _i2 = 0; _i2 < block.cases.length; _i2++) { | ||
var consequents = block.cases[_i2].consequent; | ||
for (let i = 0; i < block.cases.length; i++) { | ||
const consequents = block.cases[i].consequent; | ||
for (var j = 0; j < consequents.length; j++) { | ||
var declar = consequents[j]; | ||
addDeclarationsFromChild(_declarPaths[_i2], declar); | ||
for (let j = 0; j < consequents.length; j++) { | ||
const declar = consequents[j]; | ||
addDeclarationsFromChild(declarPaths[i], declar); | ||
} | ||
@@ -678,6 +669,6 @@ } | ||
for (var _i3 = 0; _i3 < declarators.length; _i3++) { | ||
var _declar = declarators[_i3]; | ||
for (let i = 0; i < declarators.length; i++) { | ||
const declar = declarators[i]; | ||
var keys = _core().types.getBindingIdentifiers(_declar, false, true); | ||
const keys = _core().types.getBindingIdentifiers(declar, false, true); | ||
@@ -689,3 +680,3 @@ (0, _extend().default)(this.letReferences, keys); | ||
if (!this.hasLetReferences) return; | ||
var state = { | ||
const state = { | ||
letReferences: this.letReferences, | ||
@@ -695,5 +686,3 @@ closurify: false, | ||
tdzEnabled: this.tdzEnabled, | ||
addHelper: function addHelper(name) { | ||
return _this2.addHelper(name); | ||
} | ||
addHelper: name => this.addHelper(name) | ||
}; | ||
@@ -707,6 +696,6 @@ | ||
return state.closurify; | ||
}; | ||
} | ||
_proto.checkLoop = function checkLoop() { | ||
var state = { | ||
checkLoop() { | ||
const state = { | ||
hasBreakContinue: false, | ||
@@ -724,14 +713,14 @@ ignoreLabeless: false, | ||
return state; | ||
}; | ||
} | ||
_proto.hoistVarDeclarations = function hoistVarDeclarations() { | ||
hoistVarDeclarations() { | ||
this.blockPath.traverse(hoistVarDeclarationsVisitor, this); | ||
}; | ||
} | ||
_proto.pushDeclar = function pushDeclar(node) { | ||
var declars = []; | ||
pushDeclar(node) { | ||
const declars = []; | ||
var names = _core().types.getBindingIdentifiers(node); | ||
const names = _core().types.getBindingIdentifiers(node); | ||
for (var name in names) { | ||
for (const name in names) { | ||
declars.push(_core().types.variableDeclarator(names[name])); | ||
@@ -741,9 +730,9 @@ } | ||
this.body.push(_core().types.variableDeclaration(node.kind, declars)); | ||
var replace = []; | ||
const replace = []; | ||
for (var i = 0; i < node.declarations.length; i++) { | ||
var declar = node.declarations[i]; | ||
for (let i = 0; i < node.declarations.length; i++) { | ||
const declar = node.declarations[i]; | ||
if (!declar.init) continue; | ||
var 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)); | ||
@@ -754,9 +743,9 @@ replace.push(_core().types.inherits(expr, declar)); | ||
return replace; | ||
}; | ||
} | ||
_proto.buildHas = function buildHas(ret) { | ||
var body = this.body; | ||
var retCheck; | ||
var has = this.has; | ||
var cases = []; | ||
buildHas(ret) { | ||
const body = this.body; | ||
let retCheck; | ||
const has = this.has; | ||
const cases = []; | ||
@@ -770,3 +759,3 @@ if (has.hasReturn) { | ||
if (has.hasBreakContinue) { | ||
for (var key in has.map) { | ||
for (const key in has.map) { | ||
cases.push(_core().types.switchCase(_core().types.stringLiteral(key), [has.map[key]])); | ||
@@ -780,8 +769,8 @@ } | ||
if (cases.length === 1) { | ||
var single = cases[0]; | ||
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 (var i = 0; i < cases.length; i++) { | ||
var caseConsequent = cases[i].consequent[0]; | ||
for (let i = 0; i < cases.length; i++) { | ||
const caseConsequent = cases[i].consequent[0]; | ||
@@ -805,5 +794,4 @@ if (_core().types.isBreakStatement(caseConsequent) && !caseConsequent.label) { | ||
} | ||
}; | ||
} | ||
return BlockScoping; | ||
}(); | ||
} |
@@ -9,3 +9,3 @@ "use strict"; | ||
function _core() { | ||
var data = require("@babel/core"); | ||
const data = require("@babel/core"); | ||
@@ -20,3 +20,3 @@ _core = function _core() { | ||
function getTDZStatus(refPath, bindingPath) { | ||
var executionStatus = bindingPath._guessExecutionStatusRelativeTo(refPath); | ||
const executionStatus = bindingPath._guessExecutionStatusRelativeTo(refPath); | ||
@@ -37,3 +37,3 @@ if (executionStatus === "before") { | ||
function isReference(node, scope, state) { | ||
var declared = state.letReferences[node.name]; | ||
const declared = state.letReferences[node.name]; | ||
if (!declared) return false; | ||
@@ -43,8 +43,8 @@ return scope.getBindingIdentifier(node.name) === declared; | ||
var visitor = { | ||
ReferencedIdentifier: function ReferencedIdentifier(path, state) { | ||
const visitor = { | ||
ReferencedIdentifier(path, state) { | ||
if (!state.tdzEnabled) return; | ||
var node = path.node, | ||
parent = path.parent, | ||
scope = path.scope; | ||
const node = path.node, | ||
parent = path.parent, | ||
scope = path.scope; | ||
if (path.parentPath.isFor({ | ||
@@ -54,9 +54,9 @@ left: node | ||
if (!isReference(node, scope, state)) return; | ||
var bindingPath = scope.getBinding(node.name).path; | ||
const bindingPath = scope.getBinding(node.name).path; | ||
if (bindingPath.isFunctionDeclaration()) return; | ||
var status = getTDZStatus(path, bindingPath); | ||
const status = getTDZStatus(path, bindingPath); | ||
if (status === "inside") return; | ||
if (status === "maybe") { | ||
var assert = buildTDZAssert(node, state); | ||
const assert = buildTDZAssert(node, state); | ||
bindingPath.parent._tdzThis = true; | ||
@@ -72,15 +72,16 @@ path.skip(); | ||
} else if (status === "outside") { | ||
path.replaceWith(_core().types.throwStatement(_core().types.inherits(_core().types.newExpression(_core().types.identifier("ReferenceError"), [_core().types.stringLiteral(node.name + " is not defined - temporal dead zone")]), node))); | ||
path.replaceWith(_core().types.throwStatement(_core().types.inherits(_core().types.newExpression(_core().types.identifier("ReferenceError"), [_core().types.stringLiteral(`${node.name} is not defined - temporal dead zone`)]), node))); | ||
} | ||
}, | ||
AssignmentExpression: { | ||
exit: function exit(path, state) { | ||
exit(path, state) { | ||
if (!state.tdzEnabled) return; | ||
var node = path.node; | ||
const node = path.node; | ||
if (node._ignoreBlockScopingTDZ) return; | ||
var nodes = []; | ||
var ids = path.getBindingIdentifiers(); | ||
const nodes = []; | ||
const ids = path.getBindingIdentifiers(); | ||
for (var name in ids) { | ||
var id = ids[name]; | ||
for (const name in ids) { | ||
const id = ids[name]; | ||
@@ -98,4 +99,5 @@ if (isReference(id, path.scope, state)) { | ||
} | ||
} | ||
}; | ||
exports.visitor = visitor; |
{ | ||
"name": "@babel/plugin-transform-block-scoping", | ||
"version": "7.0.0-beta.46", | ||
"version": "7.0.0-beta.47", | ||
"description": "Compile ES2015 block scoping (const and let) to ES5", | ||
@@ -9,4 +9,4 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-block-scoping", | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "7.0.0-beta.46", | ||
"lodash": "^4.2.0" | ||
"@babel/helper-plugin-utils": "7.0.0-beta.47", | ||
"lodash": "^4.17.5" | ||
}, | ||
@@ -17,8 +17,8 @@ "keywords": [ | ||
"peerDependencies": { | ||
"@babel/core": "7.0.0-beta.46" | ||
"@babel/core": "7.0.0-beta.47" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.46", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.46" | ||
"@babel/core": "7.0.0-beta.47", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.47" | ||
} | ||
} |
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
0
26733
675
+ Added@babel/code-frame@7.0.0-beta.47(transitive)
+ Added@babel/core@7.0.0-beta.47(transitive)
+ Added@babel/generator@7.0.0-beta.47(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.47(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.47(transitive)
+ Added@babel/helper-plugin-utils@7.0.0-beta.47(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.47(transitive)
+ Added@babel/helpers@7.0.0-beta.47(transitive)
+ Added@babel/highlight@7.0.0-beta.47(transitive)
+ Added@babel/template@7.0.0-beta.47(transitive)
+ Added@babel/traverse@7.0.0-beta.47(transitive)
+ Added@babel/types@7.0.0-beta.47(transitive)
+ Addedbabylon@7.0.0-beta.47(transitive)
- Removed@babel/code-frame@7.0.0-beta.46(transitive)
- Removed@babel/core@7.0.0-beta.46(transitive)
- Removed@babel/generator@7.0.0-beta.46(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.46(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.46(transitive)
- Removed@babel/helper-plugin-utils@7.0.0-beta.46(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.46(transitive)
- Removed@babel/helpers@7.0.0-beta.46(transitive)
- Removed@babel/highlight@7.0.0-beta.46(transitive)
- Removed@babel/template@7.0.0-beta.46(transitive)
- Removed@babel/traverse@7.0.0-beta.46(transitive)
- Removed@babel/types@7.0.0-beta.46(transitive)
- Removedbabylon@7.0.0-beta.46(transitive)
Updatedlodash@^4.17.5