( code: string, targets: any, assumptions: Record<string, boolean>, list: Set<string>, )
| 825 | } |
| 826 | |
| 827 | export 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 | |
| 873 | async function buildPolyfillChunk( |
| 874 | ctx: Rollup.PluginContext, |
no test coverage detected