Skip to content

Commit

Permalink
Fix dce: don't remove fn param from setters (close #267) (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangax authored Nov 14, 2016
2 parents bd10724 + 2ec0e2f commit be82668
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2209,4 +2209,20 @@ describe("dce-plugin", () => {
`);
expect(transform(source)).toBe(expected);
});
it("should NOT remove fn params for setters", () => {
const source = unpad(`
function foo() {
var x = {
set a(b) {}
};
class A {
set c(d) {
x.a = 5;
}
}
return new A();
}
`);
expect(transform(source)).toBe(source);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ module.exports = ({ types: t, traverse }) => {

// if the scope is created by a function, we obtain its
// parameter list
const paramsList = path.isFunction() ? path.get("params") : [];
const canRemoveParams = path.isFunction() && path.node.kind !== "set";
const paramsList = canRemoveParams ? path.get("params") : [];

for (let i = paramsList.length - 1; i >= 0; i--) {
const param = paramsList[i];
Expand Down

0 comments on commit be82668

Please sign in to comment.