11import type * as CompilerDOM from '@vue/compiler-dom' ;
22import type { Code , VueCodeInformation } from '../../types' ;
3+ import { codeFeatures } from '../codeFeatures' ;
34import { InlayHintInfo } from '../inlayHints' ;
45import { endOfLine , newLine , wrapWith } from '../utils' ;
56import type { TemplateCodegenOptions } from './index' ;
67
7- const _codeFeatures = {
8- all : {
9- verification : true ,
10- completion : true ,
11- semantic : true ,
12- navigation : true ,
13- } as VueCodeInformation ,
14- verification : {
15- verification : true ,
16- } as VueCodeInformation ,
17- completion : {
18- completion : true ,
19- } as VueCodeInformation ,
20- additionalCompletion : {
21- completion : { isAdditional : true } ,
22- } as VueCodeInformation ,
23- navigation : {
24- navigation : true ,
25- } as VueCodeInformation ,
26- navigationWithoutRename : {
27- navigation : {
28- shouldRename ( ) {
29- return false ;
30- } ,
31- } ,
32- } as VueCodeInformation ,
33- navigationAndCompletion : {
34- navigation : true ,
35- completion : true ,
36- } as VueCodeInformation ,
37- navigationAndAdditionalCompletion : {
38- navigation : true ,
39- completion : { isAdditional : true } ,
40- } as VueCodeInformation ,
41- navigationAndVerification : {
42- navigation : true ,
43- verification : true ,
44- } as VueCodeInformation ,
45- withoutNavigation : {
46- verification : true ,
47- completion : true ,
48- semantic : true ,
49- } as VueCodeInformation ,
50- withoutHighlight : {
51- semantic : { shouldHighlight : ( ) => false } ,
52- verification : true ,
53- navigation : true ,
54- completion : true ,
55- } as VueCodeInformation ,
56- withoutHighlightAndNavigation : {
57- semantic : { shouldHighlight : ( ) => false } ,
58- verification : true ,
59- completion : true ,
60- } as VueCodeInformation ,
61- withoutHighlightAndCompletion : {
62- semantic : { shouldHighlight : ( ) => false } ,
63- verification : true ,
64- navigation : true ,
65- } as VueCodeInformation ,
66- withoutHighlightAndCompletionAndNavigation : {
67- semantic : { shouldHighlight : ( ) => false } ,
68- verification : true ,
69- } as VueCodeInformation ,
70- } ;
71-
728export type TemplateCodegenContext = ReturnType < typeof createTemplateCodegenContext > ;
739
7410export function createTemplateCodegenContext ( options : Pick < TemplateCodegenOptions , 'scriptSetupBindingNames' | 'edited' > ) {
@@ -83,34 +19,30 @@ export function createTemplateCodegenContext(options: Pick<TemplateCodegenOption
8319 } | undefined ;
8420 let variableId = 0 ;
8521
86- const codeFeatures = new Proxy ( _codeFeatures , {
87- get ( target , key : keyof typeof _codeFeatures ) {
88- const data = target [ key ] ;
89- if ( data . verification ) {
90- if ( ignoredError ) {
91- return {
92- ...data ,
93- verification : false ,
94- } ;
95- }
96- if ( expectErrorToken ) {
97- const token = expectErrorToken ;
98- if ( typeof data . verification !== 'object' || ! data . verification . shouldReport ) {
99- return {
100- ...data ,
101- verification : {
102- shouldReport : ( ) => {
103- token . errors ++ ;
104- return false ;
105- } ,
106- } ,
107- } ;
108- }
109- }
22+ function resolveCodeFeatures ( features : VueCodeInformation ) {
23+ if ( features . verification ) {
24+ if ( ignoredError ) {
25+ return {
26+ ...features ,
27+ verification : false ,
28+ } ;
11029 }
111- return data ;
112- } ,
113- } ) ;
30+ if ( expectErrorToken ) {
31+ const token = expectErrorToken ;
32+ return {
33+ ...features ,
34+ verification : {
35+ shouldReport : ( ) => {
36+ token . errors ++ ;
37+ return false ;
38+ }
39+ } ,
40+ } ;
41+ }
42+ }
43+ return features ;
44+ }
45+
11446 const localVars = new Map < string , number > ( ) ;
11547 const specialVars = new Set < string > ( ) ;
11648 const accessExternalVariables = new Map < string , Set < number > > ( ) ;
@@ -138,9 +70,15 @@ export function createTemplateCodegenContext(options: Pick<TemplateCodegenOption
13870 const templateRefs = new Map < string , [ varName : string , offset : number ] > ( ) ;
13971
14072 return {
73+ codeFeatures : new Proxy ( codeFeatures , {
74+ get ( target , key : keyof typeof codeFeatures ) {
75+ const data = target [ key ] ;
76+ return resolveCodeFeatures ( data ) ;
77+ } ,
78+ } ) ,
79+ resolveCodeFeatures,
14180 slots,
14281 dynamicSlots,
143- codeFeatures,
14482 specialVars,
14583 accessExternalVariables,
14684 lastGenericComment,
0 commit comments