@@ -17,22 +17,32 @@ export const createStub = (options: IStubOptions) => {
17
17
return { name : tag , render }
18
18
}
19
19
20
- const resolveComponentStubByName = ( name : string , stubs : Record < any , any > ) => {
21
- const pascal = pascalCase ( name )
22
- const kebab = kebabCase ( name )
20
+ const resolveComponentStubByName = (
21
+ componentName : string ,
22
+ stubs : Record < any , any >
23
+ ) => {
24
+ const componentPascalName = pascalCase ( componentName )
25
+ const componentKebabName = kebabCase ( componentName )
23
26
24
- for ( const [ key , value ] of Object . entries ( stubs ) ) {
25
- if ( name === pascal || name === kebab ) {
27
+ for ( const [ stubKey , value ] of Object . entries ( stubs ) ) {
28
+ if (
29
+ stubKey === componentPascalName ||
30
+ stubKey === componentKebabName ||
31
+ stubKey === componentName
32
+ ) {
26
33
return value
27
34
}
28
35
}
29
36
}
30
37
31
38
const isHTMLElement = ( args : VNodeArgs ) =>
32
39
Array . isArray ( args ) && typeof args [ 0 ] === 'string'
40
+
33
41
const isCommentOrFragment = ( args : VNodeArgs ) => typeof args [ 0 ] === 'symbol'
42
+
34
43
const isParent = ( args : VNodeArgs ) =>
35
44
typeof args [ 0 ] === 'object' && args [ 0 ] [ 'name' ] === 'VTU_COMPONENT'
45
+
36
46
const isComponent = ( args : VNodeArgs ) => typeof args [ 0 ] === 'object'
37
47
38
48
export function stubComponents ( stubs : Record < any , any > ) {
@@ -48,15 +58,15 @@ export function stubComponents(stubs: Record<any, any>) {
48
58
}
49
59
50
60
const stub = resolveComponentStubByName ( name , stubs )
61
+
51
62
// we return a stub by matching Vue's `h` function
52
63
// where the signature is h(Component, props)
53
-
54
- // default stub
64
+ // case 1: default stub
55
65
if ( stub === true ) {
56
66
return [ createStub ( { name } ) , { } ]
57
67
}
58
68
59
- // custom implementation
69
+ // case 2: custom implementation
60
70
if ( typeof stub === 'object' ) {
61
71
return [ stubs [ name ] , { } ]
62
72
}
0 commit comments