From 33b4c0daab297883cb300f2d8a4b33315cbf2cd2 Mon Sep 17 00:00:00 2001 From: Stephan Schreiber Date: Tue, 7 May 2024 00:50:03 +0200 Subject: [PATCH] feat: Disable Sucrase's keepUnusedImports setting --- .github/README.md | 7 ++++++- source/cjs-transform.cts | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/README.md b/.github/README.md index 0e6e4d6..4ac9999 100644 --- a/.github/README.md +++ b/.github/README.md @@ -88,7 +88,12 @@ Use the `.ts`, `.mts` or `.cts` extensions when importing modules. They are mand import { something } from './utilities.ts' ``` -Contrary to the TypeScript compiler or other tools like `ts-node`, `tsx` or `tsimp`, `ts-run` will not try and find a corresponding `.ts` file if you use a `.js` specifier. +Contrary to the TypeScript compiler or other tools like `ts-node`, `tsx` or `tsimp`, `ts-run` will *not* try and find a corresponding `.ts` file if you use a `.js` specifier. See the [authoring section](#authoring-your-scripts) for details on how to enable .ts extension imports. + +### Type-only imports and exports +It is generally better to be explicit about type-only imports and exports by using TypeScript's `import type ...`, `import { type ...}` and `export type ...` syntax. + +>New in 1.2.3:
However, because not everyone is willing to type the extra characters, `ts-run` will now automatically remove type-only imports and exports. (see [Sucrase documentation](https://github.com/alangpierce/sucrase#transforms) for more info). ### ESM vs CommonJS `ts-run`'s sole role is to transpile TypeScript code to JavaScript code, no more, no less. It does not try to convert scripts from CommonJS to ESM or vice-versa, it does not try to optimize or minify your code and it does not downlevel nor polyfill JavaScript. diff --git a/source/cjs-transform.cts b/source/cjs-transform.cts index 590373a..140e88c 100644 --- a/source/cjs-transform.cts +++ b/source/cjs-transform.cts @@ -12,7 +12,6 @@ export function transform(source: string, format: NodeJS.ModuleType, filePath: s preserveDynamicImport: true, disableESTransforms: true, injectCreateRequireForImportRequire: true, - keepUnusedImports: true, sourceMapOptions: { compiledFilename: filePath }