@@ -271,6 +271,37 @@ test('do not rewrite when function expression is in global scope', async () => {
271271 ` )
272272} )
273273
274+ test ( 'do not rewrite when class declaration is in scope' , async ( ) => {
275+ const result = await ssrTransformSimple (
276+ `import { cls } from 'vue';function A(){ class cls {} return { cls }; }` ,
277+ )
278+ expect ( result ?. code ) . toMatchInlineSnapshot ( `
279+ "const __vite_ssr_import_0__ = await __vite_ssr_import__("vue", {"importedNames":["cls"]});
280+ function A(){ class cls {} return { cls }; }"
281+ ` )
282+ expect ( result ?. deps ) . toEqual ( [ 'vue' ] )
283+ } )
284+
285+ test ( 'do not rewrite when class expression is in scope' , async ( ) => {
286+ const result = await ssrTransformSimple (
287+ `import { cls } from './vue';var a = function() { return class cls { constructor() { console.log(cls) } } }` ,
288+ )
289+ expect ( result ?. code ) . toMatchInlineSnapshot ( `
290+ "const __vite_ssr_import_0__ = await __vite_ssr_import__("./vue", {"importedNames":["cls"]});
291+ var a = function() { return class cls { constructor() { console.log(cls) } } }"
292+ ` )
293+ } )
294+
295+ test ( 'do not rewrite when class expression is in global scope' , async ( ) => {
296+ const result = await ssrTransformSimple (
297+ `import { cls } from './vue';foo(class cls { constructor() { console.log(cls) } })` ,
298+ )
299+ expect ( result ?. code ) . toMatchInlineSnapshot ( `
300+ "const __vite_ssr_import_0__ = await __vite_ssr_import__("./vue", {"importedNames":["cls"]});
301+ foo(class cls { constructor() { console.log(cls) } })"
302+ ` )
303+ } )
304+
274305test ( 'do not rewrite catch clause' , async ( ) => {
275306 const result = await ssrTransformSimple (
276307 `import {error} from './dependency';try {} catch(error) {}` ,
0 commit comments