test/dummy/node_modules/@babel/traverse/lib/path/index.js in disco_app-0.18.1 vs test/dummy/node_modules/@babel/traverse/lib/path/index.js in disco_app-0.18.2
- old
+ new
@@ -1,81 +1,79 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
-exports.default = exports.SHOULD_SKIP = exports.SHOULD_STOP = exports.REMOVED = void 0;
+exports.default = void 0;
-var virtualTypes = require("./lib/virtual-types");
+var virtualTypes = _interopRequireWildcard(require("./lib/virtual-types"));
-var _debug = require("debug");
+var _debug = _interopRequireDefault(require("debug"));
-var _index = require("../index");
+var _index = _interopRequireDefault(require("../index"));
-var _scope = require("../scope");
+var _scope = _interopRequireDefault(require("../scope"));
-var _t = require("@babel/types");
+var t = _interopRequireWildcard(require("@babel/types"));
-var t = _t;
-
var _cache = require("../cache");
-var _generator = require("@babel/generator");
+var _generator = _interopRequireDefault(require("@babel/generator"));
-var NodePath_ancestry = require("./ancestry");
+var NodePath_ancestry = _interopRequireWildcard(require("./ancestry"));
-var NodePath_inference = require("./inference");
+var NodePath_inference = _interopRequireWildcard(require("./inference"));
-var NodePath_replacement = require("./replacement");
+var NodePath_replacement = _interopRequireWildcard(require("./replacement"));
-var NodePath_evaluation = require("./evaluation");
+var NodePath_evaluation = _interopRequireWildcard(require("./evaluation"));
-var NodePath_conversion = require("./conversion");
+var NodePath_conversion = _interopRequireWildcard(require("./conversion"));
-var NodePath_introspection = require("./introspection");
+var NodePath_introspection = _interopRequireWildcard(require("./introspection"));
-var NodePath_context = require("./context");
+var NodePath_context = _interopRequireWildcard(require("./context"));
-var NodePath_removal = require("./removal");
+var NodePath_removal = _interopRequireWildcard(require("./removal"));
-var NodePath_modification = require("./modification");
+var NodePath_modification = _interopRequireWildcard(require("./modification"));
-var NodePath_family = require("./family");
+var NodePath_family = _interopRequireWildcard(require("./family"));
-var NodePath_comments = require("./comments");
+var NodePath_comments = _interopRequireWildcard(require("./comments"));
-const {
- validate
-} = _t;
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-const debug = _debug("babel");
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
-const REMOVED = 1 << 0;
-exports.REMOVED = REMOVED;
-const SHOULD_STOP = 1 << 1;
-exports.SHOULD_STOP = SHOULD_STOP;
-const SHOULD_SKIP = 1 << 2;
-exports.SHOULD_SKIP = SHOULD_SKIP;
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+const debug = (0, _debug.default)("babel");
+
class NodePath {
constructor(hub, parent) {
+ this.parent = parent;
+ this.hub = hub;
this.contexts = [];
+ this.data = Object.create(null);
+ this.shouldSkip = false;
+ this.shouldStop = false;
+ this.removed = false;
this.state = null;
this.opts = null;
- this._traverseFlags = 0;
this.skipKeys = null;
this.parentPath = null;
+ this.context = null;
this.container = null;
this.listKey = null;
+ this.inList = false;
+ this.parentKey = null;
this.key = null;
this.node = null;
- this.type = null;
- this.parent = parent;
- this.hub = hub;
- this.data = null;
- this.context = null;
this.scope = null;
+ this.type = null;
+ this.typeAnnotation = null;
}
static get({
hub,
parentPath,
@@ -91,24 +89,30 @@
if (!parent) {
throw new Error("To get a node path the parent needs to exist");
}
const targetNode = container[key];
+ const paths = _cache.path.get(parent) || [];
- let paths = _cache.path.get(parent);
-
- if (!paths) {
- paths = new Map();
-
+ if (!_cache.path.has(parent)) {
_cache.path.set(parent, paths);
}
- let path = paths.get(targetNode);
+ let path;
+ for (let i = 0; i < paths.length; i++) {
+ const pathCheck = paths[i];
+
+ if (pathCheck.node === targetNode) {
+ path = pathCheck;
+ break;
+ }
+ }
+
if (!path) {
path = new NodePath(hub, parent);
- if (targetNode) paths.set(targetNode, path);
+ paths.push(path);
}
path.setup(parentPath, container, listKey, key);
return path;
}
@@ -116,22 +120,14 @@
getScope(scope) {
return this.isScope() ? new _scope.default(this) : scope;
}
setData(key, val) {
- if (this.data == null) {
- this.data = Object.create(null);
- }
-
return this.data[key] = val;
}
getData(key, def) {
- if (this.data == null) {
- this.data = Object.create(null);
- }
-
let val = this.data[key];
if (val === undefined && def !== undefined) val = this.data[key] = def;
return val;
}
@@ -142,11 +138,11 @@
traverse(visitor, state) {
(0, _index.default)(this.node, visitor, this.scope, state, this);
}
set(key, node) {
- validate(this.node, key, node);
+ t.validate(this.node, key, node);
this.node[key] = node;
}
getPathLocation() {
const parts = [];
@@ -168,62 +164,13 @@
toString() {
return (0, _generator.default)(this.node).code;
}
- get inList() {
- return !!this.listKey;
- }
-
- set inList(inList) {
- if (!inList) {
- this.listKey = null;
- }
- }
-
- get parentKey() {
- return this.listKey || this.key;
- }
-
- get shouldSkip() {
- return !!(this._traverseFlags & SHOULD_SKIP);
- }
-
- set shouldSkip(v) {
- if (v) {
- this._traverseFlags |= SHOULD_SKIP;
- } else {
- this._traverseFlags &= ~SHOULD_SKIP;
- }
- }
-
- get shouldStop() {
- return !!(this._traverseFlags & SHOULD_STOP);
- }
-
- set shouldStop(v) {
- if (v) {
- this._traverseFlags |= SHOULD_STOP;
- } else {
- this._traverseFlags &= ~SHOULD_STOP;
- }
- }
-
- get removed() {
- return !!(this._traverseFlags & REMOVED);
- }
-
- set removed(v) {
- if (v) {
- this._traverseFlags |= REMOVED;
- } else {
- this._traverseFlags &= ~REMOVED;
- }
- }
-
}
+exports.default = NodePath;
Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
for (const type of t.TYPES) {
const typeKey = `is${type}`;
const fn = t[typeKey];
@@ -245,9 +192,6 @@
const virtualType = virtualTypes[type];
NodePath.prototype[`is${type}`] = function (opts) {
return virtualType.checkPath(this, opts);
};
-}
-
-var _default = NodePath;
-exports.default = _default;
+}
\ No newline at end of file