Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,30 @@ 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,
options?: Options,
): 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(
Expand Down
Loading