Skip to content

Commit

Permalink
test: add sourcemap spec
Browse files Browse the repository at this point in the history
- Close #681
  • Loading branch information
Brooooooklyn committed Feb 11, 2023
1 parent 8d6b0b7 commit 9802700
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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)`
Binary file not shown.
24 changes: 24 additions & 0 deletions packages/integrate/__tests__/sourcemaps/sourcemaps.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
})
20 changes: 0 additions & 20 deletions packages/register/__test__/create-sourcemap-option.spec.ts

This file was deleted.

14 changes: 3 additions & 11 deletions packages/register/read-default-tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 9802700

Please sign in to comment.