aboutsummaryrefslogtreecommitdiff
path: root/node_modules/babel-traverse/lib/path/family.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-04-20 03:09:25 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-04-24 16:14:29 +0200
commit82f2b76e25a4a67e01ec67e5ebe39d14ad771ea8 (patch)
tree965f6eb89b84d65a62b49008fd972c004832ccd1 /node_modules/babel-traverse/lib/path/family.js
parente6e0cbc387c2a77b48e4065c229daa65bf1aa0fa (diff)
Reorganize module loading.
We now use webpack instead of SystemJS, effectively bundling modules into one file (plus commons chunks) for every entry point. This results in a much smaller extension size (almost half). Furthermore we use yarn/npm even for extension run-time dependencies. This relieves us from manually vendoring and building dependencies. It's also easier to understand for new developers familiar with node.
Diffstat (limited to 'node_modules/babel-traverse/lib/path/family.js')
-rw-r--r--node_modules/babel-traverse/lib/path/family.js101
1 files changed, 101 insertions, 0 deletions
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