test/dummy/node_modules/@babel/traverse/lib/path/modification.js in disco_app-0.18.0 vs test/dummy/node_modules/@babel/traverse/lib/path/modification.js in disco_app-0.18.1
- old
+ new
@@ -14,26 +14,32 @@
exports.pushContainer = pushContainer;
exports.hoist = hoist;
var _cache = require("../cache");
-var _hoister = _interopRequireDefault(require("./lib/hoister"));
+var _hoister = require("./lib/hoister");
-var _index = _interopRequireDefault(require("./index"));
+var _index = require("./index");
-var t = _interopRequireWildcard(require("@babel/types"));
+var _t = require("@babel/types");
-function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
+const {
+ arrowFunctionExpression,
+ assertExpression,
+ assignmentExpression,
+ blockStatement,
+ callExpression,
+ cloneNode,
+ expressionStatement,
+ isExpression
+} = _t;
-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; }
-
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
-function insertBefore(nodes) {
+function insertBefore(nodes_) {
this._assertUnremoved();
- nodes = this._verifyNodeList(nodes);
+ const nodes = this._verifyNodeList(nodes_);
+
const {
parentPath
} = this;
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
@@ -42,12 +48,13 @@
if (this.node) nodes.push(this.node);
return this.replaceExpressionWithStatements(nodes);
} else if (Array.isArray(this.container)) {
return this._containerInsertBefore(nodes);
} else if (this.isStatementOrBlock()) {
- const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null);
- this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : []));
+ const node = this.node;
+ const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
+ this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
return this.unshiftContainer("body", 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?");
}
}
@@ -87,46 +94,56 @@
function _containerInsertAfter(nodes) {
return this._containerInsert(this.key + 1, nodes);
}
-function insertAfter(nodes) {
+function insertAfter(nodes_) {
this._assertUnremoved();
- nodes = this._verifyNodeList(nodes);
+ const nodes = this._verifyNodeList(nodes_);
+
const {
parentPath
} = this;
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
return parentPath.insertAfter(nodes.map(node => {
- return t.isExpression(node) ? t.expressionStatement(node) : node;
+ return isExpression(node) ? expressionStatement(node) : node;
}));
- } else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
+ } else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
if (this.node) {
+ const node = this.node;
let {
scope
} = this;
+ if (scope.path.isPattern()) {
+ assertExpression(node);
+ this.replaceWith(callExpression(arrowFunctionExpression([], node), []));
+ this.get("callee.body").insertAfter(nodes);
+ return [this];
+ }
+
if (parentPath.isMethod({
computed: true,
- key: this.node
+ key: node
})) {
scope = scope.parent;
}
const temp = scope.generateDeclaredUidIdentifier();
- nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), this.node)));
- nodes.push(t.expressionStatement(t.cloneNode(temp)));
+ nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
+ nodes.push(expressionStatement(cloneNode(temp)));
}
return this.replaceExpressionWithStatements(nodes);
} else if (Array.isArray(this.container)) {
return this._containerInsertAfter(nodes);
} else if (this.isStatementOrBlock()) {
- const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null);
- this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : []));
+ const node = this.node;
+ const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
+ this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
return this.pushContainer("body", 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?");
}
}
@@ -134,13 +151,11 @@
function updateSiblingKeys(fromIndex, incrementBy) {
if (!this.parent) return;
const paths = _cache.path.get(this.parent);
- for (let i = 0; i < paths.length; i++) {
- const path = paths[i];
-
+ for (const [, path] of paths) {
if (path.key >= fromIndex) {
path.key += incrementBy;
}
}
}
@@ -148,11 +163,11 @@
function _verifyNodeList(nodes) {
if (!nodes) {
return [];
}
- if (nodes.constructor !== Array) {
+ if (!Array.isArray(nodes)) {
nodes = [nodes];
}
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
@@ -186,29 +201,30 @@
parentPath: this,
parent: this.node,
container: this.node[listKey],
listKey,
key: 0
- });
+ }).setContext(this.context);
return path._containerInsertBefore(nodes);
}
function pushContainer(listKey, nodes) {
this._assertUnremoved();
- nodes = this._verifyNodeList(nodes);
+ const verifiedNodes = this._verifyNodeList(nodes);
+
const container = this.node[listKey];
const path = _index.default.get({
parentPath: this,
parent: this.node,
container: container,
listKey,
key: container.length
- });
+ }).setContext(this.context);
- return path.replaceWithMultiple(nodes);
+ return path.replaceWithMultiple(verifiedNodes);
}
function hoist(scope = this.scope) {
const hoister = new _hoister.default(this, scope);
return hoister.run();
\ No newline at end of file