@@ -19,57 +19,46 @@ import type { CodeGenerator, CodeGenFunction, CodeGenOptions, CodeGenResult } fr
1919
2020export class DynamicResourceError extends Error { }
2121
22+ /**
23+ * @internal
24+ */
25+ export const DEFAULT_OPTIONS : CodeGenOptions = {
26+ type : 'plain' ,
27+ filename : 'vue-i18n-loader.js' ,
28+ inSourceMap : undefined ,
29+ locale : '' ,
30+ isGlobal : false ,
31+ sourceMap : false ,
32+ env : 'development' ,
33+ forceStringify : false ,
34+ onError : undefined ,
35+ onWarn : undefined ,
36+ strictMessage : true ,
37+ escapeHtml : false ,
38+ allowDynamic : false ,
39+ jit : false
40+ }
41+
2242/**
2343 * @internal
2444 */
2545export function generate (
2646 targetSource : string | Buffer ,
27- {
28- type = 'plain' ,
29- filename = 'vue-i18n-loader.js' ,
30- inSourceMap = undefined ,
31- locale = '' ,
32- isGlobal = false ,
33- sourceMap = false ,
34- env = 'development' ,
35- forceStringify = false ,
36- onError = undefined ,
37- onWarn = undefined ,
38- strictMessage = true ,
39- escapeHtml = false ,
40- allowDynamic = false ,
41- jit = false
42- } : CodeGenOptions
47+ options : CodeGenOptions
4348) : CodeGenResult < Node > {
4449 const value = Buffer . isBuffer ( targetSource ) ? targetSource . toString ( ) : targetSource
4550
46- const options = {
47- type,
48- source : value ,
49- sourceMap,
50- locale,
51- isGlobal,
52- inSourceMap,
53- env,
54- filename,
55- forceStringify,
56- onError,
57- onWarn,
58- strictMessage,
59- escapeHtml,
60- jit
61- } as CodeGenOptions
62- const generator = createCodeGenerator ( options )
63-
51+ const _options = Object . assign ( { } , DEFAULT_OPTIONS , options , { source : value } )
52+ const generator = createCodeGenerator ( _options )
6453 const ast = parseJavaScript ( value , {
6554 ecmaVersion : 'latest' ,
6655 sourceType : 'module' ,
67- sourceFile : filename ,
56+ sourceFile : _options . filename ,
6857 allowImportExportEverywhere : true
6958 } ) as Node
7059
7160 const exportResult = scanAst ( ast )
72- if ( ! allowDynamic ) {
61+ if ( ! _options . allowDynamic ) {
7362 if ( ! exportResult ) {
7463 throw new Error ( `You need to define an object as the locale message with 'export default'.` )
7564 }
@@ -95,17 +84,17 @@ export function generate(
9584 return {
9685 ast,
9786 code : value ,
98- map : inSourceMap
87+ map : _options . inSourceMap
9988 }
10089 }
10190 }
10291
103- const codeMaps = _generate ( generator , ast , options )
92+ const codeMaps = _generate ( generator , ast , _options )
10493
10594 const { code, map } = generator . context ( )
10695 // prettier-ignore
10796 const newMap = map
108- ? mapLinesColumns ( ( map as any ) . toJSON ( ) , codeMaps , inSourceMap ) || null
97+ ? mapLinesColumns ( ( map as any ) . toJSON ( ) , codeMaps , _options . inSourceMap ) || null
10998 : null
11099 return {
111100 ast,
@@ -162,7 +151,7 @@ function _generate(
162151 const componentNamespace = '_Component'
163152 const variableDeclarations : string [ ] = [ ]
164153
165- // slice and reseuse imports and top-level variable declarations as-is
154+ // slice and reuse imports and top-level variable declarations as-is
166155 // NOTE: this prevents optimization/compilation of top-level variables, we may be able to add support for this
167156 walk ( node , {
168157 /**
0 commit comments