File tree 3 files changed +55
-9
lines changed
packages/babel-plugin-jsx
3 files changed +55
-9
lines changed Original file line number Diff line number Diff line change @@ -354,7 +354,17 @@ const getChildren = (
354
354
return transformedText ;
355
355
}
356
356
if ( path . isJSXExpressionContainer ( ) ) {
357
- return transformJSXExpressionContainer ( path ) ;
357
+ const expression = transformJSXExpressionContainer ( path ) ;
358
+
359
+ if ( t . isIdentifier ( expression ) ) {
360
+ const { name } = expression as t . Identifier ;
361
+ const { referencePaths } = path . scope . getBinding ( name ) || { } ;
362
+ referencePaths ?. forEach ( referencePath => {
363
+ walksScope ( referencePath , name ) ;
364
+ } )
365
+ }
366
+
367
+ return expression ;
358
368
}
359
369
if ( t . isJSXSpreadChild ( path ) ) {
360
370
return transformJSXSpreadChild ( path as NodePath < t . JSXSpreadChild > ) ;
Original file line number Diff line number Diff line change @@ -171,7 +171,9 @@ const transformJSXSpreadChild = (
171
171
172
172
const walksScope = ( path : NodePath , name : string ) => {
173
173
if ( path . scope . hasBinding ( name ) && path . parentPath ) {
174
- path . parentPath . setData ( 'optimize' , false ) ;
174
+ if ( t . isJSXElement ( path . parentPath . node ) ) {
175
+ path . parentPath . setData ( 'optimize' , false ) ;
176
+ }
175
177
walksScope ( path . parentPath , name ) ;
176
178
}
177
179
}
Original file line number Diff line number Diff line change @@ -353,16 +353,18 @@ describe('PatchFlags', () => {
353
353
354
354
expect ( wrapper . classes ( ) . sort ( ) ) . toEqual ( [ 'b' , 'static' ] . sort ( ) ) ;
355
355
} ) ;
356
+ } ) ;
356
357
357
- test ( 'variables outside slot ' , async ( ) => {
358
- const A = {
359
- render ( ) {
360
- return this . $slots . default ( ) ;
361
- } ,
362
- } ;
358
+ describe ( 'variables outside slots ' , async ( ) => {
359
+ const A = {
360
+ render ( ) {
361
+ return this . $slots . default ( ) ;
362
+ } ,
363
+ } ;
363
364
364
- A . inheritAttrs = false ;
365
+ A . inheritAttrs = false ;
365
366
367
+ test ( 'internal' , async ( ) => {
366
368
const wrapper = mount ( {
367
369
data ( ) {
368
370
return {
@@ -390,7 +392,39 @@ describe('PatchFlags', () => {
390
392
} ) ;
391
393
392
394
expect ( wrapper . get ( '#textarea' ) . element . innerHTML ) . toBe ( '0' ) ;
395
+ await wrapper . get ( '#button' ) . trigger ( 'click' ) ;
396
+ expect ( wrapper . get ( '#textarea' ) . element . innerHTML ) . toBe ( '1' ) ;
397
+ } ) ;
398
+
399
+ test ( 'forwarded' , async ( ) => {
400
+ const wrapper = mount ( {
401
+ data ( ) {
402
+ return {
403
+ val : 0 ,
404
+ } ;
405
+ } ,
406
+ methods : {
407
+ inc ( ) {
408
+ this . val += 1 ;
409
+ } ,
410
+ } ,
411
+ render ( ) {
412
+ const attrs = {
413
+ innerHTML : this . val ,
414
+ } ;
415
+ const textarea = < textarea id = "textarea" { ...attrs } /> ;
416
+ return (
417
+ < A inc = { this . inc } >
418
+ < div >
419
+ { textarea }
420
+ </ div >
421
+ < button id = "button" onClick = { this . inc } > +1</ button >
422
+ </ A >
423
+ ) ;
424
+ } ,
425
+ } ) ;
393
426
427
+ expect ( wrapper . get ( '#textarea' ) . element . innerHTML ) . toBe ( '0' ) ;
394
428
await wrapper . get ( '#button' ) . trigger ( 'click' ) ;
395
429
expect ( wrapper . get ( '#textarea' ) . element . innerHTML ) . toBe ( '1' ) ;
396
430
} ) ;
You can’t perform that action at this time.
0 commit comments