MCPcopy
hub / github.com/vitejs/vite / detectPolyfills

Function detectPolyfills

packages/plugin-legacy/src/index.ts:827–871  ·  view source on GitHub ↗
(
  code: string,
  targets: any,
  assumptions: Record<string, boolean>,
  list: Set<string>,
)

Source from the content-addressed store, hash-verified

825}
826
827export async function detectPolyfills(
828 code: string,
829 targets: any,
830 assumptions: Record<string, boolean>,
831 list: Set<string>,
832): Promise<void> {
833 const babel = await loadBabel()
834 const result = babel.transform(code, {
835 ast: true,
836 code: false,
837 babelrc: false,
838 configFile: false,
839 compact: false,
840 targets,
841 assumptions,
842 browserslistConfigFile: false,
843 plugins: [
844 [
845 (await import('babel-plugin-polyfill-corejs3')).default,
846 {
847 method: 'usage-global',
848 version: _require('core-js/package.json').version,
849 shippedProposals: true,
850 },
851 ],
852 [
853 (await import('babel-plugin-polyfill-regenerator')).default,
854 {
855 method: 'usage-global',
856 },
857 ],
858 ],
859 })
860 for (const node of result!.ast!.program.body) {
861 if (node.type === 'ImportDeclaration') {
862 const source = node.source.value
863 if (
864 source.startsWith('core-js/') ||
865 source.startsWith('regenerator-runtime/')
866 ) {
867 list.add(source)
868 }
869 }
870 }
871}
872
873async function buildPolyfillChunk(
874 ctx: Rollup.PluginContext,

Callers 2

generateBundleFunction · 0.85
renderChunkFunction · 0.85

Calls 3

loadBabelFunction · 0.85
addMethod · 0.80
transformMethod · 0.45

Tested by

no test coverage detected