1
1
import { extractICSS , IICSSExports } from 'icss-utils' ;
2
2
import * as postcss from 'postcss' ;
3
- import * as postcssIcssSelectors from 'postcss-icss-selectors' ;
4
3
import * as ts_module from 'typescript/lib/tsserverlibrary' ;
5
4
import * as less from 'less' ;
6
5
import * as sass from 'sass' ;
@@ -10,7 +9,6 @@ import { Options } from '../options';
10
9
import { Logger } from './Logger' ;
11
10
12
11
const NOT_CAMELCASE_REGEXP = / [ \- _ ] / ;
13
- const processor = postcss ( postcssIcssSelectors ( { mode : 'local' } ) ) ;
14
12
15
13
const classNameToProperty = ( className : string ) => `'${ className } ': string;` ;
16
14
const classNameToNamedExport = ( className : string ) =>
@@ -39,7 +37,7 @@ const getFilePath = (fileName: string) =>
39
37
export class DtsSnapshotCreator {
40
38
constructor ( private readonly logger : Logger ) { }
41
39
42
- getClasses ( css : string , fileName : string ) {
40
+ getClasses ( processor : postcss . Processor , css : string , fileName : string ) {
43
41
try {
44
42
const fileType = getFileType ( fileName ) ;
45
43
let transformedCss = '' ;
@@ -62,7 +60,9 @@ export class DtsSnapshotCreator {
62
60
63
61
const processedCss = processor . process ( transformedCss ) ;
64
62
65
- return extractICSS ( processedCss . root ) . icssExports ;
63
+ return processedCss . root
64
+ ? extractICSS ( processedCss . root ) . icssExports
65
+ : { } ;
66
66
} catch ( e ) {
67
67
this . logger . error ( e ) ;
68
68
return { } ;
@@ -97,12 +97,13 @@ export default classes;
97
97
98
98
getDtsSnapshot (
99
99
ts : typeof ts_module ,
100
+ processor : postcss . Processor ,
100
101
fileName : string ,
101
102
scriptSnapshot : ts . IScriptSnapshot ,
102
103
options : Options ,
103
104
) {
104
105
const css = scriptSnapshot . getText ( 0 , scriptSnapshot . getLength ( ) ) ;
105
- const classes = this . getClasses ( css , fileName ) ;
106
+ const classes = this . getClasses ( processor , css , fileName ) ;
106
107
const dts = this . createExports ( classes , options ) ;
107
108
return ts . ScriptSnapshot . fromString ( dts ) ;
108
109
}
0 commit comments