Skip to content

Commit

Permalink
fix(transform): remove constant violations with their bindings (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber authored Jan 8, 2024
1 parent 72d1aae commit 769653f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-zoos-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@wyw-in-js/transform': patch
---

Sometimes, usages of variables survive the shaker even when their bindings are removed. Fixed.
13 changes: 13 additions & 0 deletions packages/transform/src/__tests__/__snapshots__/shaker.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ exports.__wywPreval = {
_exp: _exp
};"
`;

exports[`shaker should remove enum 1`] = `
""use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.__wywPreval = void 0;
const _exp2 = /*#__PURE__*/() => "t2nn9pk";
const __wywPreval = exports.__wywPreval = {
_exp2: _exp2
};"
`;
18 changes: 18 additions & 0 deletions packages/transform/src/__tests__/shaker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,22 @@ describe('shaker', () => {

expect(code).toMatchSnapshot();
});

it('should remove enum', () => {
const code = run(['__wywPreval'])`
"use strict";
var PanelKinds;
(function (PanelKinds) {
PanelKinds["DEFAULT"] = "default";
PanelKinds["TRANSPARENT"] = "transparent";
})(PanelKinds = exports.PanelKinds || (exports.PanelKinds = {}));
const _exp2 = /*#__PURE__*/() => "t2nn9pk";
export const __wywPreval = {
_exp2: _exp2,
};
`;

expect(code).toMatchSnapshot();
});
});
1 change: 1 addition & 0 deletions packages/transform/src/plugins/shaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ export default function shakerPlugin(
binding.path.isVariableDeclarator() &&
!forDeleting.includes(binding.path.get('id'))
) {
forDeleting.push(...binding.constantViolations);
forDeleting.push(binding.path.get('id'));
changed = true;
}
Expand Down

0 comments on commit 769653f

Please sign in to comment.