@@ -634,7 +634,7 @@ export async function inlineLocales(options: InlineOptions) {
634
634
// If locale data is provided, load it and prepend to file
635
635
const localeDataPath = i18n . locales [ locale ] ?. dataPath ;
636
636
if ( localeDataPath ) {
637
- localeDataContent = await loadLocaleData ( localeDataPath , true ) ;
637
+ localeDataContent = await loadLocaleData ( localeDataPath , true , options . es5 ) ;
638
638
}
639
639
}
640
640
@@ -748,7 +748,7 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {
748
748
let localeDataSource : Source | null = null ;
749
749
const localeDataPath = i18n . locales [ locale ] && i18n . locales [ locale ] . dataPath ;
750
750
if ( localeDataPath ) {
751
- const localeDataContent = await loadLocaleData ( localeDataPath , true ) ;
751
+ const localeDataContent = await loadLocaleData ( localeDataPath , true , options . es5 ) ;
752
752
localeDataSource = new OriginalSource ( localeDataContent , path . basename ( localeDataPath ) ) ;
753
753
}
754
754
@@ -854,19 +854,36 @@ function findLocalizePositions(
854
854
return positions ;
855
855
}
856
856
857
- async function loadLocaleData ( path : string , optimize : boolean ) : Promise < string > {
857
+ async function loadLocaleData ( path : string , optimize : boolean , es5 : boolean ) : Promise < string > {
858
858
// The path is validated during option processing before the build starts
859
859
const content = fs . readFileSync ( path , 'utf8' ) ;
860
860
861
- // NOTE: This can be removed once the locale data files are preprocessed in the framework
862
- if ( optimize ) {
863
- const result = await terserMangle ( content , {
864
- compress : true ,
865
- ecma : 5 ,
866
- } ) ;
861
+ // Downlevel and optimize the data
862
+ const transformResult = await transformAsync ( content , {
863
+ filename : path ,
864
+ // The types do not include the false option even though it is valid
865
+ // tslint:disable-next-line: no-any
866
+ inputSourceMap : false as any ,
867
+ babelrc : false ,
868
+ configFile : false ,
869
+ presets : [
870
+ [
871
+ require . resolve ( '@babel/preset-env' ) ,
872
+ {
873
+ bugfixes : true ,
874
+ // IE 9 is the oldest supported browser
875
+ targets : es5 ? { ie : '9' } : { esmodules : true } ,
876
+ } ,
877
+ ] ,
878
+ ] ,
879
+ minified : allowMinify && optimize ,
880
+ compact : ! shouldBeautify && optimize ,
881
+ comments : ! optimize ,
882
+ } ) ;
867
883
868
- return result . code ;
884
+ if ( ! transformResult || ! transformResult . code ) {
885
+ throw new Error ( `Unknown error occurred processing bundle for "${ path } ".` ) ;
869
886
}
870
887
871
- return content ;
888
+ return transformResult . code ;
872
889
}
0 commit comments