@@ -164,6 +164,8 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
164
164
const isDebug =
165
165
debugFlags . includes ( 'vite:*' ) || debugFlags . includes ( 'vite:legacy' )
166
166
167
+ const assumptions = options . assumptions || { }
168
+
167
169
const facadeToLegacyChunkMap = new Map ( )
168
170
const facadeToLegacyPolyfillMap = new Map ( )
169
171
const facadeToModernPolyfillMap = new Map ( )
@@ -338,6 +340,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
338
340
await detectPolyfills (
339
341
`Promise.resolve(); Promise.all();` ,
340
342
targets ,
343
+ assumptions ,
341
344
legacyPolyfills ,
342
345
)
343
346
}
@@ -490,7 +493,12 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
490
493
genModern
491
494
) {
492
495
// analyze and record modern polyfills
493
- await detectPolyfills ( raw , modernTargets , polyfillsDiscovered . modern )
496
+ await detectPolyfills (
497
+ raw ,
498
+ modernTargets ,
499
+ assumptions ,
500
+ polyfillsDiscovered . modern ,
501
+ )
494
502
}
495
503
496
504
const ms = new MagicString ( raw )
@@ -555,6 +563,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
555
563
compact : ! ! config . build . minify ,
556
564
sourceMaps,
557
565
inputSourceMap : undefined ,
566
+ assumptions,
558
567
presets : [
559
568
// forcing our plugin to run before preset-env by wrapping it in a
560
569
// preset so we can catch the injected import statements...
@@ -735,6 +744,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
735
744
export async function detectPolyfills (
736
745
code : string ,
737
746
targets : any ,
747
+ assumptions : Record < string , boolean > ,
738
748
list : Set < string > ,
739
749
) : Promise < void > {
740
750
const babel = await loadBabel ( )
@@ -743,6 +753,7 @@ export async function detectPolyfills(
743
753
babelrc : false ,
744
754
configFile : false ,
745
755
compact : false ,
756
+ assumptions,
746
757
presets : [
747
758
[
748
759
( await import ( '@babel/preset-env' ) ) . default ,
0 commit comments