diff options
Diffstat (limited to 'node_modules/babel-traverse/lib/path')
12 files changed, 224 insertions, 101 deletions
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 { |