Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cff5f0c

Browse files
Copilotsapphi-red
andauthored
fix(ssr): ssrTransform incorrectly rewrites meta identifier inside import.meta when a binding named meta exists (#22019)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: sapphi-red <[email protected]>
1 parent 5464190 commit cff5f0c

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,18 @@ test('import.meta', async () => {
300300
).toMatchInlineSnapshot(`"console.log(__vite_ssr_import_meta__.url)"`)
301301
})
302302

303+
test('import.meta with imported variable named meta', async () => {
304+
expect(
305+
await ssrTransformSimpleCode(
306+
`import { meta } from './meta';\nconsole.log(import.meta.url, \`Hello, \${meta}!\`)`,
307+
),
308+
).toMatchInlineSnapshot(`
309+
"const __vite_ssr_import_0__ = await __vite_ssr_import__("./meta", {"importedNames":["meta"]});
310+
311+
console.log(__vite_ssr_import_meta__.url, \`Hello, \${__vite_ssr_import_0__.meta}!\`)"
312+
`)
313+
})
314+
303315
test('dynamic import', async () => {
304316
const result = await ssrTransformSimple(
305317
`export const i = () => import('./foo')`,

packages/vite/src/node/ssr/ssrTransform.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,11 @@ function isRefIdentifier(
709709
return false
710710
}
711711

712+
// meta property (e.g. import.meta)
713+
if (parent.type === 'MetaProperty') {
714+
return false
715+
}
716+
712717
// export { id } from "lib"
713718
// export * as id from "lib"
714719
if (

0 commit comments

Comments
 (0)