@@ -31,70 +31,68 @@ const plugin = _ => ({
31
31
}
32
32
33
33
// Add TemplateTags typings to autocomplete root in `css()`
34
- const templateTags = { }
35
- walkElementNodes (
36
- sfc . templateAst ,
37
- ( { tag } ) => {
38
- templateTags [ tag ] = true
39
- }
40
- )
41
-
42
- embeddedFile . codeGen . addText ( `type ComponentTemplateTags__VLS = {\n${ Object . entries ( templateTags ) . map (
43
- ( [ tag ] ) => {
44
- return ` /**
45
- * The \`<${ tag } >\` tag from the Vue template.
46
- */
47
- ${ tag } : true,\n`
34
+ if ( sfc . template && sfc . template . content ) {
35
+ const templateTags = { }
36
+ walkElementNodes (
37
+ sfc . templateAst ,
38
+ ( { tag } ) => {
39
+ templateTags [ tag ] = true
48
40
}
49
- ) . join ( '' ) }
50
- }\n` )
41
+ )
42
+ embeddedFile . codeGen . addText ( `type ComponentTemplateTags__VLS = {\n ${ Object . entries ( templateTags ) . map ( ( [ tag ] ) => ` /**\n * The \`< ${ tag } >\` tag from the Vue template.\n */\n ${ tag } : true,\n` ) . join ( '' ) } }\n`)
51
43
52
- // $variantProps()
53
- embeddedFile . codeGen . addText ( '\ndeclare const $variantsProps: (key: keyof ComponentTemplateTags__VLS) => {}\n' )
44
+ // $variantProps()
45
+ embeddedFile . codeGen . addText ( '\ndeclare const $variantsProps: (key: keyof ComponentTemplateTags__VLS) => {}\n' )
54
46
55
- const templateDtMatches = sfc . template . content . match ( dtRegex )
56
- if ( templateDtMatches ) {
57
- sfc . template . content . replace (
58
- dtRegex ,
59
- ( match , dtKey , index ) => addDt ( match , dtKey , index , sfc . template . tag )
60
- )
47
+ const templateDtMatches = sfc . template . content . match ( dtRegex )
48
+ if ( templateDtMatches ) {
49
+ sfc . template . content . replace (
50
+ dtRegex ,
51
+ ( match , dtKey , index ) => addDt ( match , dtKey , index , sfc . template . tag )
52
+ )
53
+ }
54
+ } else {
55
+ embeddedFile . codeGen . addText ( 'type ComponentTemplateTags__VLS = {}' )
61
56
}
62
57
63
58
// Grab `css()` function and type it.
64
59
for ( let i = 0 ; i < sfc . styles . length ; i ++ ) {
65
60
const style = sfc . styles [ i ]
66
- const cssMatches = style . content . match ( / c s s \( ( [ \s \S ] * ) \) / )
67
- const dtMatches = style . content . match ( dtRegex )
68
61
69
- if ( cssMatches ) {
70
- embeddedFile . codeGen . addText ( 'declare const css: (declaration: import(\'@nuxtjs/design-tokens\').CSS<ComponentTemplateTags__VLS, import(\'@nuxtjs/design-tokens\').NuxtStyleTheme>) => any' )
62
+ if ( style ?. content ) {
63
+ const cssMatches = style . content . match ( / c s s \( ( [ \s \S ] * ) \) / )
64
+ const dtMatches = style . content . match ( dtRegex )
65
+
66
+ if ( cssMatches ) {
67
+ embeddedFile . codeGen . addText ( 'declare const css: (declaration: import(\'@nuxtjs/design-tokens\').CSS<ComponentTemplateTags__VLS, import(\'@nuxtjs/design-tokens\').NuxtStyleTheme>) => any' )
71
68
72
- embeddedFile . codeGen . addText ( '\nconst __VLS_css = ' )
73
- embeddedFile . codeGen . addCode2 (
74
- cssMatches [ 0 ] ,
75
- cssMatches . index ,
76
- {
77
- vueTag : 'style' ,
78
- vueTagIndex : i ,
79
- capabilities : {
80
- basic : true ,
81
- references : true ,
82
- definitions : true ,
83
- diagnostic : true ,
84
- rename : true ,
85
- completion : true ,
86
- semanticTokens : true
69
+ embeddedFile . codeGen . addText ( '\nconst __VLS_css = ' )
70
+ embeddedFile . codeGen . addCode2 (
71
+ cssMatches [ 0 ] ,
72
+ cssMatches . index ,
73
+ {
74
+ vueTag : 'style' ,
75
+ vueTagIndex : i ,
76
+ capabilities : {
77
+ basic : true ,
78
+ references : true ,
79
+ definitions : true ,
80
+ diagnostic : true ,
81
+ rename : true ,
82
+ completion : true ,
83
+ semanticTokens : true
84
+ }
87
85
}
88
- }
89
- )
90
- embeddedFile . codeGen . addText ( '\n' )
91
- }
86
+ )
87
+ embeddedFile . codeGen . addText ( '\n' )
88
+ }
92
89
93
- if ( dtMatches ) {
94
- style . content . replace (
95
- dtRegex ,
96
- ( match , dtKey , index ) => addDt ( match , dtKey , index , style . tag , i )
97
- )
90
+ if ( dtMatches ) {
91
+ style . content . replace (
92
+ dtRegex ,
93
+ ( match , dtKey , index ) => addDt ( match , dtKey , index , style . tag , i )
94
+ )
95
+ }
98
96
}
99
97
}
100
98
}
0 commit comments