1- import type { CMKConfig } from '@css-modules-kit/core' ;
2- import {
3- getCssModuleFileName ,
4- isComponentFileName ,
5- isCSSModuleFile ,
6- isCSSModulesDtsFile ,
7- STYLES_EXPORT_NAME ,
8- } from '@css-modules-kit/core' ;
1+ import type { CMKConfig , Resolver } from '@css-modules-kit/core' ;
2+ import { getCssModuleFileName , isComponentFileName , isCSSModuleFile , STYLES_EXPORT_NAME } from '@css-modules-kit/core' ;
93import ts from 'typescript' ;
4+ import { convertDefaultImportsToNamespaceImports } from '../../util.js' ;
105
116export function getCompletionsAtPosition (
127 languageService : ts . LanguageService ,
@@ -89,6 +84,7 @@ function isClassNamePropEntry(entry: ts.CompletionEntry) {
8984
9085export function getCompletionEntryDetails (
9186 languageService : ts . LanguageService ,
87+ resolver : Resolver ,
9288 config : CMKConfig ,
9389) : ts . LanguageService [ 'getCompletionEntryDetails' ] {
9490 // eslint-disable-next-line max-params
@@ -104,39 +100,9 @@ export function getCompletionEntryDetails(
104100 ) ;
105101 if ( ! details ) return undefined ;
106102
107- if ( config . namedExports && isDefaultExportedStylesEntryDetails ( entryName , data , config ) ) {
108- for ( const codeAction of details . codeActions ?? [ ] ) {
109- for ( const change of codeAction . changes ) {
110- // `import styles from` => `import * as styles from`
111- for ( const textChange of change . textChanges ) {
112- if ( textChange . newText . startsWith ( `import ${ STYLES_EXPORT_NAME } from` ) ) {
113- textChange . newText = textChange . newText . replace (
114- `import ${ STYLES_EXPORT_NAME } from` ,
115- `import * as ${ STYLES_EXPORT_NAME } from` ,
116- ) ;
117- }
118- }
119- }
120- }
103+ if ( config . namedExports && details . codeActions ) {
104+ convertDefaultImportsToNamespaceImports ( details . codeActions , fileName , resolver ) ;
121105 }
122106 return details ;
123107 } ;
124108}
125-
126- /**
127- * Check if the completion entry details are the default exported `styles` entry.
128- */
129- function isDefaultExportedStylesEntryDetails (
130- entryName : string ,
131- data : ts . CompletionEntryData | undefined ,
132- config : CMKConfig ,
133- ) : boolean {
134- return (
135- entryName === STYLES_EXPORT_NAME &&
136- ! ! data &&
137- // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
138- data . exportName === ts . InternalSymbolName . Default &&
139- data . fileName !== undefined &&
140- isCSSModulesDtsFile ( data . fileName , config . arbitraryExtensions )
141- ) ;
142- }
0 commit comments