11import type { LoaderDefinitionFunction } from 'webpack/types'
22
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 {
64 // vue-loader pads SFC file sections with newlines - trim those
75 const data = rawData . replace ( / ^ ( \n | \r \n ) + | ( \n | \r \n ) + $ / g, '' )
86
9- if ( typeof query . locale !== 'string' ) {
7+ const locale = query . get ( 'locale' )
8+ if ( typeof locale !== 'string' ) {
109 throw new Error ( 'Custom block does not have locale attribute' )
1110 }
1211
@@ -33,14 +32,15 @@ import { FluentResource } from '@fluent/bundle'
3332export default function (Component) {
3433 const target = Component.options || Component
3534 target.fluent = target.fluent || {}
36- target.fluent['${ query . locale } '] = new FluentResource(\`${ data } \`)
35+ target.fluent['${ locale } '] = new FluentResource(\`${ data } \`)
3736 ${ hotCode }
3837}\n`
3938}
4039
4140const loader : LoaderDefinitionFunction = function ( this , source , sourceMap ) {
4241 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 )
4444 } catch ( err ) {
4545 this . emitError ( err as Error )
4646 this . callback ( err as Error )
0 commit comments