1
1
import * as CompilerDOM from '@vue/compiler-dom' ;
2
2
import { camelize , capitalize } from '@vue/shared' ;
3
3
import type { Code , VueCodeInformation } from '../../types' ;
4
- import { getSlotsPropertyName , hyphenateTag } from '../../utils/shared' ;
4
+ import { getElementTagOffsets , getSlotsPropertyName , hyphenateTag } from '../../utils/shared' ;
5
5
import { codeFeatures } from '../codeFeatures' ;
6
6
import { createVBindShorthandInlayHintInfo } from '../inlayHints' ;
7
7
import { endOfLine , identifierRegex , newLine , normalizeAttributeValue } from '../utils' ;
@@ -25,13 +25,7 @@ export function* generateComponent(
25
25
ctx : TemplateCodegenContext ,
26
26
node : CompilerDOM . ElementNode ,
27
27
) : Generator < Code > {
28
- const tagOffsets = [ node . loc . start . offset + options . template . content . slice ( node . loc . start . offset ) . indexOf ( node . tag ) ] ;
29
- if ( ! node . isSelfClosing && options . template . lang === 'html' ) {
30
- const endTagOffset = node . loc . start . offset + node . loc . source . lastIndexOf ( node . tag ) ;
31
- if ( endTagOffset > tagOffsets [ 0 ] ) {
32
- tagOffsets . push ( endTagOffset ) ;
33
- }
34
- }
28
+ const tagOffsets = getElementTagOffsets ( node , options . template ) ;
35
29
const failedPropExps : FailedPropExpression [ ] = [ ] ;
36
30
const possibleOriginalNames = getPossibleOriginalComponentNames ( node . tag , true ) ;
37
31
const matchImportName = possibleOriginalNames . find ( name => options . scriptSetupImportComponentNames . has ( name ) ) ;
@@ -294,25 +288,16 @@ export function* generateElement(
294
288
ctx : TemplateCodegenContext ,
295
289
node : CompilerDOM . ElementNode ,
296
290
) : Generator < Code > {
297
- const startTagOffset = node . loc . start . offset
298
- + options . template . content . slice ( node . loc . start . offset ) . indexOf ( node . tag ) ;
299
- const endTagOffset = ! node . isSelfClosing && options . template . lang === 'html'
300
- ? node . loc . start . offset + node . loc . source . lastIndexOf ( node . tag )
301
- : undefined ;
291
+ const [ startTagOffset , endTagOffset ] = getElementTagOffsets ( node , options . template ) ;
302
292
const failedPropExps : FailedPropExpression [ ] = [ ] ;
303
293
304
- const features = {
305
- ...codeFeatures . semanticWithoutHighlight ,
306
- ...codeFeatures . navigationWithoutHighlight ,
307
- } ;
308
-
309
294
yield `__VLS_asFunctionalElement(__VLS_elements` ;
310
295
yield * generatePropertyAccess (
311
296
options ,
312
297
ctx ,
313
298
node . tag ,
314
299
startTagOffset ,
315
- features ,
300
+ codeFeatures . withoutHighlightAndCompletion ,
316
301
) ;
317
302
if ( endTagOffset !== undefined ) {
318
303
yield `, __VLS_elements` ;
@@ -321,7 +306,7 @@ export function* generateElement(
321
306
ctx ,
322
307
node . tag ,
323
308
endTagOffset ,
324
- features ,
309
+ codeFeatures . withoutHighlightAndCompletion ,
325
310
) ;
326
311
}
327
312
yield `)(` ;
0 commit comments