@@ -7,44 +7,27 @@ import { createPlugins } from './plugins';
77import type { VueCompilerOptions , VueLanguagePlugin , VueLanguagePluginReturn } from './types' ;
88import { VueVirtualCode } from './virtualFile/vueFile' ;
99
10- const fileRegistries : {
11- key : string ;
12- plugins : VueLanguagePlugin [ ] ;
13- files : Map < string , VueVirtualCode > ;
14- } [ ] = [ ] ;
10+ const fileRegistries : Record < string , Map < string , VueVirtualCode > > = { } ;
1511
16- function getVueFileRegistry ( key : string , plugins : VueLanguagePlugin [ ] ) {
17- let fileRegistry = fileRegistries . find ( r =>
18- r . key === key
19- && r . plugins . length === plugins . length
20- && r . plugins . every ( plugin => plugins . includes ( plugin ) )
21- ) ?. files ;
22- if ( ! fileRegistry ) {
23- fileRegistry = new Map ( ) ;
24- fileRegistries . push ( {
25- key : key ,
26- plugins : plugins ,
27- files : fileRegistry ,
28- } ) ;
29- }
30- return fileRegistry ;
31- }
32-
33- function getFileRegistryKey (
12+ function getVueFileRegistry (
3413 compilerOptions : ts . CompilerOptions ,
3514 vueCompilerOptions : VueCompilerOptions ,
3615 plugins : VueLanguagePluginReturn [ ] ,
3716) {
38- const values = [
17+ const key = JSON . stringify ( [
18+ ...plugins . map ( plugin => plugin . name )
19+ . filter ( name => typeof name === 'string' )
20+ . sort ( ) ,
3921 ...Object . keys ( vueCompilerOptions )
40- . sort ( )
4122 . filter ( key => key !== 'plugins' )
23+ . sort ( )
4224 . map ( key => [ key , vueCompilerOptions [ key as keyof VueCompilerOptions ] ] ) ,
43- [ ...new Set ( plugins . map ( plugin => plugin . requiredCompilerOptions ?? [ ] ) . flat ( ) ) ]
25+ ... [ ...new Set ( plugins . flatMap ( plugin => plugin . requiredCompilerOptions ?? [ ] ) ) ]
4426 . sort ( )
4527 . map ( key => [ key , compilerOptions [ key as keyof ts . CompilerOptions ] ] ) ,
46- ] ;
47- return JSON . stringify ( values ) ;
28+ ] ) ;
29+
30+ return fileRegistries [ key ] ??= new Map ( ) ;
4831}
4932
5033export function createVueLanguagePlugin < T > (
@@ -62,10 +45,7 @@ export function createVueLanguagePlugin<T>(
6245 vueCompilerOptions,
6346 } ;
6447 const plugins = createPlugins ( pluginContext ) ;
65- const fileRegistry = getVueFileRegistry (
66- getFileRegistryKey ( compilerOptions , vueCompilerOptions , plugins ) ,
67- vueCompilerOptions . plugins ,
68- ) ;
48+ const fileRegistry = getVueFileRegistry ( compilerOptions , vueCompilerOptions , plugins ) ;
6949
7050 return {
7151 getLanguageId ( scriptId ) {
0 commit comments