@@ -27,7 +27,7 @@ export function createCheckerByJsonConfigBase(
27
27
checkerOptions : MetaCheckerOptions = { }
28
28
) {
29
29
rootDir = rootDir . replace ( windowsPathReg , '/' ) ;
30
- return createCheckerWorker (
30
+ return baseCreate (
31
31
ts ,
32
32
( ) => vue . createParsedCommandLineByJson ( ts , ts . sys , rootDir , json ) ,
33
33
checkerOptions ,
@@ -42,7 +42,7 @@ export function createCheckerBase(
42
42
checkerOptions : MetaCheckerOptions = { }
43
43
) {
44
44
tsconfig = tsconfig . replace ( windowsPathReg , '/' ) ;
45
- return createCheckerWorker (
45
+ return baseCreate (
46
46
ts ,
47
47
( ) => vue . createParsedCommandLine ( ts , ts . sys , tsconfig ) ,
48
48
checkerOptions ,
@@ -51,75 +51,28 @@ export function createCheckerBase(
51
51
) ;
52
52
}
53
53
54
- function createCheckerWorker (
54
+ export function baseCreate (
55
55
ts : typeof import ( 'typescript' ) ,
56
- loadParsedCommandLine : ( ) => vue . ParsedCommandLine ,
56
+ getCommandLine : ( ) => vue . ParsedCommandLine ,
57
57
checkerOptions : MetaCheckerOptions ,
58
58
rootPath : string ,
59
59
globalComponentName : string
60
60
) {
61
-
62
- /**
63
- * Original Host
64
- */
65
-
66
- let parsedCommandLine = loadParsedCommandLine ( ) ;
67
- let fileNames = parsedCommandLine . fileNames . map ( path => path . replace ( windowsPathReg , '/' ) ) ;
61
+ let commandLine = getCommandLine ( ) ;
62
+ let fileNames = commandLine . fileNames . map ( path => path . replace ( windowsPathReg , '/' ) ) ;
68
63
let projectVersion = 0 ;
69
64
70
- const scriptSnapshots = new Map < string , ts . IScriptSnapshot > ( ) ;
71
65
const projectHost : TypeScriptProjectHost = {
72
66
getCurrentDirectory : ( ) => rootPath ,
73
67
getProjectVersion : ( ) => projectVersion . toString ( ) ,
74
- getCompilationSettings : ( ) => parsedCommandLine . options ,
68
+ getCompilationSettings : ( ) => commandLine . options ,
75
69
getScriptFileNames : ( ) => fileNames ,
76
- getProjectReferences : ( ) => parsedCommandLine . projectReferences ,
77
- getScriptSnapshot : fileName => {
78
- if ( ! scriptSnapshots . has ( fileName ) ) {
79
- const fileText = ts . sys . readFile ( fileName ) ;
80
- if ( fileText !== undefined ) {
81
- scriptSnapshots . set ( fileName , ts . ScriptSnapshot . fromString ( fileText ) ) ;
82
- }
83
- }
84
- return scriptSnapshots . get ( fileName ) ;
85
- } ,
70
+ getProjectReferences : ( ) => commandLine . projectReferences ,
86
71
} ;
87
-
88
- return {
89
- ...baseCreate ( ts , projectHost , parsedCommandLine . vueOptions , checkerOptions , globalComponentName ) ,
90
- updateFile ( fileName : string , text : string ) {
91
- fileName = fileName . replace ( windowsPathReg , '/' ) ;
92
- scriptSnapshots . set ( fileName , ts . ScriptSnapshot . fromString ( text ) ) ;
93
- projectVersion ++ ;
94
- } ,
95
- deleteFile ( fileName : string ) {
96
- fileName = fileName . replace ( windowsPathReg , '/' ) ;
97
- fileNames = fileNames . filter ( f => f !== fileName ) ;
98
- projectVersion ++ ;
99
- } ,
100
- reload ( ) {
101
- parsedCommandLine = loadParsedCommandLine ( ) ;
102
- fileNames = parsedCommandLine . fileNames . map ( path => path . replace ( windowsPathReg , '/' ) ) ;
103
- this . clearCache ( ) ;
104
- } ,
105
- clearCache ( ) {
106
- scriptSnapshots . clear ( ) ;
107
- projectVersion ++ ;
108
- } ,
109
- } ;
110
- }
111
-
112
- export function baseCreate (
113
- ts : typeof import ( 'typescript' ) ,
114
- projectHost : TypeScriptProjectHost ,
115
- vueCompilerOptions : vue . VueCompilerOptions ,
116
- checkerOptions : MetaCheckerOptions ,
117
- globalComponentName : string
118
- ) {
119
72
const globalComponentSnapshot = ts . ScriptSnapshot . fromString ( '<script setup lang="ts"></script>' ) ;
120
- const metaSnapshots : Record < string , ts . IScriptSnapshot > = { } ;
73
+ const scriptSnapshots = new Map < string , ts . IScriptSnapshot | undefined > ( ) ;
74
+ const metaSnapshots = new Map < string , ts . IScriptSnapshot > ( ) ;
121
75
const getScriptFileNames = projectHost . getScriptFileNames ;
122
- const getScriptSnapshot = projectHost . getScriptSnapshot ;
123
76
projectHost . getScriptFileNames = ( ) => {
124
77
const names = getScriptFileNames ( ) ;
125
78
return [
@@ -129,20 +82,6 @@ export function baseCreate(
129
82
getMetaFileName ( globalComponentName ) ,
130
83
] ;
131
84
} ;
132
- projectHost . getScriptSnapshot = fileName => {
133
- if ( isMetaFileName ( fileName ) ) {
134
- if ( ! metaSnapshots [ fileName ] ) {
135
- metaSnapshots [ fileName ] = ts . ScriptSnapshot . fromString ( getMetaScriptContent ( fileName ) ) ;
136
- }
137
- return metaSnapshots [ fileName ] ;
138
- }
139
- else if ( fileName === globalComponentName ) {
140
- return globalComponentSnapshot ;
141
- }
142
- else {
143
- return getScriptSnapshot ( fileName ) ;
144
- }
145
- } ;
146
85
147
86
const vueLanguagePlugin = vue . createVueLanguagePlugin2 < string > (
148
87
ts ,
@@ -153,7 +92,7 @@ export function baseCreate(
153
92
ts . sys . useCaseSensitiveFileNames
154
93
) ,
155
94
projectHost . getCompilationSettings ( ) ,
156
- vueCompilerOptions
95
+ commandLine . vueOptions
157
96
) ;
158
97
const language = vue . createLanguage (
159
98
[
@@ -166,7 +105,30 @@ export function baseCreate(
166
105
] ,
167
106
new vue . FileMap ( ts . sys . useCaseSensitiveFileNames ) ,
168
107
fileName => {
169
- const snapshot = projectHost . getScriptSnapshot ( fileName ) ;
108
+ let snapshot = scriptSnapshots . get ( fileName ) ;
109
+
110
+ if ( fileName === globalComponentName ) {
111
+ snapshot = globalComponentSnapshot ;
112
+ }
113
+ else if ( isMetaFileName ( fileName ) ) {
114
+ if ( ! metaSnapshots . has ( fileName ) ) {
115
+ metaSnapshots . set ( fileName , ts . ScriptSnapshot . fromString ( getMetaScriptContent ( fileName ) ) ) ;
116
+ }
117
+ snapshot = metaSnapshots . get ( fileName ) ;
118
+ }
119
+ else {
120
+ if ( ! scriptSnapshots . has ( fileName ) ) {
121
+ const fileText = ts . sys . readFile ( fileName ) ;
122
+ if ( fileText !== undefined ) {
123
+ scriptSnapshots . set ( fileName , ts . ScriptSnapshot . fromString ( fileText ) ) ;
124
+ }
125
+ else {
126
+ scriptSnapshots . set ( fileName , undefined ) ;
127
+ }
128
+ }
129
+ snapshot = scriptSnapshots . get ( fileName ) ;
130
+ }
131
+
170
132
if ( snapshot ) {
171
133
language . scripts . set ( fileName , snapshot ) ;
172
134
}
@@ -182,7 +144,7 @@ export function baseCreate(
182
144
const getScriptKind = languageServiceHost . getScriptKind ?. bind ( languageServiceHost ) ;
183
145
languageServiceHost . getScriptKind = fileName => {
184
146
const scriptKind = getScriptKind ! ( fileName ) ;
185
- if ( vueCompilerOptions . extensions . some ( ext => fileName . endsWith ( ext ) ) ) {
147
+ if ( commandLine . vueOptions . extensions . some ( ext => fileName . endsWith ( ext ) ) ) {
186
148
if ( scriptKind === ts . ScriptKind . JS ) {
187
149
return ts . ScriptKind . TS ;
188
150
}
@@ -199,6 +161,25 @@ export function baseCreate(
199
161
return {
200
162
getExportNames,
201
163
getComponentMeta,
164
+ updateFile ( fileName : string , text : string ) {
165
+ fileName = fileName . replace ( windowsPathReg , '/' ) ;
166
+ scriptSnapshots . set ( fileName , ts . ScriptSnapshot . fromString ( text ) ) ;
167
+ projectVersion ++ ;
168
+ } ,
169
+ deleteFile ( fileName : string ) {
170
+ fileName = fileName . replace ( windowsPathReg , '/' ) ;
171
+ fileNames = fileNames . filter ( f => f !== fileName ) ;
172
+ projectVersion ++ ;
173
+ } ,
174
+ reload ( ) {
175
+ commandLine = getCommandLine ( ) ;
176
+ fileNames = commandLine . fileNames . map ( path => path . replace ( windowsPathReg , '/' ) ) ;
177
+ this . clearCache ( ) ;
178
+ } ,
179
+ clearCache ( ) {
180
+ scriptSnapshots . clear ( ) ;
181
+ projectVersion ++ ;
182
+ } ,
202
183
__internal__ : {
203
184
tsLs,
204
185
} ,
@@ -210,7 +191,7 @@ export function baseCreate(
210
191
211
192
function getMetaFileName ( fileName : string ) {
212
193
return (
213
- vueCompilerOptions . extensions . some ( ext => fileName . endsWith ( ext ) )
194
+ commandLine . vueOptions . extensions . some ( ext => fileName . endsWith ( ext ) )
214
195
? fileName
215
196
: fileName . substring ( 0 , fileName . lastIndexOf ( '.' ) )
216
197
) + '.meta.ts' ;
@@ -229,7 +210,7 @@ interface ComponentMeta<T> {
229
210
exposed: ComponentExposed<T>;
230
211
};
231
212
232
- ${ vueCompilerOptions . target < 3 ? vue2TypeHelpersCode : typeHelpersCode }
213
+ ${ commandLine . vueOptions . target < 3 ? vue2TypeHelpersCode : typeHelpersCode }
233
214
` . trim ( ) ;
234
215
return code ;
235
216
}
@@ -321,11 +302,11 @@ ${vueCompilerOptions.target < 3 ? vue2TypeHelpersCode : typeHelpersCode}
321
302
322
303
// fill defaults
323
304
const printer = ts . createPrinter ( checkerOptions . printer ) ;
324
- const snapshot = projectHost . getScriptSnapshot ( componentPath ) ! ;
305
+ const snapshot = language . scripts . get ( componentPath ) ?. snapshot ! ;
325
306
326
307
const vueFile = language . scripts . get ( componentPath ) ?. generated ?. root ;
327
308
const vueDefaults = vueFile && exportName === 'default'
328
- ? ( vueFile instanceof vue . VueVirtualCode ? readVueComponentDefaultProps ( vueFile , printer , ts , vueCompilerOptions ) : { } )
309
+ ? ( vueFile instanceof vue . VueVirtualCode ? readVueComponentDefaultProps ( vueFile , printer , ts , commandLine . vueOptions ) : { } )
329
310
: { } ;
330
311
const tsDefaults = ! vueFile ? readTsComponentDefaultProps (
331
312
componentPath . substring ( componentPath . lastIndexOf ( '.' ) + 1 ) , // ts | js | tsx | jsx
0 commit comments