diff --git a/packages/integrate/__tests__/sourcemaps/__snapshots__/sourcemaps.spec.ts.md b/packages/integrate/__tests__/sourcemaps/__snapshots__/sourcemaps.spec.ts.md new file mode 100644 index 000000000..0c8e78857 --- /dev/null +++ b/packages/integrate/__tests__/sourcemaps/__snapshots__/sourcemaps.spec.ts.md @@ -0,0 +1,20 @@ +# Snapshot report for `packages/integrate/__tests__/sourcemaps/sourcemaps.spec.ts` + +The actual snapshot is saved in `sourcemaps.spec.ts.snap`. + +Generated by [AVA](https://avajs.dev). + +## should work with sourcemaps + +> Snapshot 1 + + `Error: ␊ + at /Users/longyinan/workspace/github/swc-node/packages/integrate/__tests__/sourcemaps/sourcemaps.spec.ts:23:14␊ + at Test.callFn (file:///Users/longyinan/workspace/github/swc-node/node_modules/.pnpm/ava@5.2.0/node_modules/ava/lib/test.js:507:21)␊ + at Test.run (file:///Users/longyinan/workspace/github/swc-node/node_modules/.pnpm/ava@5.2.0/node_modules/ava/lib/test.js:520:23)␊ + at Runner.runSingle (file:///Users/longyinan/workspace/github/swc-node/node_modules/.pnpm/ava@5.2.0/node_modules/ava/lib/runner.js:285:33)␊ + at Runner.runTest (file:///Users/longyinan/workspace/github/swc-node/node_modules/.pnpm/ava@5.2.0/node_modules/ava/lib/runner.js:367:30)␊ + at processTicksAndRejections (node:internal/process/task_queues:96:5)␊ + at async Promise.all (index 0)␊ + at file:///Users/longyinan/workspace/github/swc-node/node_modules/.pnpm/ava@5.2.0/node_modules/ava/lib/runner.js:532:21␊ + at Runner.start (file:///Users/longyinan/workspace/github/swc-node/node_modules/.pnpm/ava@5.2.0/node_modules/ava/lib/runner.js:540:15)` diff --git a/packages/integrate/__tests__/sourcemaps/__snapshots__/sourcemaps.spec.ts.snap b/packages/integrate/__tests__/sourcemaps/__snapshots__/sourcemaps.spec.ts.snap new file mode 100644 index 000000000..92577b2e3 Binary files /dev/null and b/packages/integrate/__tests__/sourcemaps/__snapshots__/sourcemaps.spec.ts.snap differ diff --git a/packages/integrate/__tests__/sourcemaps/sourcemaps.spec.ts b/packages/integrate/__tests__/sourcemaps/sourcemaps.spec.ts new file mode 100644 index 000000000..1e9c4781e --- /dev/null +++ b/packages/integrate/__tests__/sourcemaps/sourcemaps.spec.ts @@ -0,0 +1,24 @@ +import test from 'ava' + +// @ts-expect-error +interface _Unused1 {} +// @ts-expect-error +interface _Unused2 {} +// @ts-expect-error +interface _Unused3 {} +// @ts-expect-error +interface _Unused4 {} +// @ts-expect-error +interface _Unused5 {} +// @ts-expect-error +interface _Unused6 {} +// @ts-expect-error +interface _Unused7 {} +// @ts-expect-error +interface _Unused8 {} +// @ts-expect-error +interface _Unused9 {} + +test('should work with sourcemaps', (t) => { + t.snapshot(new Error().stack) +}) diff --git a/packages/register/__test__/create-sourcemap-option.spec.ts b/packages/register/__test__/create-sourcemap-option.spec.ts deleted file mode 100644 index f9ff8fd5d..000000000 --- a/packages/register/__test__/create-sourcemap-option.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Config } from '@swc/core' -import test from 'ava' -import { CompilerOptions } from 'typescript' - -import { createSourcemapOption } from '../read-default-tsconfig' - -const FIXTURES: [CompilerOptions, Config['sourceMaps']][] = [ - [{ sourceMap: true, inlineSourceMap: true }, 'inline'], - [{ sourceMap: false, inlineSourceMap: true }, 'inline'], - [{ sourceMap: true, inlineSourceMap: false }, true], - [{ sourceMap: false, inlineSourceMap: false }, false], - [{ inlineSourceMap: true }, 'inline'], - [{ inlineSourceMap: false }, true], -] - -for (const [config, expect] of FIXTURES) { - test(`should create ${expect} from ${JSON.stringify(config)}`, (t) => { - t.is(createSourcemapOption(config), expect!) - }) -} diff --git a/packages/register/read-default-tsconfig.ts b/packages/register/read-default-tsconfig.ts index 9a6fdae39..9023314e5 100644 --- a/packages/register/read-default-tsconfig.ts +++ b/packages/register/read-default-tsconfig.ts @@ -97,26 +97,18 @@ function toModule(moduleKind: ts.ModuleKind) { } } -export function createSourcemapOption(options: ts.CompilerOptions) { - return options.sourceMap !== false - ? options.inlineSourceMap - ? 'inline' - : true - : options.inlineSourceMap - ? 'inline' - : false -} - export function tsCompilerOptionsToSwcConfig(options: ts.CompilerOptions, filename: string): Options { const isJsx = filename.endsWith('.tsx') || filename.endsWith('.jsx') || Boolean(options.jsx) return { module: toModule(options.module ?? ts.ModuleKind.ES2015), - sourcemap: createSourcemapOption(options), + sourcemap: Boolean(options.sourceMap), experimentalDecorators: options.experimentalDecorators ?? false, emitDecoratorMetadata: options.emitDecoratorMetadata ?? false, esModuleInterop: options.esModuleInterop ?? false, swc: { filename, + inputSourceMap: options.inlineSourceMap, + sourceRoot: options.sourceRoot, jsc: { externalHelpers: Boolean(options.importHelpers), parser: {