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

fix(ssr): replace __vite_ssr_identity__ with (0, ...) and inject ; between statements #18748

Merged
merged 12 commits into from
Nov 26, 2024
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"test-build": "VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
"test-unit": "vitest run",
"test-docs": "pnpm run docs-build",
"bench": "vitest bench",
"debug-serve": "VITE_DEBUG_SERVE=1 vitest run -c vitest.config.e2e.ts",
"debug-build": "VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 vitest run -c vitest.config.e2e.ts",
"docs": "pnpm --filter=docs run docs",
Expand Down
81 changes: 81 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import fs from 'node:fs'
import { bench } from 'vitest'
import { ssrTransform } from '../ssrTransform'

const ssrTransformSimple = async (code: string, url = '') =>
ssrTransform(code, null, url, code)
const ssrTransformSimpleCode = async (code: string, url?: string) =>
(await ssrTransformSimple(code, url))?.code

bench(
'basic',
async () => {
await ssrTransformSimpleCode(`
import { f } from './f'

let x = 0;

x
f()

if (1)
x
f()

if (1)
x
else
x
f()


let y = x
f()

x /*;;*/ /*;;*/
f()

function z() {
x
f()

if (1) {
x
f()
}
}

let a = {}
f()

let b = () => {}
f()

function c() {
}
f()

class D {
}
f()

{
x
}
f()
`)
},
{ time: 5000 },
)

const file =
'packages/vite/src/node/ssr/__tests__/node_modules/.cache/_chunk-YE4AM67Y.js'
const js = fs.readFileSync(file, 'utf-8')

bench(
'large',
async () => {
await ssrTransformSimpleCode(js)
},
{ time: 5000 },
)
Loading