@@ -94,40 +94,49 @@ describe('generateDts', () => {
9494 "
9595 ` ) ;
9696 } ) ;
97- test ( 'does not generate types for external files ' , async ( ) => {
97+ test ( 'does not generate `@import` types for unmatched or unresolvable modules ' , async ( ) => {
9898 const iff = await createIFF ( {
9999 'test.module.css' : dedent `
100- @import './external .css';
101- @value imported from './external .css';
100+ @import './unmatched.module .css';
101+ @import './unresolvable.module .css';
102102 ` ,
103- 'external. css' : '' ,
103+ 'unmatched.module. css' : '.unmatched_1 { color: red; } ' ,
104104 } ) ;
105+ // FIXME: Currently, the type for unresolvable modules is still generated.
105106 expect (
106107 generateDts (
107108 readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! ,
108- { ...host , matchesPattern : ( path ) => path . endsWith ( '.module.css' ) } ,
109+ { ...host , matchesPattern : ( path ) => path . endsWith ( '.module.css' ) && ! path . endsWith ( 'unmatched.module.css' ) } ,
109110 options ,
110111 ) . text ,
111112 ) . toMatchInlineSnapshot ( `
112113 "// @ts-nocheck
113114 declare const styles = {
115+ ...(await import('./unresolvable.module.css')).default,
114116 };
115117 export default styles;
116118 "
117119 ` ) ;
118120 } ) ;
119- test ( 'does not generate types for unresolved files ' , async ( ) => {
121+ test ( 'generates `@value` types for unmatched or unresolvable modules ' , async ( ) => {
120122 const iff = await createIFF ( {
121123 'test.module.css' : dedent `
122- @import '@/a.module.css';
124+ @value unmatched_1 from './unmatched.module.css';
125+ @value unresolvable_1 from './unresolvable.module.css';
123126 ` ,
127+ 'unmatched.module.css' : '.unmatched_1 { color: red; }' ,
124128 } ) ;
125- const resolver = ( _specifier : string ) => undefined ;
129+ // FIXME: Currently, the type for unmatched modules is missing.
126130 expect (
127- generateDts ( readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! , { ...host , resolver } , options ) . text ,
131+ generateDts (
132+ readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! ,
133+ { ...host , matchesPattern : ( path ) => path . endsWith ( '.module.css' ) && ! path . endsWith ( 'unmatched.module.css' ) } ,
134+ options ,
135+ ) . text ,
128136 ) . toMatchInlineSnapshot ( `
129137 "// @ts-nocheck
130138 declare const styles = {
139+ unresolvable_1: (await import('./unresolvable.module.css')).default.unresolvable_1,
131140 };
132141 export default styles;
133142 "
@@ -145,9 +154,8 @@ describe('generateDts', () => {
145154 @value b_2: red;
146155 ` ,
147156 } ) ;
148- expect (
149- generateDts ( readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! , host , options ) . text ,
150- ) . toMatchInlineSnapshot ( `
157+ expect ( generateDts ( readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! , host , options ) . text )
158+ . toMatchInlineSnapshot ( `
151159 "// @ts-nocheck
152160 declare const styles = {
153161 };
@@ -159,9 +167,8 @@ describe('generateDts', () => {
159167 const iff = await createIFF ( {
160168 'test.module.css' : '.__proto__ { color: red; }' ,
161169 } ) ;
162- expect (
163- generateDts ( readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! , host , options ) . text ,
164- ) . toMatchInlineSnapshot ( `
170+ expect ( generateDts ( readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! , host , options ) . text )
171+ . toMatchInlineSnapshot ( `
165172 "// @ts-nocheck
166173 declare const styles = {
167174 };
@@ -174,21 +181,13 @@ describe('generateDts', () => {
174181 'test.module.css' : '.default { color: red; }' ,
175182 } ) ;
176183 expect (
177- generateDts (
178- readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! ,
179- host ,
180- { ...options , namedExports : true } ,
181- ) . text ,
184+ generateDts ( readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! , host , { ...options , namedExports : true } ) . text ,
182185 ) . toMatchInlineSnapshot ( `
183186 "// @ts-nocheck
184187 "
185188 ` ) ;
186189 expect (
187- generateDts (
188- readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! ,
189- host ,
190- { ...options , namedExports : false } ,
191- ) . text ,
190+ generateDts ( readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! , host , { ...options , namedExports : false } ) . text ,
192191 ) . toMatchInlineSnapshot ( `
193192 "// @ts-nocheck
194193 declare const styles = {
@@ -213,11 +212,7 @@ describe('generateDts', () => {
213212 ` ,
214213 } ) ;
215214 expect (
216- generateDts (
217- readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! ,
218- host ,
219- { ...options , namedExports : true } ,
220- ) . text ,
215+ generateDts ( readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! , host , { ...options , namedExports : true } ) . text ,
221216 ) . toMatchInlineSnapshot ( `
222217 "// @ts-nocheck
223218 export var local1: string;
@@ -235,11 +230,12 @@ describe('generateDts', () => {
235230 'test.module.css' : '.local1 { color: red; }' ,
236231 } ) ;
237232 expect (
238- generateDts (
239- readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! ,
240- host ,
241- { ...options , namedExports : true , forTsPlugin : true , prioritizeNamedImports : false } ,
242- ) . text ,
233+ generateDts ( readAndParseCSSModule ( iff . paths [ 'test.module.css' ] ) ! , host , {
234+ ...options ,
235+ namedExports : true ,
236+ forTsPlugin : true ,
237+ prioritizeNamedImports : false ,
238+ } ) . text ,
243239 ) . toMatchInlineSnapshot ( `
244240 "// @ts-nocheck
245241 export var local1: string;
0 commit comments