1
1
"use strict" ;
2
2
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
3
+ var querystring_1 = require ( "querystring" ) ;
3
4
var loader = function ( source ) {
4
5
if ( this . version && Number ( this . version ) >= 2 ) {
5
6
try {
6
7
this . cacheable && this . cacheable ( ) ;
7
- this . callback ( null , "module.exports = " + generateCode ( source ) ) ;
8
+ this . callback ( null , "module.exports = " + generateCode ( source , querystring_1 . parse ( this . resourceQuery ) ) ) ;
8
9
}
9
10
catch ( err ) {
10
11
this . emitError ( err . message ) ;
@@ -17,11 +18,20 @@ var loader = function (source) {
17
18
this . callback ( new Error ( message ) ) ;
18
19
}
19
20
} ;
20
- function generateCode ( source ) {
21
+ function generateCode ( source , query ) {
22
+ var _a ;
21
23
var code = '' ;
22
24
var value = typeof source === 'string'
23
25
? JSON . parse ( source )
24
- : source ;
26
+ : Buffer . isBuffer ( source )
27
+ ? JSON . parse ( source . toString ( ) )
28
+ : null ;
29
+ if ( value === null ) {
30
+ throw new Error ( 'invalid source!' ) ;
31
+ }
32
+ if ( query . locale && typeof query . locale === 'string' ) {
33
+ value = Object . assign ( { } , ( _a = { } , _a [ query . locale ] = value , _a ) ) ;
34
+ }
25
35
value = JSON . stringify ( value )
26
36
. replace ( / \u2028 / g, '\\u2028' )
27
37
. replace ( / \u2029 / g, '\\u2029' )
0 commit comments