11import { extractICSS , IICSSExports } from 'icss-utils' ;
22import * as postcss from 'postcss' ;
3- import * as postcssIcssSelectors from 'postcss-icss-selectors' ;
43import * as ts_module from 'typescript/lib/tsserverlibrary' ;
54import * as less from 'less' ;
65import * as sass from 'sass' ;
@@ -10,7 +9,6 @@ import { Options } from '../options';
109import { Logger } from './Logger' ;
1110
1211const NOT_CAMELCASE_REGEXP = / [ \- _ ] / ;
13- const processor = postcss ( postcssIcssSelectors ( { mode : 'local' } ) ) ;
1412
1513const classNameToProperty = ( className : string ) => `'${ className } ': string;` ;
1614const classNameToNamedExport = ( className : string ) =>
@@ -39,7 +37,7 @@ const getFilePath = (fileName: string) =>
3937export class DtsSnapshotCreator {
4038 constructor ( private readonly logger : Logger ) { }
4139
42- getClasses ( css : string , fileName : string ) {
40+ getClasses ( processor : postcss . Processor , css : string , fileName : string ) {
4341 try {
4442 const fileType = getFileType ( fileName ) ;
4543 let transformedCss = '' ;
@@ -62,7 +60,9 @@ export class DtsSnapshotCreator {
6260
6361 const processedCss = processor . process ( transformedCss ) ;
6462
65- return extractICSS ( processedCss . root ) . icssExports ;
63+ return processedCss . root
64+ ? extractICSS ( processedCss . root ) . icssExports
65+ : { } ;
6666 } catch ( e ) {
6767 this . logger . error ( e ) ;
6868 return { } ;
@@ -97,12 +97,13 @@ export default classes;
9797
9898 getDtsSnapshot (
9999 ts : typeof ts_module ,
100+ processor : postcss . Processor ,
100101 fileName : string ,
101102 scriptSnapshot : ts . IScriptSnapshot ,
102103 options : Options ,
103104 ) {
104105 const css = scriptSnapshot . getText ( 0 , scriptSnapshot . getLength ( ) ) ;
105- const classes = this . getClasses ( css , fileName ) ;
106+ const classes = this . getClasses ( processor , css , fileName ) ;
106107 const dts = this . createExports ( classes , options ) ;
107108 return ts . ScriptSnapshot . fromString ( dts ) ;
108109 }
0 commit comments