@@ -18,7 +18,10 @@ import type {
18
18
PreRenderedChunk ,
19
19
RenderedChunk ,
20
20
} from 'rollup'
21
- import type { PluginItem as BabelPlugin } from '@babel/core'
21
+ import type {
22
+ PluginItem as BabelPlugin ,
23
+ types as BabelTypes ,
24
+ } from '@babel/core'
22
25
import colors from 'picocolors'
23
26
import type { Options } from './types'
24
27
@@ -387,23 +390,22 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
387
390
return null
388
391
}
389
392
390
- // @ts -ignore avoid esbuild transform on legacy chunks since it produces
393
+ // @ts -expect-error avoid esbuild transform on legacy chunks since it produces
391
394
// legacy-unsafe code - e.g. rewriting object properties into shorthands
392
395
opts . __vite_skip_esbuild__ = true
393
396
394
- // @ts -ignore force terser for legacy chunks. This only takes effect if
397
+ // @ts -expect-error force terser for legacy chunks. This only takes effect if
395
398
// minification isn't disabled, because that leaves out the terser plugin
396
399
// entirely.
397
400
opts . __vite_force_terser__ = true
398
401
399
- // @ts -ignore
400
- // In the `generateBundle` hook,
402
+ // @ts -expect-error In the `generateBundle` hook,
401
403
// we'll delete the assets from the legacy bundle to avoid emitting duplicate assets.
402
404
// But that's still a waste of computing resource.
403
405
// So we add this flag to avoid emitting the asset in the first place whenever possible.
404
406
opts . __vite_skip_asset_emit__ = true
405
407
406
- // @ts -ignore avoid emitting assets for legacy bundle
408
+ // avoid emitting assets for legacy bundle
407
409
const needPolyfills =
408
410
options . polyfills !== false && ! Array . isArray ( options . polyfills )
409
411
@@ -752,12 +754,11 @@ function isLegacyBundle(
752
754
function recordAndRemovePolyfillBabelPlugin (
753
755
polyfills : Set < string > ,
754
756
) : BabelPlugin {
755
- return ( { types : t } ) : BabelPlugin => ( {
757
+ return ( { types : t } : { types : typeof BabelTypes } ) : BabelPlugin => ( {
756
758
name : 'vite-remove-polyfill-import' ,
757
759
post ( { path } ) {
758
760
path . get ( 'body' ) . forEach ( ( p ) => {
759
- if ( t . isImportDeclaration ( p ) ) {
760
- // @ts -expect-error
761
+ if ( t . isImportDeclaration ( p . node ) ) {
761
762
polyfills . add ( p . node . source . value )
762
763
p . remove ( )
763
764
}
0 commit comments