1
1
import replace from '@rollup/plugin-replace' ;
2
- import { parse } from 'acorn' ;
2
+ import { Options , parse } from 'acorn' ;
3
3
import { rollup } from 'rollup' ;
4
4
import { minify } from 'terser' ;
5
5
@@ -32,7 +32,10 @@ const resolvePlugin = ({ code }) => ({
32
32
} ,
33
33
} ) ;
34
34
35
- export const treeshakeWithRollup = ( code : string ) : Promise < Output > => {
35
+ export const treeshakeWithRollup = (
36
+ code : string ,
37
+ parseOptions ?: Options ,
38
+ ) : Promise < Output > => {
36
39
const config = {
37
40
name : 'rollup-plugin-size-snapshot-vite' ,
38
41
input : `/${ inputName } ` ,
@@ -54,21 +57,23 @@ export const treeshakeWithRollup = (code: string): Promise<Output> => {
54
57
} ,
55
58
) ,
56
59
)
57
- . then (
58
- ( result ) : Output => {
59
- const { code = '' } = result ;
60
- const ast = parse ( code , { sourceType : 'module' } ) as any ;
61
- const import_statements = ast . body
62
- // collect all toplevel import statements
63
- . filter ( ( node ) => node . type === 'ImportDeclaration' )
64
- // endpos is the next character after node -> substract 1
65
- . map ( ( node ) => node . end - node . start )
66
- . reduce ( ( acc , size ) => acc + size , 0 ) ;
60
+ . then ( ( result ) : Output => {
61
+ const { code = '' } = result ;
62
+ const ast = parse ( code , {
63
+ sourceType : 'module' ,
64
+ ecmaVersion : 11 ,
65
+ ...parseOptions ,
66
+ } ) as any ;
67
+ const import_statements = ast . body
68
+ // collect all toplevel import statements
69
+ . filter ( ( node ) => node . type === 'ImportDeclaration' )
70
+ // endpos is the next character after node -> substract 1
71
+ . map ( ( node ) => node . end - node . start )
72
+ . reduce ( ( acc , size ) => acc + size , 0 ) ;
67
73
68
- return {
69
- code : code . length ,
70
- import_statements,
71
- } ;
72
- } ,
73
- ) ;
74
+ return {
75
+ code : code . length ,
76
+ import_statements,
77
+ } ;
78
+ } ) ;
74
79
} ;
0 commit comments