avoid trying to replace a node with itself, antipattern!

This commit is contained in:
Sebastian McKenzie
2015-05-04 22:19:37 +01:00
parent 01e5354fd9
commit 2c0c2f12df
7 changed files with 9 additions and 9 deletions

View File

@@ -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;
}

View File

@@ -8,6 +8,4 @@ export function ArrowFunctionExpression(node) {
node.expression = false;
node.type = "FunctionExpression";
node.shadow = true;
return node;
}

View File

@@ -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) {

View File

@@ -97,5 +97,5 @@ exports.Function = function (node, parent, scope, file) {
node.body.body = body.concat(node.body.body);
}
return node;
this.checkSelf();
};

View File

@@ -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();
};

View File

@@ -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