1
1
import type { LoaderDefinitionFunction } from 'webpack/types'
2
2
3
- import { parseQuery , OptionObject } from 'loader-utils'
4
-
5
- function generateCode ( rawData : string , query : OptionObject , hot = false ) : string {
3
+ function generateCode ( rawData : string , query : URLSearchParams , hot = false ) : string {
6
4
// vue-loader pads SFC file sections with newlines - trim those
7
5
const data = rawData . replace ( / ^ ( \n | \r \n ) + | ( \n | \r \n ) + $ / g, '' )
8
6
9
- if ( typeof query . locale !== 'string' ) {
7
+ const locale = query . get ( 'locale' )
8
+ if ( typeof locale !== 'string' ) {
10
9
throw new Error ( 'Custom block does not have locale attribute' )
11
10
}
12
11
@@ -33,14 +32,15 @@ import { FluentResource } from '@fluent/bundle'
33
32
export default function (Component) {
34
33
const target = Component.options || Component
35
34
target.fluent = target.fluent || {}
36
- target.fluent['${ query . locale } '] = new FluentResource(\`${ data } \`)
35
+ target.fluent['${ locale } '] = new FluentResource(\`${ data } \`)
37
36
${ hotCode }
38
37
}\n`
39
38
}
40
39
41
40
const loader : LoaderDefinitionFunction = function ( this , source , sourceMap ) {
42
41
try {
43
- this . callback ( null , generateCode ( source , parseQuery ( this . resourceQuery ) , this . hot ) , sourceMap )
42
+ const options = new URLSearchParams ( this . resourceQuery . slice ( 1 ) )
43
+ this . callback ( null , generateCode ( source , options , this . hot ) , sourceMap )
44
44
} catch ( err ) {
45
45
this . emitError ( err as Error )
46
46
this . callback ( err as Error )
0 commit comments