Skip to content

Commit 7888ac5

Browse files
author
Daniel Del Core
committed
remove unused var test
1 parent c1b2425 commit 7888ac5

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

community/javascript/src/remove-unused-vars/transform.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ console.log(y);
1818
`);
1919
});
2020

21+
it('should remove unused variables in function declaration', async () => {
22+
const result = await applyTransform(
23+
transformer,
24+
`export function hello() { var a = 1; debugger; }`,
25+
);
26+
27+
expect(result).toMatchInlineSnapshot(`
28+
"export function hello() {
29+
debugger;
30+
}"
31+
`);
32+
});
33+
2134
it('should not remove used variables', async () => {
2235
const result = await applyTransform(
2336
transformer,

scripts/cli-integration-test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ function main() {
2727

2828
{
2929
const targetFilePath = path.join(__dirname, 'remove-unused-vars-test2.ts');
30-
writeFileSync(targetFilePath, `function hello() { var a = 1; debugger; }`);
30+
writeFileSync(
31+
targetFilePath,
32+
`export function hello() { var a = 1; debugger; }`,
33+
);
3134

3235
execSync(
3336
`npx --yes @hypermod/cli@latest --packages javascript#remove-unused-vars --experimental-loader ${targetFilePath}`,
3437
{ stdio: 'inherit' },
3538
);
3639

3740
const targetFileOutput = readFileSync(targetFilePath, 'utf-8');
38-
const expectedFileOutput = `function hello() { debugger; }`;
41+
const expectedFileOutput = `export function hello() {
42+
debugger;
43+
}`;
3944

4045
if (targetFileOutput !== expectedFileOutput) {
4146
throw new Error(

0 commit comments

Comments
 (0)