avoid trying to replace a node with itself, antipattern!
This commit is contained in:
@@ -8,7 +8,8 @@ import * as t from "../../types";
|
||||
var remapVisitor = {
|
||||
enter(node, parent, scope, formatter) {
|
||||
var remap = formatter.internalRemap[node.name];
|
||||
if (this.isReferencedIdentifier() && remap) {
|
||||
|
||||
if (this.isReferencedIdentifier() && remap && node !== remap) {
|
||||
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
|
||||
return remap;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,4 @@ export function ArrowFunctionExpression(node) {
|
||||
node.expression = false;
|
||||
node.type = "FunctionExpression";
|
||||
node.shadow = true;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ exports.Function = function (node, parent, scope, file) {
|
||||
|
||||
var block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
return node;
|
||||
this.checkSelf();
|
||||
};
|
||||
|
||||
export function CatchClause(node, parent, scope, file) {
|
||||
|
||||
@@ -97,5 +97,5 @@ exports.Function = function (node, parent, scope, file) {
|
||||
node.body.body = body.concat(node.body.body);
|
||||
}
|
||||
|
||||
return node;
|
||||
this.checkSelf();
|
||||
};
|
||||
|
||||
@@ -96,7 +96,8 @@ exports.Function = function (node, parent, scope, file) {
|
||||
candidate.replaceWith(argsId);
|
||||
optimizeMemberExpression(candidate.parent, node.params.length);
|
||||
}
|
||||
return node;
|
||||
this.checkSelf();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -137,5 +138,5 @@ exports.Function = function (node, parent, scope, file) {
|
||||
});
|
||||
loop._blockHoist = node.params.length + 1;
|
||||
node.body.body.unshift(loop);
|
||||
return node;
|
||||
this.checkSelf();
|
||||
};
|
||||
|
||||
@@ -510,7 +510,7 @@ export default class TraversalPath {
|
||||
}
|
||||
|
||||
if (this.node === replacement) {
|
||||
throw new Error("You're trying to replace a node with itself which isn't allowed. If you're trying to do a transformer recache then use `this.checkSelf()`");
|
||||
throw new Error("You're trying to replace a node with itself which doesn't make any sense. If you're trying to do a transformer recache then use `this.checkSelf()`");
|
||||
}
|
||||
|
||||
// normalise inserting an entire AST
|
||||
|
||||
Reference in New Issue
Block a user