This commit is contained in:
parent
7c8a6cb461
commit
6230855b71
@ -20,7 +20,9 @@ export function insertBefore(nodes) {
|
||||
) {
|
||||
return this.parentPath.insertBefore(nodes);
|
||||
} else if (
|
||||
(this.isNodeType("Expression") && this.listKey !== "params") ||
|
||||
(this.isNodeType("Expression") &&
|
||||
this.listKey !== "params" &&
|
||||
this.listKey !== "arguments") ||
|
||||
(this.parentPath.isForStatement() && this.key === "init")
|
||||
) {
|
||||
if (this.node) nodes.push(this.node);
|
||||
|
||||
@ -53,6 +53,19 @@ describe("modification", function() {
|
||||
|
||||
assert.equal(generateCode(rootPath), "function test(a) {\n b;\n}");
|
||||
});
|
||||
|
||||
it("properly handles more than one arguments", function() {
|
||||
const code = "foo(a, b);";
|
||||
const ast = parse(code);
|
||||
traverse(ast, {
|
||||
CallExpression: function(path) {
|
||||
path.unshiftContainer("arguments", t.identifier("d"));
|
||||
assert.equal(generateCode(path), "foo(d, a, b);");
|
||||
path.unshiftContainer("arguments", t.stringLiteral("s"));
|
||||
assert.equal(generateCode(path), `foo("s", d, a, b);`);
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("insertBefore", function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user