Skip to content

Commit 9a79b90

Browse files
authored
perf: reduce the number of unused imports (#8508)
1 parent 2e49189 commit 9a79b90

File tree

120 files changed

+626
-546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+626
-546
lines changed

packages/browser/src/client/tester/runner.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import type { VitestBrowserClientMocker } from './mocker'
44
import { globalChannel, onCancel } from '@vitest/browser/client'
55
import { page, userEvent } from '@vitest/browser/context'
66
import {
7+
DecodedMap,
8+
getOriginalPosition,
79
loadDiffConfig,
810
loadSnapshotSerializers,
9-
originalPositionFor,
1011
takeCoverageInsideWorker,
11-
TraceMap,
1212
} from 'vitest/internal/browser'
1313
import { NodeBenchmarkRunner, VitestTestRunner } from 'vitest/runners'
1414
import { createStackString, parseStacktrace } from '../../../../utils/src/source-map'
@@ -154,20 +154,11 @@ export function createBrowserRunner(
154154
return rpc().onTaskAnnotate(test.id, annotation)
155155
}
156156

157-
const traceMap = new TraceMap(map as any)
158-
const { line, column, source } = originalPositionFor(traceMap, annotation.location)
159-
if (line != null && column != null && source != null) {
160-
let file: string = annotation.location.file
161-
if (source) {
162-
const fileUrl = annotation.location.file.startsWith('file://')
163-
? annotation.location.file
164-
: `file://${annotation.location.file}`
165-
const sourceRootUrl = map.sourceRoot
166-
? new URL(map.sourceRoot, fileUrl)
167-
: fileUrl
168-
file = new URL(source, sourceRootUrl).pathname
169-
}
170-
157+
const traceMap = new DecodedMap(map as any, annotation.location.file)
158+
const position = getOriginalPosition(traceMap, annotation.location)
159+
if (position) {
160+
const { source, column, line } = position
161+
const file = source || annotation.location.file
171162
annotation.location = {
172163
line,
173164
column: column + 1,
@@ -261,7 +252,7 @@ async function getTraceMap(file: string, sourceMaps: Map<string, any>) {
261252
if (!result) {
262253
return null
263254
}
264-
return new TraceMap(result as any)
255+
return new DecodedMap(result as any, file)
265256
}
266257

267258
async function updateTestFilesLocations(files: File[], sourceMaps: Map<string, any>) {
@@ -272,8 +263,9 @@ async function updateTestFilesLocations(files: File[], sourceMaps: Map<string, a
272263
}
273264
const updateLocation = (task: Task) => {
274265
if (task.location) {
275-
const { line, column } = originalPositionFor(traceMap, task.location)
276-
if (line != null && column != null) {
266+
const position = getOriginalPosition(traceMap, task.location)
267+
if (position) {
268+
const { line, column } = position
277269
task.location = { line, column: task.each ? column : column + 1 }
278270
}
279271
}

packages/browser/src/client/tester/snapshot.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { VitestBrowserClient } from '@vitest/browser/client'
22
import type { ParsedStack } from 'vitest/internal/browser'
33
import type { SnapshotEnvironment } from 'vitest/snapshot'
4-
import { originalPositionFor, TraceMap } from 'vitest/internal/browser'
4+
import { DecodedMap, getOriginalPosition } from 'vitest/internal/browser'
55

66
export class VitestBrowserSnapshotEnvironment implements SnapshotEnvironment {
77
private sourceMaps = new Map<string, any>()
8-
private traceMaps = new Map<string, TraceMap>()
8+
private traceMaps = new Map<string, DecodedMap>()
99

1010
public addSourceMap(filepath: string, map: any): void {
1111
this.sourceMaps.set(filepath, map)
@@ -46,12 +46,12 @@ export class VitestBrowserSnapshotEnvironment implements SnapshotEnvironment {
4646
}
4747
let traceMap = this.traceMaps.get(stack.file)
4848
if (!traceMap) {
49-
traceMap = new TraceMap(map)
49+
traceMap = new DecodedMap(map, stack.file)
5050
this.traceMaps.set(stack.file, traceMap)
5151
}
52-
const { line, column } = originalPositionFor(traceMap, stack)
53-
if (line != null && column != null) {
54-
return { ...stack, line, column }
52+
const position = getOriginalPosition(traceMap, stack)
53+
if (position) {
54+
return { ...stack, line: position.line, column: position.column }
5555
}
5656
return stack
5757
}

packages/browser/src/client/tester/state.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const sessionId = getBrowserState().sessionId
88
const state: WorkerGlobalState = {
99
ctx: {
1010
pool: 'browser',
11-
worker: './browser.js',
1211
workerId: 1,
1312
config,
1413
projectName: config.name || '',

packages/browser/src/node/commands/screenshotMatcher/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ScreenshotMatcherOptions } from '../../../../context'
33
import type { ScreenshotMatcherArguments } from '../../../shared/screenshotMatcher/types'
44
import type { AnyCodec } from './codecs'
55
import { platform } from 'node:os'
6-
import { deepMerge } from '@vitest/utils'
6+
import { deepMerge } from '@vitest/utils/helpers'
77
import { basename, dirname, extname, join, relative, resolve } from 'pathe'
88
import { takeScreenshot } from '../screenshot'
99
import { getCodec } from './codecs'

packages/browser/src/node/plugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { ParentBrowserProject } from './projectParent'
66
import { createReadStream, lstatSync, readFileSync } from 'node:fs'
77
import { createRequire } from 'node:module'
88
import { dynamicImportPlugin } from '@vitest/mocker/node'
9-
import { toArray } from '@vitest/utils'
9+
import { toArray } from '@vitest/utils/helpers'
1010
import MagicString from 'magic-string'
1111
import { basename, dirname, extname, resolve } from 'pathe'
1212
import sirv from 'sirv'
@@ -281,7 +281,6 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => {
281281
const include = [
282282
'vitest > expect-type',
283283
'vitest > @vitest/snapshot > magic-string',
284-
'vitest > @vitest/runner > strip-literal',
285284
'vitest > @vitest/expect > chai',
286285
'vitest > @vitest/expect > chai > loupe',
287286
'vitest > @vitest/utils > loupe',

packages/browser/src/node/plugins/pluginContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Rollup } from 'vite'
22
import type { Plugin } from 'vitest/config'
33
import type { ParentBrowserProject } from '../projectParent'
44
import { fileURLToPath } from 'node:url'
5-
import { slash } from '@vitest/utils'
5+
import { slash } from '@vitest/utils/helpers'
66
import { dirname, resolve } from 'pathe'
77

88
const VIRTUAL_ID_CONTEXT = '\0@vitest/browser/context'

packages/browser/src/node/pool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DeferPromise } from '@vitest/utils'
1+
import type { DeferPromise } from '@vitest/utils/helpers'
22
import type {
33
BrowserProvider,
44
ProcessPool,
@@ -9,7 +9,7 @@ import type {
99
import crypto from 'node:crypto'
1010
import * as nodeos from 'node:os'
1111
import { performance } from 'node:perf_hooks'
12-
import { createDefer } from '@vitest/utils'
12+
import { createDefer } from '@vitest/utils/helpers'
1313
import { stringify } from 'flatted'
1414
import { createDebugger } from 'vitest/node'
1515

packages/browser/src/node/projectParent.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,19 @@ export class ParentBrowserProject {
7575
return result?.map
7676
},
7777
getUrlId: (id) => {
78-
const mod = this.vite.moduleGraph.getModuleById(id)
78+
const moduleGraph = this.vite.environments.client.moduleGraph
79+
const mod = moduleGraph.getModuleById(id)
7980
if (mod) {
8081
return id
8182
}
8283
const resolvedPath = resolve(this.vite.config.root, id.slice(1))
83-
const modUrl = this.vite.moduleGraph.getModuleById(resolvedPath)
84+
const modUrl = moduleGraph.getModuleById(resolvedPath)
8485
if (modUrl) {
8586
return resolvedPath
8687
}
8788
// some browsers (looking at you, safari) don't report queries in stack traces
8889
// the next best thing is to try the first id that this file resolves to
89-
const files = this.vite.moduleGraph.getModulesByFile(resolvedPath)
90+
const files = moduleGraph.getModulesByFile(resolvedPath)
9091
if (files && files.size) {
9192
return files.values().next().value!.id!
9293
}

packages/expect/src/jest-expect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Constructable } from '@vitest/utils'
44
import type { AsymmetricMatcher } from './jest-asymmetric-matchers'
55
import type { Assertion, ChaiPlugin } from './types'
66
import { isMockFunction } from '@vitest/spy'
7-
import { assertTypes } from '@vitest/utils'
7+
import { assertTypes } from '@vitest/utils/helpers'
88
import c from 'tinyrainbow'
99
import { JEST_MATCHERS_OBJECT } from './constants'
1010
import {

packages/expect/src/jest-matcher-utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { Formatter } from 'tinyrainbow'
22
import type { MatcherHintOptions, Tester } from './types'
3-
import { getType, stringify } from '@vitest/utils'
43
import { diff, printDiffOrStringify } from '@vitest/utils/diff'
4+
import { stringify } from '@vitest/utils/display'
5+
import { getType } from '@vitest/utils/helpers'
56
import c from 'tinyrainbow'
67
import { JEST_MATCHERS_OBJECT } from './constants'
78

0 commit comments

Comments
 (0)