@@ -34,9 +34,9 @@ export const processRenderResponse = (
34
34
. then (
35
35
(
36
36
result : Partial < RollupPluginSassProcessorFnOutput > ,
37
- ) : [ string , string , Record < string , string > ?] => {
37
+ ) : [ string , Record < string , unknown > , Record < string , string > ?] => {
38
38
if ( ! isObject ( result ) ) {
39
- return [ result , '' ] ;
39
+ return [ result , { } ] ;
40
40
}
41
41
42
42
if ( ! isString ( result . css ) ) {
@@ -55,18 +55,8 @@ export const processRenderResponse = (
55
55
) ;
56
56
}
57
57
58
- const { css : outCss , cssModules } = result ;
59
-
60
- // Remove "reserved" keys to avoid to add them inside additional exports
61
- delete result . css ;
62
- delete result . cssModules ;
63
-
64
- const namedExports = Object . keys ( result ) . reduce (
65
- ( agg , name ) =>
66
- agg + `export const ${ name } = ${ JSON . stringify ( result [ name ] ) } ;\n` ,
67
- '' ,
68
- ) ;
69
- return [ outCss , namedExports , cssModules ] as const ;
58
+ const { css, cssModules, ...namedExports } = result ;
59
+ return [ css , namedExports , cssModules ] ;
70
60
} ,
71
61
)
72
62
@@ -99,14 +89,18 @@ export const processRenderResponse = (
99
89
path . basename ( fileId , path . extname ( fileId ) ) ,
100
90
) ;
101
91
102
- const codeOutput = [
92
+ const codeOutput : string [ ] = [
103
93
...imports ,
94
+
104
95
`var ${ variableName } = ${ defaultExport } ;` ,
105
96
`export default ${ cssModules ? JSON . stringify ( cssModules ) : variableName } ;` ,
106
- namedExports ,
107
- ] . join ( '\n' ) ;
108
97
109
- return codeOutput ;
98
+ ...Object . entries ( namedExports ) . map (
99
+ ( [ n , v ] ) => `export const ${ n } = ${ JSON . stringify ( v ) } ;` ,
100
+ ) ,
101
+ ] ;
102
+
103
+ return codeOutput . join ( '\n' ) ;
110
104
} )
111
105
) ; // @note do not `catch` here - let error propagate to rollup level
112
106
} ;
0 commit comments