@@ -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
@@ -753,7 +753,7 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {
753
753
let localeDataSource : Source | null = null ;
754
754
const localeDataPath = i18n . locales [ locale ] && i18n . locales [ locale ] . dataPath ;
755
755
if ( localeDataPath ) {
756
- const localeDataContent = await loadLocaleData ( localeDataPath , true ) ;
756
+ const localeDataContent = await loadLocaleData ( localeDataPath , true , options . es5 ) ;
757
757
localeDataSource = new OriginalSource ( localeDataContent , path . basename ( localeDataPath ) ) ;
758
758
}
759
759
@@ -870,19 +870,36 @@ function findLocalizePositions(
870
870
return positions ;
871
871
}
872
872
873
- async function loadLocaleData ( path : string , optimize : boolean ) : Promise < string > {
873
+ async function loadLocaleData ( path : string , optimize : boolean , es5 : boolean ) : Promise < string > {
874
874
// The path is validated during option processing before the build starts
875
875
const content = fs . readFileSync ( path , 'utf8' ) ;
876
876
877
- // NOTE: This can be removed once the locale data files are preprocessed in the framework
878
- if ( optimize ) {
879
- const result = await terserMangle ( content , {
880
- compress : true ,
881
- ecma : 5 ,
882
- } ) ;
877
+ // Downlevel and optimize the data
878
+ const transformResult = await transformAsync ( content , {
879
+ filename : path ,
880
+ // The types do not include the false option even though it is valid
881
+ // tslint:disable-next-line: no-any
882
+ inputSourceMap : false as any ,
883
+ babelrc : false ,
884
+ configFile : false ,
885
+ presets : [
886
+ [
887
+ require . resolve ( '@babel/preset-env' ) ,
888
+ {
889
+ bugfixes : true ,
890
+ // IE 9 is the oldest support browser
891
+ targets : es5 ? { ie : '9' } : { esmodules : true } ,
892
+ } ,
893
+ ] ,
894
+ ] ,
895
+ minified : allowMinify && optimize ,
896
+ compact : ! shouldBeautify && optimize ,
897
+ comments : ! optimize ,
898
+ } ) ;
883
899
884
- return result . code ;
900
+ if ( ! transformResult || ! transformResult . code ) {
901
+ throw new Error ( `Unknown error occurred processing bundle for "${ path } ".` ) ;
885
902
}
886
903
887
- return content ;
904
+ return transformResult . code ;
888
905
}
0 commit comments