File tree 2 files changed +35
-2
lines changed
packages/vite/src/node/ssr
2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -498,3 +498,34 @@ objRest()
498
498
"
499
499
` )
500
500
} )
501
+
502
+ test ( 'class props' , async ( ) => {
503
+ expect (
504
+ (
505
+ await ssrTransform (
506
+ `
507
+ import { remove, add } from 'vue'
508
+
509
+ class A {
510
+ remove = 1
511
+ add = null
512
+ }
513
+ ` ,
514
+ null ,
515
+ null
516
+ )
517
+ ) . code
518
+ ) . toMatchInlineSnapshot ( `
519
+ "
520
+ const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
521
+
522
+
523
+ const add = __vite_ssr_import_0__.add;
524
+ const remove = __vite_ssr_import_0__.remove;
525
+ class A {
526
+ remove = 1
527
+ add = null
528
+ }
529
+ "
530
+ ` )
531
+ } )
Original file line number Diff line number Diff line change @@ -180,6 +180,7 @@ export async function ssrTransform(
180
180
// 3. convert references to import bindings & import.meta references
181
181
walk ( ast , {
182
182
onIdentifier ( id , parent , parentStack ) {
183
+ const grandparent = parentStack [ parentStack . length - 2 ]
183
184
const binding = idToImportMap . get ( id . name )
184
185
if ( ! binding ) {
185
186
return
@@ -195,8 +196,9 @@ export async function ssrTransform(
195
196
s . appendLeft ( id . end , `: ${ binding } ` )
196
197
}
197
198
} else if (
198
- parent . type === 'ClassDeclaration' &&
199
- id === parent . superClass
199
+ ( parent . type === 'PropertyDefinition' &&
200
+ grandparent ?. type === 'ClassBody' ) ||
201
+ ( parent . type === 'ClassDeclaration' && id === parent . superClass )
200
202
) {
201
203
if ( ! declaredConst . has ( id . name ) ) {
202
204
declaredConst . add ( id . name )
You can’t perform that action at this time.
0 commit comments