diff --git a/src/internal.ts b/src/internal.ts index c866253e8..ba1334864 100644 --- a/src/internal.ts +++ b/src/internal.ts @@ -8,14 +8,20 @@ import swc from "../lib/wasm.js"; const DEFAULT_OPTIONS = { mode: "strip-only", deprecatedTsModuleAsError: true, - // default transform will only work when mode is "transform" +} satisfies Options; + +// swc only reads `transform` in "transform" mode, so these defaults are kept +// out of strip-only calls to avoid deserializing them on every call. +const DEFAULT_TRANSFORM_OPTIONS = { + mode: "transform", + deprecatedTsModuleAsError: true, transform: { verbatimModuleSyntax: true, nativeClassProperties: true, noEmptyExport: true, importNotUsedAsValues: "preserve", }, -} as Options; +} satisfies Options; export function transformSync( source: string, @@ -23,10 +29,9 @@ export function transformSync( ): TransformOutput { // Ensure that the source code is a string const input = `${source ?? ""}`; - return swc.transformSync(input, { - ...DEFAULT_OPTIONS, - ...options, - }); + const defaults = + options?.mode === "transform" ? DEFAULT_TRANSFORM_OPTIONS : DEFAULT_OPTIONS; + return swc.transformSync(input, { ...defaults, ...options }); } export function transformModuleSyntax(