@@ -634,7 +634,7 @@ export async function inlineLocales(options: InlineOptions) {
634634 // If locale data is provided, load it and prepend to file
635635 const localeDataPath = i18n . locales [ locale ] ?. dataPath ;
636636 if ( localeDataPath ) {
637- localeDataContent = await loadLocaleData ( localeDataPath , true ) ;
637+ localeDataContent = await loadLocaleData ( localeDataPath , true , options . es5 ) ;
638638 }
639639 }
640640
@@ -748,7 +748,7 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {
748748 let localeDataSource : Source | null = null ;
749749 const localeDataPath = i18n . locales [ locale ] && i18n . locales [ locale ] . dataPath ;
750750 if ( localeDataPath ) {
751- const localeDataContent = await loadLocaleData ( localeDataPath , true ) ;
751+ const localeDataContent = await loadLocaleData ( localeDataPath , true , options . es5 ) ;
752752 localeDataSource = new OriginalSource ( localeDataContent , path . basename ( localeDataPath ) ) ;
753753 }
754754
@@ -854,19 +854,36 @@ function findLocalizePositions(
854854 return positions ;
855855}
856856
857- async function loadLocaleData ( path : string , optimize : boolean ) : Promise < string > {
857+ async function loadLocaleData ( path : string , optimize : boolean , es5 : boolean ) : Promise < string > {
858858 // The path is validated during option processing before the build starts
859859 const content = fs . readFileSync ( path , 'utf8' ) ;
860860
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+ } ) ;
867883
868- return result . code ;
884+ if ( ! transformResult || ! transformResult . code ) {
885+ throw new Error ( `Unknown error occurred processing bundle for "${ path } ".` ) ;
869886 }
870887
871- return content ;
888+ return transformResult . code ;
872889}
0 commit comments