@@ -3,7 +3,7 @@ import path from 'path'
3
3
import { describe , expect , test } from 'vitest'
4
4
import type { ComponentResolver } from '../src'
5
5
import { Context } from '../src/core/context'
6
- import { getDeclaration } from '../src/core/declaration'
6
+ import { getDeclaration , parseDeclaration } from '../src/core/declaration'
7
7
8
8
const resolver : ComponentResolver [ ] = [
9
9
{
@@ -82,4 +82,73 @@ const _directive_loading = _resolveDirective("loading")`
82
82
expect ( contents ) . not . toContain ( 'comment' )
83
83
expect ( contents ) . toContain ( 'vSome' )
84
84
} )
85
+
86
+ test ( 'parseDeclaration' , async ( ) => {
87
+ const code = `
88
+ // generated by unplugin-vue-components
89
+ // We suggest you to commit this file into source control
90
+ // Read more: https://github.com/vuejs/core/pull/3399
91
+ import '@vue/runtime-core'
92
+
93
+ export {}
94
+
95
+ declare module '@vue/runtime-core' {
96
+ export interface GlobalComponents {
97
+ ComponentA: typeof import('./src/components/ComponentA.vue')['default']
98
+ ComponentB: typeof import('./src/components/ComponentB.vue')['default']
99
+ ComponentC: typeof import('./src/components/component-c.vue')['default']
100
+ }
101
+ }`
102
+
103
+ const imports = parseDeclaration ( code )
104
+ expect ( imports ) . matchSnapshot ( )
105
+ } )
106
+
107
+ test ( 'parseDeclaration - has icon component like <IMdi:diceD12>' , async ( ) => {
108
+ const code = `
109
+ // generated by unplugin-vue-components
110
+ // We suggest you to commit this file into source control
111
+ // Read more: https://github.com/vuejs/core/pull/3399
112
+ import '@vue/runtime-core'
113
+
114
+ export {}
115
+
116
+ declare module '@vue/runtime-core' {
117
+ export interface GlobalComponents {
118
+ ComponentA: typeof import('./src/components/ComponentA.vue')['default']
119
+ 'IMdi:diceD12': typeof import('~icons/mdi/dice-d12')['default']
120
+ IMdiLightAlarm: typeof import('~icons/mdi-light/alarm')['default']
121
+ }
122
+ }`
123
+
124
+ const imports = parseDeclaration ( code )
125
+ expect ( imports ) . matchSnapshot ( )
126
+ } )
127
+
128
+ test ( 'parseDeclaration - with directives' , async ( ) => {
129
+ const code = `
130
+ // generated by unplugin-vue-components
131
+ // We suggest you to commit this file into source control
132
+ // Read more: https://github.com/vuejs/core/pull/3399
133
+ import '@vue/runtime-core'
134
+
135
+ export {}
136
+
137
+ declare module '@vue/runtime-core' {
138
+ export interface GlobalComponents {
139
+ ComponentA: typeof import('./src/components/ComponentA.vue')['default']
140
+ 'IMdi:diceD12': typeof import('~icons/mdi/dice-d12')['default']
141
+ IMdiLightAlarm: typeof import('~icons/mdi-light/alarm')['default']
142
+ }
143
+
144
+ export interface ComponentCustomProperties {
145
+ vDirective: typeof import('foo')
146
+ vLoading: typeof import('test/directive/Loading')['default']
147
+ vSome: typeof import('test/directive/Some')['default']
148
+ }
149
+ }`
150
+
151
+ const imports = parseDeclaration ( code )
152
+ expect ( imports ) . matchSnapshot ( )
153
+ } )
85
154
} )
0 commit comments