@@ -121,6 +121,121 @@ describe('compiler: element transform', () => {
121121 expect ( node . tag ) . toBe ( `Example` )
122122 } )
123123
124+ test ( 'resolve component from scoped slot bindings and shadows setup bindings' , ( ) => {
125+ const { code } = baseCompile (
126+ `<Example v-slot="{ Foo }"><Foo /></Example>` ,
127+ {
128+ prefixIdentifiers : true ,
129+ bindingMetadata : {
130+ Example : BindingTypes . SETUP_CONST ,
131+ Foo : BindingTypes . SETUP_MAYBE_REF ,
132+ } ,
133+ } ,
134+ )
135+
136+ expect ( code ) . toContain ( `_createVNode(Foo)` )
137+ expect ( code ) . not . toContain ( `_component_Foo` )
138+ expect ( code ) . not . toContain ( `_resolveComponent("Foo")` )
139+ expect ( code ) . not . toContain ( `$setup["Foo"]` )
140+ } )
141+
142+ test ( 'resolve kebab-cased component from scoped slot bindings' , ( ) => {
143+ const { code } = baseCompile (
144+ `<Example v-slot="{ fooBar }"><foo-bar /></Example>` ,
145+ {
146+ prefixIdentifiers : true ,
147+ isNativeTag : tag => tag !== 'foo-bar' ,
148+ bindingMetadata : {
149+ Example : BindingTypes . SETUP_CONST ,
150+ } ,
151+ } ,
152+ )
153+
154+ expect ( code ) . toContain ( `_createVNode(fooBar)` )
155+ expect ( code ) . not . toContain ( `_component_foo_bar` )
156+ expect ( code ) . not . toContain ( `_resolveComponent("foo-bar")` )
157+ } )
158+
159+ test ( 'does not resolve component from inactive scoped slot bindings' , ( ) => {
160+ const { code } = baseCompile (
161+ `<Example v-slot="{ Foo }"><Foo /></Example><Foo />` ,
162+ {
163+ prefixIdentifiers : true ,
164+ bindingMetadata : {
165+ Example : BindingTypes . SETUP_CONST ,
166+ } ,
167+ } ,
168+ )
169+
170+ expect ( code ) . toContain ( `_createVNode(Foo)` )
171+ expect ( code ) . toContain ( `const _component_Foo = _resolveComponent("Foo")` )
172+ expect ( code ) . toContain ( `_createVNode(_component_Foo)` )
173+ } )
174+
175+ test ( 'does not resolve component from v-for bindings' , ( ) => {
176+ const { code } = baseCompile (
177+ `<template v-for="Foo in list"><Foo :value="Foo" /></template>` ,
178+ {
179+ prefixIdentifiers : true ,
180+ } ,
181+ )
182+
183+ expect ( code ) . toContain ( `const _component_Foo = _resolveComponent("Foo")` )
184+ expect ( code ) . toContain ( `_createBlock(_component_Foo` )
185+ expect ( code ) . toContain ( `value: Foo` )
186+ expect ( code ) . not . toContain ( `_createVNode(Foo` )
187+ expect ( code ) . not . toContain ( `_createBlock(Foo` )
188+ } )
189+
190+ test ( 'does not resolve component from scoped slot bindings shadowed by v-for' , ( ) => {
191+ const { code } = baseCompile (
192+ `<Example v-slot="{ Foo }"><template v-for="Foo in list"><Foo /></template></Example>` ,
193+ {
194+ prefixIdentifiers : true ,
195+ bindingMetadata : {
196+ Example : BindingTypes . SETUP_CONST ,
197+ } ,
198+ } ,
199+ )
200+
201+ expect ( code ) . toContain ( `const _component_Foo = _resolveComponent("Foo")` )
202+ expect ( code ) . toContain ( `_createBlock(_component_Foo)` )
203+ expect ( code ) . not . toContain ( `_createVNode(Foo)` )
204+ expect ( code ) . not . toContain ( `_createBlock(Foo)` )
205+ } )
206+
207+ test ( 'resolve component from scoped slot bindings shadowing v-for' , ( ) => {
208+ const { code } = baseCompile (
209+ `<div v-for="Foo in list"><Example v-slot="{ Foo }"><Foo /></Example></div>` ,
210+ {
211+ prefixIdentifiers : true ,
212+ bindingMetadata : {
213+ Example : BindingTypes . SETUP_CONST ,
214+ } ,
215+ } ,
216+ )
217+
218+ expect ( code ) . toContain ( `_createVNode(Foo)` )
219+ expect ( code ) . not . toContain ( `_component_Foo` )
220+ expect ( code ) . not . toContain ( `_resolveComponent("Foo")` )
221+ } )
222+
223+ test ( 'resolve component from template scoped slot bindings' , ( ) => {
224+ const { code } = baseCompile (
225+ `<Example><template #default="{ Foo }"><Foo /></template></Example>` ,
226+ {
227+ prefixIdentifiers : true ,
228+ bindingMetadata : {
229+ Example : BindingTypes . SETUP_CONST ,
230+ } ,
231+ } ,
232+ )
233+
234+ expect ( code ) . toContain ( `_createVNode(Foo)` )
235+ expect ( code ) . not . toContain ( `_component_Foo` )
236+ expect ( code ) . not . toContain ( `_resolveComponent("Foo")` )
237+ } )
238+
124239 test ( 'resolve namespaced component from setup bindings' , ( ) => {
125240 const { root, node } = parseWithElementTransform ( `<Foo.Example/>` , {
126241 bindingMetadata : {
@@ -175,6 +290,23 @@ describe('compiler: element transform', () => {
175290 expect ( node . tag ) . toBe ( '_unref($props["Foo"]).Example' )
176291 } )
177292
293+ test ( 'resolve namespaced component from scoped slot bindings' , ( ) => {
294+ const { code } = baseCompile (
295+ `<Example v-slot="slotProps"><slot-props.Foo /></Example>` ,
296+ {
297+ prefixIdentifiers : true ,
298+ isNativeTag : tag => tag !== 'slot-props.Foo' ,
299+ bindingMetadata : {
300+ Example : BindingTypes . SETUP_CONST ,
301+ } ,
302+ } ,
303+ )
304+
305+ expect ( code ) . toContain ( `_createVNode(slotProps.Foo)` )
306+ expect ( code ) . not . toContain ( `_component_slot_props` )
307+ expect ( code ) . not . toContain ( `_resolveComponent("slot-props.Foo")` )
308+ } )
309+
178310 test ( 'do not resolve component from non-script-setup bindings' , ( ) => {
179311 const bindingMetadata = {
180312 Example : BindingTypes . SETUP_MAYBE_REF ,
0 commit comments