8
8
BASE_URI ,
9
9
SINGLE_DOT_PATH_SEGMENT ,
10
10
stringifyRequest,
11
+ stringifyLocal,
11
12
} = require ( "./utils" ) ;
12
13
const schema = require ( "./loader-options.json" ) ;
13
14
@@ -22,6 +23,7 @@ const MiniCssExtractPlugin = require("./index");
22
23
/** @typedef {import("webpack").AssetInfo } AssetInfo */
23
24
/** @typedef {import("webpack").NormalModule } NormalModule */
24
25
/** @typedef {import("./index.js").LoaderOptions } LoaderOptions */
26
+ /** @typedef {{ [key: string]: string | function } | function } Locals */
25
27
26
28
/** @typedef {any } TODO */
27
29
@@ -38,7 +40,7 @@ const MiniCssExtractPlugin = require("./index");
38
40
39
41
/**
40
42
* @param {string } content
41
- * @param {{ loaderContext: import("webpack").LoaderContext<LoaderOptions>, options: LoaderOptions, locals: {[key: string]: string } | undefined } } context
43
+ * @param {{ loaderContext: import("webpack").LoaderContext<LoaderOptions>, options: LoaderOptions, locals: Locals | undefined } } context
42
44
* @returns {string }
43
45
*/
44
46
function hotLoader ( content , context ) {
@@ -95,7 +97,7 @@ function pitch(request) {
95
97
* @returns {void }
96
98
*/
97
99
const handleExports = ( originalExports , compilation , assets , assetsInfo ) => {
98
- /** @type {{[key: string]: string } | undefined } */
100
+ /** @type {Locals | undefined } */
99
101
let locals ;
100
102
let namedExport ;
101
103
@@ -170,7 +172,8 @@ function pitch(request) {
170
172
locals = { } ;
171
173
}
172
174
173
- locals [ key ] = originalExports [ key ] ;
175
+ /** @type {{ [key: string]: string } } */ ( locals ) [ key ] =
176
+ originalExports [ key ] ;
174
177
}
175
178
} ) ;
176
179
} else {
@@ -228,15 +231,14 @@ function pitch(request) {
228
231
? Object . keys ( locals )
229
232
. map (
230
233
( key ) =>
231
- `\nexport var ${ key } = ${ JSON . stringify (
232
- /** @type {{[key: string]: string } } */
233
- ( locals ) [ key ]
234
+ `\nexport var ${ key } = ${ stringifyLocal (
235
+ /** @type {{ [key: string]: string } } */ ( locals ) [ key ]
234
236
) } ;`
235
237
)
236
238
. join ( "" )
237
239
: `\n${
238
240
esModule ? "export default" : "module.exports ="
239
- } ${ JSON . stringify ( locals ) } ;`
241
+ } ${ stringifyLocal ( /** @type { function } */ ( locals ) ) } ;`
240
242
: esModule
241
243
? `\nexport {};`
242
244
: "" ;
0 commit comments