aboutsummaryrefslogtreecommitdiff
path: root/node_modules/babel-traverse/lib
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/babel-traverse/lib')
-rw-r--r--node_modules/babel-traverse/lib/cache.js10
-rw-r--r--node_modules/babel-traverse/lib/index.js3
-rw-r--r--node_modules/babel-traverse/lib/path/ancestry.js12
-rw-r--r--node_modules/babel-traverse/lib/path/comments.js2
-rw-r--r--node_modules/babel-traverse/lib/path/evaluation.js10
-rw-r--r--node_modules/babel-traverse/lib/path/family.js101
-rw-r--r--node_modules/babel-traverse/lib/path/index.js12
-rw-r--r--node_modules/babel-traverse/lib/path/inference/inferer-reference.js12
-rw-r--r--node_modules/babel-traverse/lib/path/introspection.js26
-rw-r--r--node_modules/babel-traverse/lib/path/lib/hoister.js91
-rw-r--r--node_modules/babel-traverse/lib/path/lib/removal-hooks.js21
-rw-r--r--node_modules/babel-traverse/lib/path/lib/virtual-types.js20
-rw-r--r--node_modules/babel-traverse/lib/path/modification.js4
-rw-r--r--node_modules/babel-traverse/lib/path/replacement.js14
-rw-r--r--node_modules/babel-traverse/lib/scope/binding.js10
-rw-r--r--node_modules/babel-traverse/lib/scope/index.js177
-rw-r--r--node_modules/babel-traverse/lib/scope/lib/renamer.js10
17 files changed, 333 insertions, 202 deletions
diff --git a/node_modules/babel-traverse/lib/cache.js b/node_modules/babel-traverse/lib/cache.js
index c88cdba83..b337eec6b 100644
--- a/node_modules/babel-traverse/lib/cache.js
+++ b/node_modules/babel-traverse/lib/cache.js
@@ -8,6 +8,8 @@ var _weakMap = require("babel-runtime/core-js/weak-map");
var _weakMap2 = _interopRequireDefault(_weakMap);
exports.clear = clear;
+exports.clearPath = clearPath;
+exports.clearScope = clearScope;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -15,6 +17,14 @@ var path = exports.path = new _weakMap2.default();
var scope = exports.scope = new _weakMap2.default();
function clear() {
+ clearPath();
+ clearScope();
+}
+
+function clearPath() {
exports.path = path = new _weakMap2.default();
+}
+
+function clearScope() {
exports.scope = scope = new _weakMap2.default();
} \ No newline at end of file
diff --git a/node_modules/babel-traverse/lib/index.js b/node_modules/babel-traverse/lib/index.js
index a5d1468d3..19a14cea5 100644
--- a/node_modules/babel-traverse/lib/index.js
+++ b/node_modules/babel-traverse/lib/index.js
@@ -155,6 +155,9 @@ traverse.clearCache = function () {
cache.clear();
};
+traverse.clearCache.clearPath = cache.clearPath;
+traverse.clearCache.clearScope = cache.clearScope;
+
traverse.copyCache = function (source, destination) {
if (cache.path.has(source)) {
cache.path.set(destination, cache.path.get(source));
diff --git a/node_modules/babel-traverse/lib/path/ancestry.js b/node_modules/babel-traverse/lib/path/ancestry.js
index 30f675b04..2a8c32272 100644
--- a/node_modules/babel-traverse/lib/path/ancestry.js
+++ b/node_modules/babel-traverse/lib/path/ancestry.js
@@ -13,6 +13,8 @@ exports.getStatementParent = getStatementParent;
exports.getEarliestCommonAncestorFrom = getEarliestCommonAncestorFrom;
exports.getDeepestCommonAncestorFrom = getDeepestCommonAncestorFrom;
exports.getAncestry = getAncestry;
+exports.isAncestor = isAncestor;
+exports.isDescendant = isDescendant;
exports.inType = inType;
exports.inShadow = inShadow;
@@ -181,6 +183,16 @@ function getAncestry() {
return paths;
}
+function isAncestor(maybeDescendant) {
+ return maybeDescendant.isDescendant(this);
+}
+
+function isDescendant(maybeAncestor) {
+ return !!this.findParent(function (parent) {
+ return parent === maybeAncestor;
+ });
+}
+
function inType() {
var path = this;
while (path) {
diff --git a/node_modules/babel-traverse/lib/path/comments.js b/node_modules/babel-traverse/lib/path/comments.js
index 215add0d2..800018cc3 100644
--- a/node_modules/babel-traverse/lib/path/comments.js
+++ b/node_modules/babel-traverse/lib/path/comments.js
@@ -5,6 +5,8 @@ exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
exports.addComment = addComment;
exports.addComments = addComments;
function shareCommentsWithSiblings() {
+ if (typeof this.key === "string") return;
+
var node = this.node;
if (!node) return;
diff --git a/node_modules/babel-traverse/lib/path/evaluation.js b/node_modules/babel-traverse/lib/path/evaluation.js
index 724d4728e..86aac21b5 100644
--- a/node_modules/babel-traverse/lib/path/evaluation.js
+++ b/node_modules/babel-traverse/lib/path/evaluation.js
@@ -156,15 +156,19 @@ function evaluate() {
return deopt(binding.path);
}
+ if (binding && path.node.start < binding.path.node.end) {
+ return deopt(binding.path);
+ }
+
if (binding && binding.hasValue) {
return binding.value;
} else {
if (node.name === "undefined") {
- return undefined;
+ return binding ? deopt(binding.path) : undefined;
} else if (node.name === "Infinity") {
- return Infinity;
+ return binding ? deopt(binding.path) : Infinity;
} else if (node.name === "NaN") {
- return NaN;
+ return binding ? deopt(binding.path) : NaN;
}
var resolved = path.resolve();
diff --git a/node_modules/babel-traverse/lib/path/family.js b/node_modules/babel-traverse/lib/path/family.js
index c3a60fdfd..4dd375298 100644
--- a/node_modules/babel-traverse/lib/path/family.js
+++ b/node_modules/babel-traverse/lib/path/family.js
@@ -2,6 +2,10 @@
exports.__esModule = true;
+var _create = require("babel-runtime/core-js/object/create");
+
+var _create2 = _interopRequireDefault(_create);
+
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
@@ -10,11 +14,17 @@ exports.getStatementParent = getStatementParent;
exports.getOpposite = getOpposite;
exports.getCompletionRecords = getCompletionRecords;
exports.getSibling = getSibling;
+exports.getPrevSibling = getPrevSibling;
+exports.getNextSibling = getNextSibling;
+exports.getAllNextSiblings = getAllNextSiblings;
+exports.getAllPrevSiblings = getAllPrevSiblings;
exports.get = get;
exports._getKey = _getKey;
exports._getPattern = _getPattern;
exports.getBindingIdentifiers = getBindingIdentifiers;
exports.getOuterBindingIdentifiers = getOuterBindingIdentifiers;
+exports.getBindingIdentifierPaths = getBindingIdentifierPaths;
+exports.getOuterBindingIdentifierPaths = getOuterBindingIdentifierPaths;
var _index = require("./index");
@@ -91,6 +101,36 @@ function getSibling(key) {
});
}
+function getPrevSibling() {
+ return this.getSibling(this.key - 1);
+}
+
+function getNextSibling() {
+ return this.getSibling(this.key + 1);
+}
+
+function getAllNextSiblings() {
+ var _key = this.key;
+ var sibling = this.getSibling(++_key);
+ var siblings = [];
+ while (sibling.node) {
+ siblings.push(sibling);
+ sibling = this.getSibling(++_key);
+ }
+ return siblings;
+}
+
+function getAllPrevSiblings() {
+ var _key = this.key;
+ var sibling = this.getSibling(--_key);
+ var siblings = [];
+ while (sibling.node) {
+ siblings.push(sibling);
+ sibling = this.getSibling(--_key);
+ }
+ return siblings;
+}
+
function get(key, context) {
if (context === true) context = this.context;
var parts = key.split(".");
@@ -162,4 +202,65 @@ function getBindingIdentifiers(duplicates) {
function getOuterBindingIdentifiers(duplicates) {
return t.getOuterBindingIdentifiers(this.node, duplicates);
+}
+
+function getBindingIdentifierPaths() {
+ var duplicates = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
+ var outerOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
+
+ var path = this;
+ var search = [].concat(path);
+ var ids = (0, _create2.default)(null);
+
+ while (search.length) {
+ var id = search.shift();
+ if (!id) continue;
+ if (!id.node) continue;
+
+ var keys = t.getBindingIdentifiers.keys[id.node.type];
+
+ if (id.isIdentifier()) {
+ if (duplicates) {
+ var _ids = ids[id.node.name] = ids[id.node.name] || [];
+ _ids.push(id);
+ } else {
+ ids[id.node.name] = id;
+ }
+ continue;
+ }
+
+ if (id.isExportDeclaration()) {
+ var declaration = id.get("declaration");
+ if (declaration.isDeclaration()) {
+ search.push(declaration);
+ }
+ continue;
+ }
+
+ if (outerOnly) {
+ if (id.isFunctionDeclaration()) {
+ search.push(id.get("id"));
+ continue;
+ }
+ if (id.isFunctionExpression()) {
+ continue;
+ }
+ }
+
+ if (keys) {
+ for (var i = 0; i < keys.length; i++) {
+ var key = keys[i];
+ var child = id.get(key);
+ if (Array.isArray(child) || child.node) {
+ search = search.concat(child);
+ }
+ }
+ }
+ }
+
+ return ids;
+}
+
+function getOuterBindingIdentifierPaths(duplicates) {
+ return this.getBindingIdentifierPaths(duplicates, true);
} \ No newline at end of file
diff --git a/node_modules/babel-traverse/lib/path/index.js b/node_modules/babel-traverse/lib/path/index.js
index d97a3d190..dd8ae2464 100644
--- a/node_modules/babel-traverse/lib/path/index.js
+++ b/node_modules/babel-traverse/lib/path/index.js
@@ -74,12 +74,12 @@ var NodePath = function () {
}
NodePath.get = function get(_ref) {
- var hub = _ref.hub;
- var parentPath = _ref.parentPath;
- var parent = _ref.parent;
- var container = _ref.container;
- var listKey = _ref.listKey;
- var key = _ref.key;
+ var hub = _ref.hub,
+ parentPath = _ref.parentPath,
+ parent = _ref.parent,
+ container = _ref.container,
+ listKey = _ref.listKey,
+ key = _ref.key;
if (!hub && parentPath) {
hub = parentPath.hub;
diff --git a/node_modules/babel-traverse/lib/path/inference/inferer-reference.js b/node_modules/babel-traverse/lib/path/inference/inferer-reference.js
index 22ab3053a..3a8ff31e6 100644
--- a/node_modules/babel-traverse/lib/path/inference/inferer-reference.js
+++ b/node_modules/babel-traverse/lib/path/inference/inferer-reference.js
@@ -44,15 +44,13 @@ function getTypeAnnotationBindingConstantViolations(path, name) {
var testType = getConditionalAnnotation(path, name);
if (testType) {
- (function () {
- var testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
+ var testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
- constantViolations = constantViolations.filter(function (path) {
- return testConstantViolations.indexOf(path) < 0;
- });
+ constantViolations = constantViolations.filter(function (path) {
+ return testConstantViolations.indexOf(path) < 0;
+ });
- types.push(testType.typeAnnotation);
- })();
+ types.push(testType.typeAnnotation);
}
if (constantViolations.length) {
diff --git a/node_modules/babel-traverse/lib/path/introspection.js b/node_modules/babel-traverse/lib/path/introspection.js
index a84f9d219..27be03912 100644
--- a/node_modules/babel-traverse/lib/path/introspection.js
+++ b/node_modules/babel-traverse/lib/path/introspection.js
@@ -3,10 +3,6 @@
exports.__esModule = true;
exports.is = undefined;
-var _typeof2 = require("babel-runtime/helpers/typeof");
-
-var _typeof3 = _interopRequireDefault(_typeof2);
-
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
@@ -319,8 +315,6 @@ function resolve(dangerous, resolved) {
}
function _resolve(dangerous, resolved) {
- var _this = this;
-
if (resolved && resolved.indexOf(this) >= 0) return;
resolved = resolved || [];
@@ -339,20 +333,12 @@ function _resolve(dangerous, resolved) {
if (binding.kind === "module") return;
if (binding.path !== this) {
- var _ret = function () {
- var ret = binding.path.resolve(dangerous, resolved);
-
- if (_this.find(function (parent) {
- return parent.node === ret.node;
- })) return {
- v: void 0
- };
- return {
- v: ret
- };
- }();
-
- if ((typeof _ret === "undefined" ? "undefined" : (0, _typeof3.default)(_ret)) === "object") return _ret.v;
+ var ret = binding.path.resolve(dangerous, resolved);
+
+ if (this.find(function (parent) {
+ return parent.node === ret.node;
+ })) return;
+ return ret;
}
} else if (this.isTypeCastExpression()) {
return this.get("expression").resolve(dangerous, resolved);
diff --git a/node_modules/babel-traverse/lib/path/lib/hoister.js b/node_modules/babel-traverse/lib/path/lib/hoister.js
index bcf8d78c4..3cdcdeb56 100644
--- a/node_modules/babel-traverse/lib/path/lib/hoister.js
+++ b/node_modules/babel-traverse/lib/path/lib/hoister.js
@@ -2,14 +2,14 @@
exports.__esModule = true;
-var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
-
-var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
-
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
+var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
+
+var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
+
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
@@ -20,35 +20,24 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
var referenceVisitor = {
ReferencedIdentifier: function ReferencedIdentifier(path, state) {
- if (path.isJSXIdentifier() && _babelTypes.react.isCompatTag(path.node.name)) {
+ if (path.isJSXIdentifier() && _babelTypes.react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
return;
}
+ if (path.node.name === "this") {
+ var scope = path.scope;
+ do {
+ if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) break;
+ } while (scope = scope.parent);
+ if (scope) state.breakOnScopePaths.push(scope.path);
+ }
+
var binding = path.scope.getBinding(path.node.name);
if (!binding) return;
if (binding !== state.scope.getBinding(path.node.name)) return;
- if (binding.constant) {
- state.bindings[path.node.name] = binding;
- } else {
- for (var _iterator = binding.constantViolations, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
- var _ref;
-
- if (_isArray) {
- if (_i >= _iterator.length) break;
- _ref = _iterator[_i++];
- } else {
- _i = _iterator.next();
- if (_i.done) break;
- _ref = _i.value;
- }
-
- var violationPath = _ref;
-
- state.breakOnScopePaths = state.breakOnScopePaths.concat(violationPath.getAncestry());
- }
- }
+ state.bindings[path.node.name] = binding;
}
};
@@ -57,10 +46,15 @@ var PathHoister = function () {
(0, _classCallCheck3.default)(this, PathHoister);
this.breakOnScopePaths = [];
+
this.bindings = {};
+
this.scopes = [];
+
this.scope = scope;
this.path = path;
+
+ this.attachAfter = false;
}
PathHoister.prototype.isCompatibleScope = function isCompatibleScope(scope) {
@@ -107,7 +101,29 @@ var PathHoister = function () {
if (binding.kind === "param") continue;
- if (binding.path.getStatementParent().key > path.key) return;
+ if (this.getAttachmentParentForPath(binding.path).key > path.key) {
+ this.attachAfter = true;
+ path = binding.path;
+
+ for (var _iterator = binding.constantViolations, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
+ var _ref;
+
+ if (_isArray) {
+ if (_i >= _iterator.length) break;
+ _ref = _iterator[_i++];
+ } else {
+ _i = _iterator.next();
+ if (_i.done) break;
+ _ref = _i.value;
+ }
+
+ var violationPath = _ref;
+
+ if (this.getAttachmentParentForPath(violationPath).key > path.key) {
+ path = violationPath;
+ }
+ }
+ }
}
}
@@ -118,6 +134,7 @@ var PathHoister = function () {
var scopes = this.scopes;
var scope = scopes.pop();
+
if (!scope) return;
if (scope.path.isFunction()) {
@@ -126,16 +143,22 @@ var PathHoister = function () {
return scope.path.get("body").get("body")[0];
} else {
- return this.getNextScopeStatementParent();
+ return this.getNextScopeAttachmentParent();
}
} else if (scope.path.isProgram()) {
- return this.getNextScopeStatementParent();
+ return this.getNextScopeAttachmentParent();
}
};
- PathHoister.prototype.getNextScopeStatementParent = function getNextScopeStatementParent() {
+ PathHoister.prototype.getNextScopeAttachmentParent = function getNextScopeAttachmentParent() {
var scope = this.scopes.pop();
- if (scope) return scope.path.getStatementParent();
+ if (scope) return this.getAttachmentParentForPath(scope.path);
+ };
+
+ PathHoister.prototype.getAttachmentParentForPath = function getAttachmentParentForPath(path) {
+ do {
+ if (!path.parentPath || Array.isArray(path.container) && path.isStatement() || path.isVariableDeclarator() && path.parentPath.node !== null && path.parentPath.node.declarations.length > 1) return path;
+ } while (path = path.parentPath);
};
PathHoister.prototype.hasOwnParamBindings = function hasOwnParamBindings(scope) {
@@ -143,7 +166,8 @@ var PathHoister = function () {
if (!scope.hasOwnBinding(name)) continue;
var binding = this.bindings[name];
- if (binding.kind === "param") return true;
+
+ if (binding.kind === "param" && binding.constant) return true;
}
return false;
};
@@ -163,7 +187,10 @@ var PathHoister = function () {
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
var uid = attachTo.scope.generateUidIdentifier("ref");
- attachTo.insertBefore([t.variableDeclaration("var", [t.variableDeclarator(uid, this.path.node)])]);
+ var declarator = t.variableDeclarator(uid, this.path.node);
+
+ var insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
+ attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t.variableDeclaration("var", [declarator])]);
var parent = this.path.parentPath;
if (parent.isJSXElement() && this.path.container === parent.node.children) {
diff --git a/node_modules/babel-traverse/lib/path/lib/removal-hooks.js b/node_modules/babel-traverse/lib/path/lib/removal-hooks.js
index 6838b74d4..6058ec1fb 100644
--- a/node_modules/babel-traverse/lib/path/lib/removal-hooks.js
+++ b/node_modules/babel-traverse/lib/path/lib/removal-hooks.js
@@ -2,22 +2,7 @@
exports.__esModule = true;
var hooks = exports.hooks = [function (self, parent) {
- if (self.key === "body" && parent.isArrowFunctionExpression()) {
- self.replaceWith(self.scope.buildUndefinedNode());
- return true;
- }
-}, function (self, parent) {
- var removeParent = false;
-
- removeParent = removeParent || self.key === "test" && (parent.isWhile() || parent.isSwitchCase());
-
- removeParent = removeParent || self.key === "declaration" && parent.isExportDeclaration();
-
- removeParent = removeParent || self.key === "body" && parent.isLabeledStatement();
-
- removeParent = removeParent || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1;
-
- removeParent = removeParent || self.key === "expression" && parent.isExpressionStatement();
+ var removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
if (removeParent) {
parent.remove();
@@ -38,9 +23,9 @@ var hooks = exports.hooks = [function (self, parent) {
return true;
}
}, function (self, parent) {
- if (parent.isIfStatement() && (self.key === 'consequent' || self.key === 'alternate') || parent.isLoop() && self.key === 'body') {
+ if (parent.isIfStatement() && (self.key === "consequent" || self.key === "alternate") || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
self.replaceWith({
- type: 'BlockStatement',
+ type: "BlockStatement",
body: []
});
return true;
diff --git a/node_modules/babel-traverse/lib/path/lib/virtual-types.js b/node_modules/babel-traverse/lib/path/lib/virtual-types.js
index 1cb61cc8c..80bb5b925 100644
--- a/node_modules/babel-traverse/lib/path/lib/virtual-types.js
+++ b/node_modules/babel-traverse/lib/path/lib/virtual-types.js
@@ -12,8 +12,8 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
var ReferencedIdentifier = exports.ReferencedIdentifier = {
types: ["Identifier", "JSXIdentifier"],
checkPath: function checkPath(_ref, opts) {
- var node = _ref.node;
- var parent = _ref.parent;
+ var node = _ref.node,
+ parent = _ref.parent;
if (!t.isIdentifier(node, opts) && !t.isJSXMemberExpression(parent, opts)) {
if (t.isJSXIdentifier(node, opts)) {
@@ -30,8 +30,8 @@ var ReferencedIdentifier = exports.ReferencedIdentifier = {
var ReferencedMemberExpression = exports.ReferencedMemberExpression = {
types: ["MemberExpression"],
checkPath: function checkPath(_ref2) {
- var node = _ref2.node;
- var parent = _ref2.parent;
+ var node = _ref2.node,
+ parent = _ref2.parent;
return t.isMemberExpression(node) && t.isReferenced(node, parent);
}
@@ -40,8 +40,8 @@ var ReferencedMemberExpression = exports.ReferencedMemberExpression = {
var BindingIdentifier = exports.BindingIdentifier = {
types: ["Identifier"],
checkPath: function checkPath(_ref3) {
- var node = _ref3.node;
- var parent = _ref3.parent;
+ var node = _ref3.node,
+ parent = _ref3.parent;
return t.isIdentifier(node) && t.isBinding(node, parent);
}
@@ -50,8 +50,8 @@ var BindingIdentifier = exports.BindingIdentifier = {
var Statement = exports.Statement = {
types: ["Statement"],
checkPath: function checkPath(_ref4) {
- var node = _ref4.node;
- var parent = _ref4.parent;
+ var node = _ref4.node,
+ parent = _ref4.parent;
if (t.isStatement(node)) {
if (t.isVariableDeclaration(node)) {
@@ -122,7 +122,7 @@ var Pure = exports.Pure = {
};
var Flow = exports.Flow = {
- types: ["Flow", "ImportDeclaration", "ExportDeclaration"],
+ types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"],
checkPath: function checkPath(_ref5) {
var node = _ref5.node;
@@ -132,6 +132,8 @@ var Flow = exports.Flow = {
return node.importKind === "type" || node.importKind === "typeof";
} else if (t.isExportDeclaration(node)) {
return node.exportKind === "type";
+ } else if (t.isImportSpecifier(node)) {
+ return node.importKind === "type" || node.importKind === "typeof";
} else {
return false;
}
diff --git a/node_modules/babel-traverse/lib/path/modification.js b/node_modules/babel-traverse/lib/path/modification.js
index a763f6d7b..30fb165b7 100644
--- a/node_modules/babel-traverse/lib/path/modification.js
+++ b/node_modules/babel-traverse/lib/path/modification.js
@@ -58,7 +58,7 @@ function insertBefore(nodes) {
if (this.node) nodes.push(this.node);
this._replaceWith(t.blockStatement(nodes));
} else {
- throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
+ throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
}
}
@@ -172,7 +172,7 @@ function insertAfter(nodes) {
if (this.node) nodes.unshift(this.node);
this._replaceWith(t.blockStatement(nodes));
} else {
- throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
+ throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
}
}
diff --git a/node_modules/babel-traverse/lib/path/replacement.js b/node_modules/babel-traverse/lib/path/replacement.js
index dc852334d..a60c73d54 100644
--- a/node_modules/babel-traverse/lib/path/replacement.js
+++ b/node_modules/babel-traverse/lib/path/replacement.js
@@ -230,10 +230,16 @@ function replaceExpressionWithStatements(nodes) {
return path.isLoop();
});
if (loop) {
- var callee = this.get("callee");
-
- var uid = callee.scope.generateDeclaredUidIdentifier("ret");
- callee.get("body").pushContainer("body", t.returnStatement(uid));
+ var uid = loop.getData("expressionReplacementReturnUid");
+
+ if (!uid) {
+ var callee = this.get("callee");
+ uid = callee.scope.generateDeclaredUidIdentifier("ret");
+ callee.get("body").pushContainer("body", t.returnStatement(uid));
+ loop.setData("expressionReplacementReturnUid", uid);
+ } else {
+ uid = t.identifier(uid.name);
+ }
path.get("expression").replaceWith(t.assignmentExpression("=", uid, path.node.expression));
} else {
diff --git a/node_modules/babel-traverse/lib/scope/binding.js b/node_modules/babel-traverse/lib/scope/binding.js
index b1acf1b10..0730cdfc0 100644
--- a/node_modules/babel-traverse/lib/scope/binding.js
+++ b/node_modules/babel-traverse/lib/scope/binding.js
@@ -10,11 +10,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
var Binding = function () {
function Binding(_ref) {
- var existing = _ref.existing;
- var identifier = _ref.identifier;
- var scope = _ref.scope;
- var path = _ref.path;
- var kind = _ref.kind;
+ var existing = _ref.existing,
+ identifier = _ref.identifier,
+ scope = _ref.scope,
+ path = _ref.path,
+ kind = _ref.kind;
(0, _classCallCheck3.default)(this, Binding);
this.identifier = identifier;
diff --git a/node_modules/babel-traverse/lib/scope/index.js b/node_modules/babel-traverse/lib/scope/index.js
index 36cfb3429..c960a7322 100644
--- a/node_modules/babel-traverse/lib/scope/index.js
+++ b/node_modules/babel-traverse/lib/scope/index.js
@@ -93,21 +93,76 @@ function getCache(path, parentScope, self) {
}
}
+function gatherNodeParts(node, parts) {
+ if (t.isModuleDeclaration(node)) {
+ if (node.source) {
+ gatherNodeParts(node.source, parts);
+ } else if (node.specifiers && node.specifiers.length) {
+ for (var _iterator2 = node.specifiers, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
+ var _ref2;
+
+ if (_isArray2) {
+ if (_i2 >= _iterator2.length) break;
+ _ref2 = _iterator2[_i2++];
+ } else {
+ _i2 = _iterator2.next();
+ if (_i2.done) break;
+ _ref2 = _i2.value;
+ }
+
+ var specifier = _ref2;
+
+ gatherNodeParts(specifier, parts);
+ }
+ } else if (node.declaration) {
+ gatherNodeParts(node.declaration, parts);
+ }
+ } else if (t.isModuleSpecifier(node)) {
+ gatherNodeParts(node.local, parts);
+ } else if (t.isMemberExpression(node)) {
+ gatherNodeParts(node.object, parts);
+ gatherNodeParts(node.property, parts);
+ } else if (t.isIdentifier(node)) {
+ parts.push(node.name);
+ } else if (t.isLiteral(node)) {
+ parts.push(node.value);
+ } else if (t.isCallExpression(node)) {
+ gatherNodeParts(node.callee, parts);
+ } else if (t.isObjectExpression(node) || t.isObjectPattern(node)) {
+ for (var _iterator3 = node.properties, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
+ var _ref3;
+
+ if (_isArray3) {
+ if (_i3 >= _iterator3.length) break;
+ _ref3 = _iterator3[_i3++];
+ } else {
+ _i3 = _iterator3.next();
+ if (_i3.done) break;
+ _ref3 = _i3.value;
+ }
+
+ var prop = _ref3;
+
+ gatherNodeParts(prop.key || prop.argument, parts);
+ }
+ }
+}
+
var collectorVisitor = {
For: function For(path) {
- for (var _iterator2 = t.FOR_INIT_KEYS, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
- var _ref2;
+ for (var _iterator4 = t.FOR_INIT_KEYS, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : (0, _getIterator3.default)(_iterator4);;) {
+ var _ref4;
- if (_isArray2) {
- if (_i2 >= _iterator2.length) break;
- _ref2 = _iterator2[_i2++];
+ if (_isArray4) {
+ if (_i4 >= _iterator4.length) break;
+ _ref4 = _iterator4[_i4++];
} else {
- _i2 = _iterator2.next();
- if (_i2.done) break;
- _ref2 = _i2.value;
+ _i4 = _iterator4.next();
+ if (_i4.done) break;
+ _ref4 = _i4.value;
}
- var key = _ref2;
+ var key = _ref4;
var declar = path.get(key);
if (declar.isVar()) path.scope.getFunctionParent().registerBinding("var", declar);
@@ -133,8 +188,8 @@ var collectorVisitor = {
ExportDeclaration: {
exit: function exit(path) {
- var node = path.node;
- var scope = path.scope;
+ var node = path.node,
+ scope = path.scope;
var declar = node.declaration;
if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) {
@@ -144,19 +199,19 @@ var collectorVisitor = {
var binding = scope.getBinding(_id.name);
if (binding) binding.reference(path);
} else if (t.isVariableDeclaration(declar)) {
- for (var _iterator3 = declar.declarations, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
- var _ref3;
+ for (var _iterator5 = declar.declarations, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : (0, _getIterator3.default)(_iterator5);;) {
+ var _ref5;
- if (_isArray3) {
- if (_i3 >= _iterator3.length) break;
- _ref3 = _iterator3[_i3++];
+ if (_isArray5) {
+ if (_i5 >= _iterator5.length) break;
+ _ref5 = _iterator5[_i5++];
} else {
- _i3 = _iterator3.next();
- if (_i3.done) break;
- _ref3 = _i3.value;
+ _i5 = _iterator5.next();
+ if (_i5.done) break;
+ _ref5 = _i5.value;
}
- var decl = _ref3;
+ var decl = _ref5;
var ids = t.getBindingIdentifiers(decl);
for (var name in ids) {
@@ -197,19 +252,19 @@ var collectorVisitor = {
},
Block: function Block(path) {
var paths = path.get("body");
- for (var _iterator4 = paths, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : (0, _getIterator3.default)(_iterator4);;) {
- var _ref4;
+ for (var _iterator6 = paths, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : (0, _getIterator3.default)(_iterator6);;) {
+ var _ref6;
- if (_isArray4) {
- if (_i4 >= _iterator4.length) break;
- _ref4 = _iterator4[_i4++];
+ if (_isArray6) {
+ if (_i6 >= _iterator6.length) break;
+ _ref6 = _iterator6[_i6++];
} else {
- _i4 = _iterator4.next();
- if (_i4.done) break;
- _ref4 = _i4.value;
+ _i6 = _iterator6.next();
+ if (_i6.done) break;
+ _ref6 = _i6.value;
}
- var bodyPath = _ref4;
+ var bodyPath = _ref6;
if (bodyPath.isFunctionDeclaration()) {
path.scope.getBlockParent().registerDeclaration(bodyPath);
@@ -297,63 +352,7 @@ var Scope = function () {
}
var parts = [];
-
- var add = function add(node) {
- if (t.isModuleDeclaration(node)) {
- if (node.source) {
- add(node.source);
- } else if (node.specifiers && node.specifiers.length) {
- for (var _iterator5 = node.specifiers, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : (0, _getIterator3.default)(_iterator5);;) {
- var _ref5;
-
- if (_isArray5) {
- if (_i5 >= _iterator5.length) break;
- _ref5 = _iterator5[_i5++];
- } else {
- _i5 = _iterator5.next();
- if (_i5.done) break;
- _ref5 = _i5.value;
- }
-
- var specifier = _ref5;
-
- add(specifier);
- }
- } else if (node.declaration) {
- add(node.declaration);
- }
- } else if (t.isModuleSpecifier(node)) {
- add(node.local);
- } else if (t.isMemberExpression(node)) {
- add(node.object);
- add(node.property);
- } else if (t.isIdentifier(node)) {
- parts.push(node.name);
- } else if (t.isLiteral(node)) {
- parts.push(node.value);
- } else if (t.isCallExpression(node)) {
- add(node.callee);
- } else if (t.isObjectExpression(node) || t.isObjectPattern(node)) {
- for (var _iterator6 = node.properties, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : (0, _getIterator3.default)(_iterator6);;) {
- var _ref6;
-
- if (_isArray6) {
- if (_i6 >= _iterator6.length) break;
- _ref6 = _iterator6[_i6++];
- } else {
- _i6 = _iterator6.next();
- if (_i6.done) break;
- _ref6 = _i6.value;
- }
-
- var prop = _ref6;
-
- add(prop.key || prop.argument);
- }
- }
- };
-
- add(node);
+ gatherNodeParts(node, parts);
var id = parts.join("$");
id = id.replace(/^_/, "") || defaultName || "ref";
@@ -393,11 +392,7 @@ var Scope = function () {
if (kind === "hoisted" && local.kind === "let") return;
- var duplicate = false;
-
- if (!duplicate) duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module";
-
- if (!duplicate) duplicate = local.kind === "param" && (kind === "let" || kind === "const");
+ var duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && (kind === "let" || kind === "const");
if (duplicate) {
throw this.hub.file.buildCodeFrameError(id, messages.get("scopeDuplicateDeclaration", name), TypeError);
diff --git a/node_modules/babel-traverse/lib/scope/lib/renamer.js b/node_modules/babel-traverse/lib/scope/lib/renamer.js
index b159e7754..a3b970515 100644
--- a/node_modules/babel-traverse/lib/scope/lib/renamer.js
+++ b/node_modules/babel-traverse/lib/scope/lib/renamer.js
@@ -108,11 +108,11 @@ var Renamer = function () {
};
Renamer.prototype.rename = function rename(block) {
- var binding = this.binding;
- var oldName = this.oldName;
- var newName = this.newName;
- var scope = binding.scope;
- var path = binding.path;
+ var binding = this.binding,
+ oldName = this.oldName,
+ newName = this.newName;
+ var scope = binding.scope,
+ path = binding.path;
var parentDeclar = path.find(function (path) {