Skip to content

Commit

Permalink
Only remove type imports
Browse files Browse the repository at this point in the history
ember-cli uses `babel-remove-types` to remove types from .gts files and if some of the imported references are only used in the `<template>` context, babel assumes they are unused and removes them.

By enabling the `onlyRemoveTypeImports` option of `@babel/plugin-transform-typescript` those imports are now no longer stripped.

Co-Authored-By: Bert De Block <[email protected]>
  • Loading branch information
Windvis and bertdeblock committed Jan 29, 2025
1 parent 532e210 commit fdf4822
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { format, Options as PrettierOptions } from 'prettier';

// @ts-expect-error We're only importing so we can create a config item, so we don't care about types
import bts from '@babel/plugin-transform-typescript';
const babelTsTransform = createConfigItem(bts);
const babelTsTransform = createConfigItem([bts, { onlyRemoveTypeImports: true }]);

// @ts-expect-error We're only importing so we can create a config item, so we don't care about types
import bsd from '@babel/plugin-syntax-decorators';
Expand Down
13 changes: 13 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ export default class Foo extends Component {
this.prop2 = prop2;
}
}
`;
expect(await removeTypes(contents)).toEqual(expected);
});

it("doesn't remove unused imports", async () => {
const contents = `import Foo from 'foo';
export default class Baz {}
`;

const expected = `import Foo from 'foo';
export default class Baz {}
`;
expect(await removeTypes(contents)).toEqual(expected);
});
Expand Down

0 comments on commit fdf4822

Please sign in to comment.