unshiftContainer seems to incorrectly handle function params #6150 (#6354)

This commit is contained in:
Abhilash Singh 2017-09-30 18:44:51 +05:30 committed by Henry Zhu
parent 7c8a6cb461
commit 6230855b71
2 changed files with 16 additions and 1 deletions

View File

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

View File

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