babel-plugin-transform-es2015-block-scoping
Advanced tools
Comparing version
106
lib/index.js
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = _default; | ||
exports.default = function () { | ||
var _babelTraverse = _interopRequireDefault(require("babel-traverse")); | ||
var _tdz = require("./tdz"); | ||
var t = _interopRequireWildcard(require("babel-types")); | ||
var _values = _interopRequireDefault(require("lodash/values")); | ||
var _extend = _interopRequireDefault(require("lodash/extend")); | ||
var _babelTemplate = _interopRequireDefault(require("babel-template")); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var DONE = new WeakSet(); | ||
function _default() { | ||
return { | ||
@@ -40,6 +59,5 @@ visitor: { | ||
Loop: function Loop(path, file) { | ||
var node = path.node, | ||
parent = path.parent, | ||
var parent = path.parent, | ||
scope = path.scope; | ||
t.ensureBlock(node); | ||
path.ensureBlock(); | ||
var blockScoping = new BlockScoping(path, path.get("body"), parent, scope, file); | ||
@@ -63,32 +81,4 @@ var replace = blockScoping.run(); | ||
}; | ||
}; | ||
} | ||
var _babelTraverse = require("babel-traverse"); | ||
var _babelTraverse2 = _interopRequireDefault(_babelTraverse); | ||
var _tdz = require("./tdz"); | ||
var _babelTypes = require("babel-types"); | ||
var t = _interopRequireWildcard(_babelTypes); | ||
var _values = require("lodash/values"); | ||
var _values2 = _interopRequireDefault(_values); | ||
var _extend = require("lodash/extend"); | ||
var _extend2 = _interopRequireDefault(_extend); | ||
var _babelTemplate = require("babel-template"); | ||
var _babelTemplate2 = _interopRequireDefault(_babelTemplate); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var DONE = new WeakSet(); | ||
function ignoreBlock(path) { | ||
@@ -98,3 +88,3 @@ return t.isLoop(path.parent) || t.isCatchClause(path.parent); | ||
var buildRetCheck = (0, _babelTemplate2.default)("\n if (typeof RETURN === \"object\") return RETURN.v;\n"); | ||
var buildRetCheck = (0, _babelTemplate.default)("\n if (typeof RETURN === \"object\") return RETURN.v;\n"); | ||
@@ -152,3 +142,3 @@ function isBlockScoped(node) { | ||
var letReferenceBlockVisitor = _babelTraverse2.default.visitors.merge([{ | ||
var letReferenceBlockVisitor = _babelTraverse.default.visitors.merge([{ | ||
Loop: { | ||
@@ -171,3 +161,3 @@ enter: function enter(path, state) { | ||
var letReferenceFunctionVisitor = _babelTraverse2.default.visitors.merge([{ | ||
var letReferenceFunctionVisitor = _babelTraverse.default.visitors.merge([{ | ||
ReferencedIdentifier: function ReferencedIdentifier(path, state) { | ||
@@ -264,3 +254,3 @@ var ref = state.letReferences[path.node.name]; | ||
if (node[this.LOOP_IGNORE]) return; | ||
var replace = void 0; | ||
var replace; | ||
var loopText = loopNodeTo(node); | ||
@@ -319,3 +309,5 @@ | ||
BlockScoping.prototype.run = function run() { | ||
var _proto = BlockScoping.prototype; | ||
_proto.run = function run() { | ||
var block = this.block; | ||
@@ -346,3 +338,3 @@ if (DONE.has(block)) return; | ||
BlockScoping.prototype.updateScopeInfo = function updateScopeInfo(wrappedInClosure) { | ||
_proto.updateScopeInfo = function updateScopeInfo(wrappedInClosure) { | ||
var scope = this.scope; | ||
@@ -369,3 +361,3 @@ var parentScope = scope.getFunctionParent() || scope.getProgramParent(); | ||
BlockScoping.prototype.remap = function remap() { | ||
_proto.remap = function remap() { | ||
var letRefs = this.letReferences; | ||
@@ -389,3 +381,3 @@ var scope = this.scope; | ||
BlockScoping.prototype.wrapClosure = function wrapClosure() { | ||
_proto.wrapClosure = function wrapClosure() { | ||
if (this.file.opts.throwIfClosureRequired) { | ||
@@ -414,3 +406,3 @@ throw this.blockPath.buildCodeFrameError("Compiling let/const in this block would add a closure " + "(throwIfClosureRequired)."); | ||
this.hoistVarDeclarations(); | ||
var args = (0, _values2.default)(outsideRefs); | ||
var args = (0, _values.default)(outsideRefs); | ||
var params = args.map(function (id) { | ||
@@ -425,3 +417,3 @@ return t.clone(id); | ||
var hasYield = _babelTraverse2.default.hasType(fn.body, "YieldExpression", t.FUNCTION_TYPES); | ||
var hasYield = _babelTraverse.default.hasType(fn.body, "YieldExpression", t.FUNCTION_TYPES); | ||
@@ -434,3 +426,3 @@ if (hasYield) { | ||
var hasAsync = _babelTraverse2.default.hasType(fn.body, "AwaitExpression", t.FUNCTION_TYPES); | ||
var hasAsync = _babelTraverse.default.hasType(fn.body, "AwaitExpression", t.FUNCTION_TYPES); | ||
@@ -443,4 +435,4 @@ if (hasAsync) { | ||
var placeholderPath = void 0; | ||
var index = void 0; | ||
var placeholderPath; | ||
var index; | ||
@@ -459,3 +451,3 @@ if (this.has.hasReturn || this.has.hasBreakContinue) { | ||
var callPath = void 0; | ||
var callPath; | ||
@@ -475,3 +467,3 @@ if (isSwitch) { | ||
var placeholder = callPath.get(placeholderPath); | ||
var fnPath = void 0; | ||
var fnPath; | ||
@@ -491,3 +483,3 @@ if (this.loop) { | ||
BlockScoping.prototype.addContinuations = function addContinuations(fn) { | ||
_proto.addContinuations = function addContinuations(fn) { | ||
var state = { | ||
@@ -509,3 +501,3 @@ reassignments: {}, | ||
BlockScoping.prototype.getLetReferences = function getLetReferences() { | ||
_proto.getLetReferences = function getLetReferences() { | ||
var _this = this; | ||
@@ -521,3 +513,3 @@ | ||
declarators.push(init); | ||
(0, _extend2.default)(this.outsideLetReferences, t.getBindingIdentifiers(init)); | ||
(0, _extend.default)(this.outsideLetReferences, t.getBindingIdentifiers(init)); | ||
} | ||
@@ -565,3 +557,3 @@ } | ||
var keys = t.getBindingIdentifiers(_declar, false, true); | ||
(0, _extend2.default)(this.letReferences, keys); | ||
(0, _extend.default)(this.letReferences, keys); | ||
this.hasLetReferences = true; | ||
@@ -586,3 +578,3 @@ } | ||
BlockScoping.prototype.checkLoop = function checkLoop() { | ||
_proto.checkLoop = function checkLoop() { | ||
var state = { | ||
@@ -603,7 +595,7 @@ hasBreakContinue: false, | ||
BlockScoping.prototype.hoistVarDeclarations = function hoistVarDeclarations() { | ||
_proto.hoistVarDeclarations = function hoistVarDeclarations() { | ||
this.blockPath.traverse(hoistVarDeclarationsVisitor, this); | ||
}; | ||
BlockScoping.prototype.pushDeclar = function pushDeclar(node) { | ||
_proto.pushDeclar = function pushDeclar(node) { | ||
var declars = []; | ||
@@ -629,5 +621,5 @@ var names = t.getBindingIdentifiers(node); | ||
BlockScoping.prototype.buildHas = function buildHas(ret) { | ||
_proto.buildHas = function buildHas(ret) { | ||
var body = this.body; | ||
var retCheck = void 0; | ||
var retCheck; | ||
var has = this.has; | ||
@@ -634,0 +626,0 @@ var cases = []; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.visitor = undefined; | ||
exports.visitor = void 0; | ||
var _babelTypes = require("babel-types"); | ||
var t = _interopRequireWildcard(require("babel-types")); | ||
var t = _interopRequireWildcard(_babelTypes); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -34,3 +32,3 @@ | ||
var visitor = exports.visitor = { | ||
var visitor = { | ||
ReferencedIdentifier: function ReferencedIdentifier(path, state) { | ||
@@ -87,2 +85,3 @@ if (!this.file.opts.tdz) return; | ||
} | ||
}; | ||
}; | ||
exports.visitor = visitor; |
{ | ||
"name": "babel-plugin-transform-es2015-block-scoping", | ||
"version": "7.0.0-beta.2", | ||
"version": "7.0.0-beta.3", | ||
"description": "Compile ES2015 block scoping (const and let) to ES5", | ||
@@ -9,5 +9,5 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-block-scoping", | ||
"dependencies": { | ||
"babel-template": "7.0.0-beta.2", | ||
"babel-traverse": "7.0.0-beta.2", | ||
"babel-types": "7.0.0-beta.2", | ||
"babel-template": "7.0.0-beta.3", | ||
"babel-traverse": "7.0.0-beta.3", | ||
"babel-types": "7.0.0-beta.3", | ||
"lodash": "^4.2.0" | ||
@@ -19,4 +19,4 @@ }, | ||
"devDependencies": { | ||
"babel-helper-plugin-test-runner": "7.0.0-beta.2" | ||
"babel-helper-plugin-test-runner": "7.0.0-beta.3" | ||
} | ||
} |
23259
-1.62%604
-0.66%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated