1- import type { CMKConfig , CSSModule , MatchesPattern , Resolver } from '@css-modules-kit/core' ;
2- import { isCSSModuleFile , parseCSSModule } from '@css-modules-kit/core' ;
1+ import type { CSSModule , MatchesPattern , Resolver } from '@css-modules-kit/core' ;
2+ import { isCSSModuleFile } from '@css-modules-kit/core' ;
33import type { Language } from '@volar/language-core' ;
44import ts from 'typescript' ;
55import { CMK_DATA_KEY , isCSSModuleScript } from '../../language-plugin.js' ;
@@ -18,27 +18,6 @@ function toTextSpan(loc: { start: { offset: number }; end: { offset: number } })
1818 return { start : loc . start . offset , length : loc . end . offset - loc . start . offset } ;
1919}
2020
21- function getImportedCSSModule (
22- resolver : Resolver ,
23- matchesPattern : MatchesPattern ,
24- config : CMKConfig ,
25- getCSSModule : ( path : string ) => CSSModule | undefined ,
26- from : string ,
27- requestFileName : string ,
28- ) : CSSModule | undefined {
29- const resolved = resolver ( from , { request : requestFileName } ) ;
30- if ( ! resolved || ! matchesPattern ( resolved ) || ! isCSSModuleFile ( resolved ) ) return ;
31- const existing = getCSSModule ( resolved ) ;
32- if ( existing ) return existing ;
33- const code = ts . sys . readFile ( resolved ) ;
34- if ( ! code ) return ;
35- return parseCSSModule ( code , {
36- fileName : resolved ,
37- includeSyntaxError : false ,
38- keyframes : config . keyframes ,
39- } ) ;
40- }
41-
4221function dedupeDefinitions ( definitions : readonly ts . DefinitionInfo [ ] ) : ts . DefinitionInfo [ ] {
4322 const seen = new Set < string > ( ) ;
4423 const result : ts . DefinitionInfo [ ] = [ ] ;
@@ -57,7 +36,6 @@ export function getDefinitionAndBoundSpan(
5736 languageService : ts . LanguageService ,
5837 resolver : Resolver ,
5938 matchesPattern : MatchesPattern ,
60- config : CMKConfig ,
6139 getCSSModule : ( path : string ) => CSSModule | undefined ,
6240) : ts . LanguageService [ 'getDefinitionAndBoundSpan' ] {
6341 return ( ...args ) => {
@@ -74,14 +52,9 @@ export function getDefinitionAndBoundSpan(
7452 const isInValue = position >= value . loc . start . offset && position < value . loc . end . offset ;
7553 if ( ! isInLocal && ! isInValue ) continue ;
7654
77- const importedModule = getImportedCSSModule (
78- resolver ,
79- matchesPattern ,
80- config ,
81- getCSSModule ,
82- importer . from ,
83- cssModule . fileName ,
84- ) ;
55+ const resolved = resolver ( importer . from , { request : cssModule . fileName } ) ;
56+ const importedModule =
57+ resolved && matchesPattern ( resolved ) && isCSSModuleFile ( resolved ) ? getCSSModule ( resolved ) : undefined ;
8558 if ( ! importedModule ) continue ;
8659
8760 const targetName = value . name ;
@@ -168,14 +141,9 @@ export function getDefinitionAndBoundSpan(
168141 if ( ! matchesTokenName ) continue ;
169142 const fallbackLoc = ( matchesTokenName && tokenName === localName ? value . localLoc : value . loc ) ?? value . loc ;
170143 importedLocs . push ( fallbackLoc as { start : { offset : number } ; end : { offset : number } } ) ;
171- const importedModule = getImportedCSSModule (
172- resolver ,
173- matchesPattern ,
174- config ,
175- getCSSModule ,
176- importer . from ,
177- cssModule . fileName ,
178- ) ;
144+ const resolved = resolver ( importer . from , { request : cssModule . fileName } ) ;
145+ const importedModule =
146+ resolved && matchesPattern ( resolved ) && isCSSModuleFile ( resolved ) ? getCSSModule ( resolved ) : undefined ;
179147 if ( importedModule ) {
180148 const matches = importedModule . localTokens . filter ( ( token ) => token . name === value . name ) ;
181149 if ( matches . length > 0 ) {
0 commit comments