diff --git a/packages/cli/src/swc/compile.ts b/packages/cli/src/swc/compile.ts index cb8d93c..7b162c8 100644 --- a/packages/cli/src/swc/compile.ts +++ b/packages/cli/src/swc/compile.ts @@ -12,9 +12,28 @@ function withSourceMap( destFile: string, destDir: string ) { + let dts: string | undefined; + + // TODO: Remove once fixed in core + if ((output as any).output) { + const json = JSON.parse((output as any).output); + + if (json.__swc_isolated_declarations__) { + dts = json.__swc_isolated_declarations__; + } + } + + let dtsPath: string | undefined; + + if (dts) { + dtsPath = join(destDir, basename(destFile) + ".d.ts"); + } + if (!output.map || options.sourceMaps === "inline") { return { sourceCode: output.code, + dts, + dtsPath, }; } // TODO: remove once fixed in core https://github.com/swc-project/swc/issues/1388 @@ -32,23 +51,6 @@ function withSourceMap( relative(destDir, sourceMapPath) )}`; - let dts: string | undefined; - - // TODO: Remove once fixed in core - if ((output as any).output) { - const json = JSON.parse((output as any).output); - - if (json.__swc_isolated_declarations__) { - dts = json.__swc_isolated_declarations__; - } - } - - let dtsPath: string | undefined; - - if (dts) { - dtsPath = join(destDir, basename(destFile) + ".d.ts"); - } - return { sourceMap: output.map, sourceMapPath,