(raw, chunk, opts, { chunks })
| 480 | }, |
| 481 | |
| 482 | async renderChunk(raw, chunk, opts, { chunks }) { |
| 483 | if (config.build.ssr) { |
| 484 | return null |
| 485 | } |
| 486 | |
| 487 | // On first run, initialize the map with sorted chunk file names |
| 488 | let chunkFileNameToPolyfills = outputToChunkFileNameToPolyfills.get(opts) |
| 489 | if (chunkFileNameToPolyfills == null) { |
| 490 | chunkFileNameToPolyfills = new Map() |
| 491 | for (const fileName in chunks) { |
| 492 | chunkFileNameToPolyfills.set(fileName, { |
| 493 | modern: new Set(), |
| 494 | legacy: new Set(), |
| 495 | }) |
| 496 | } |
| 497 | outputToChunkFileNameToPolyfills.set(opts, chunkFileNameToPolyfills) |
| 498 | } |
| 499 | const polyfillsDiscovered = chunkFileNameToPolyfills.get(chunk.fileName) |
| 500 | if (polyfillsDiscovered == null) { |
| 501 | throw new Error( |
| 502 | `Internal @vitejs/plugin-legacy error: discovered polyfills for ${chunk.fileName} should exist`, |
| 503 | ) |
| 504 | } |
| 505 | |
| 506 | if (!isLegacyChunk(chunk)) { |
| 507 | if ( |
| 508 | options.modernPolyfills && |
| 509 | !Array.isArray(options.modernPolyfills) && |
| 510 | genModern |
| 511 | ) { |
| 512 | // analyze and record modern polyfills |
| 513 | await detectPolyfills( |
| 514 | raw, |
| 515 | modernTargets, |
| 516 | assumptions, |
| 517 | polyfillsDiscovered.modern, |
| 518 | ) |
| 519 | } |
| 520 | |
| 521 | const ms = new MagicString(raw) |
| 522 | |
| 523 | if (genLegacy && chunk.isEntry) { |
| 524 | // append this code to avoid modern chunks running on legacy targeted browsers |
| 525 | ms.prepend(createModernChunkLegacyGuard(chunk.fileName)) |
| 526 | } |
| 527 | |
| 528 | if (raw.includes(legacyEnvVarMarker)) { |
| 529 | const re = new RegExp(legacyEnvVarMarker, 'g') |
| 530 | let match |
| 531 | while ((match = re.exec(raw))) { |
| 532 | ms.overwrite( |
| 533 | match.index, |
| 534 | match.index + legacyEnvVarMarker.length, |
| 535 | `false`, |
| 536 | ) |
| 537 | } |
| 538 | } |
| 539 |
nothing calls this directly
no test coverage detected