Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace source-map with trace-mapping #3236

Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
"magic-string": "^0.30.0",
"pathe": "^1.1.0",
"picocolors": "^1.0.0",
"source-map": "^0.6.1",
"std-env": "^3.3.2",
"strip-literal": "^1.0.1",
"tinybench": "^2.4.0",
Expand All @@ -165,6 +164,7 @@
"@ampproject/remapping": "^2.2.0",
"@antfu/install-pkg": "^0.1.1",
"@edge-runtime/vm": "2.1.2",
"@jridgewell/trace-mapping": "^0.3.17",
"@sinonjs/fake-timers": "^10.0.2",
"@types/diff": "^5.0.3",
"@types/istanbul-lib-coverage": "^2.0.4",
Expand Down
17 changes: 10 additions & 7 deletions packages/vitest/src/typecheck/typechecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { rm } from 'node:fs/promises'
import type { ExecaChildProcess } from 'execa'
import { execa } from 'execa'
import { basename, extname, resolve } from 'pathe'
import { SourceMapConsumer } from 'source-map'
import { TraceMap, generatedPositionFor } from '@jridgewell/trace-mapping'
import type { RawSourceMap } from '@ampproject/remapping'
import { getTasks } from '../utils'
import { ensurePackageInstalled } from '../node/pkg'
import type { Awaitable, File, ParsedStack, Task, TaskResultPack, TaskState, TscErrorInfo } from '../types'
Expand Down Expand Up @@ -119,7 +120,7 @@ export class Typechecker {
}
const sortedDefinitions = [...definitions.sort((a, b) => b.start - a.start)]
// has no map for ".js" files that use // @ts-check
const mapConsumer = map && new SourceMapConsumer(map)
const traceMap = map && new TraceMap(map as unknown as RawSourceMap)
const indexMap = createIndexMap(parsed)
const markState = (task: Task, state: TaskState) => {
task.result = {
Expand All @@ -129,11 +130,13 @@ export class Typechecker {
markState(task.suite, state)
}
errors.forEach(({ error, originalError }) => {
const processedPos = mapConsumer?.generatedPositionFor({
line: originalError.line,
column: originalError.column,
source: basename(path),
}) || originalError
const processedPos = traceMap
? generatedPositionFor(traceMap, {
line: originalError.line,
column: originalError.column,
source: basename(path),
})
: originalError
const line = processedPos.line ?? originalError.line
const column = processedPos.column ?? originalError.column
const index = indexMap.get(`${line}:${column}`)
Expand Down
3 changes: 1 addition & 2 deletions packages/vitest/src/types/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { RawSourceMap } from 'source-map'
import type { FetchResult, ViteNodeResolveId } from 'vite-node'
import type { FetchResult, RawSourceMap, ViteNodeResolveId } from 'vite-node'
import type { EnvironmentOptions, ResolvedConfig, VitestEnvironment } from './config'
import type { UserConsoleLog } from './general'
import type { SnapshotResult } from './snapshot'
Expand Down
Loading