({ file, source, map, options = {} })
| 39 | * @param {number} [$0.options.corejsVersion] |
| 40 | */ |
| 41 | export async function process ({ file, source, map, options = {} }) { |
| 42 | const { timings, start, end } = options.timings ? createPerformanceTimings() : noopTimings; |
| 43 | const { minify, downlevel, modernize } = options; |
| 44 | |
| 45 | const polyfills = new Set(); |
| 46 | let legacy; |
| 47 | |
| 48 | const outputOptions = { |
| 49 | compact: minify, |
| 50 | minified: minify, |
| 51 | // envName: minify ? 'production' : 'development', |
| 52 | comments: minify ? false : undefined, |
| 53 | generatorOpts: { |
| 54 | concise: true |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | start('modern'); |
| 59 | const modern = await babel.transformAsync(source, { |
| 60 | configFile: false, |
| 61 | babelrc: false, |
| 62 | filename: file, |
| 63 | inputSourceMap: map, |
| 64 | sourceMaps: true, |
| 65 | sourceFileName: file, |
| 66 | sourceType: 'module', |
| 67 | envName: 'modern', |
| 68 | // ast: true, |
| 69 | presets: [ |
| 70 | ['@babel/preset-env', { |
| 71 | loose: true, |
| 72 | modules: false, |
| 73 | bugfixes: true, |
| 74 | targets: { |
| 75 | esmodules: true |
| 76 | }, |
| 77 | // corejs: options.corejsVersion, |
| 78 | useBuiltIns: false |
| 79 | }], |
| 80 | modernize && ['babel-preset-modernize', { |
| 81 | loose: true, |
| 82 | webpack: true |
| 83 | }] |
| 84 | ].filter(Boolean), |
| 85 | ...outputOptions, |
| 86 | caller: { |
| 87 | supportsStaticESM: true, |
| 88 | name: NAME + '-modern' |
| 89 | } |
| 90 | }); |
| 91 | end('modern'); |
| 92 | |
| 93 | if (minify) { |
| 94 | start('modern-minify'); |
| 95 | const minified = await terser.minify(modern.code, { |
| 96 | // Enables shorthand properties in objects and object patterns: |
| 97 | ecma: 2017, |
| 98 | module: false, |
nothing calls this directly
no test coverage detected