File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
packages/repl/src/lib/workers/bundler/plugins Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -20,16 +20,31 @@ const plugin: Plugin = {
20
20
} ) ;
21
21
22
22
const requires : string [ ] = [ ] ;
23
+ const exports : string [ ] = [ ] ;
23
24
24
25
walk ( ast as Node , null , {
25
- CallExpression : ( node ) => {
26
+ CallExpression : ( node , context ) => {
26
27
if ( node . callee . type === 'Identifier' && node . callee . name === 'require' ) {
27
28
if ( node . arguments . length !== 1 ) return ;
28
29
const arg = node . arguments [ 0 ] ;
29
30
if ( arg . type !== 'Literal' || typeof arg . value !== 'string' ) return ;
30
31
31
32
requires . push ( arg . value ) ;
32
33
}
34
+
35
+ context . next ( ) ;
36
+ } ,
37
+ AssignmentExpression : ( node , context ) => {
38
+ if ( node . operator !== '=' ) return ;
39
+ if ( node . left . type !== 'MemberExpression' ) return ;
40
+ if ( node . left . object . type !== 'Identifier' || node . left . object . name !== 'exports' ) return ;
41
+ if ( node . left . computed || node . left . property . type !== 'Identifier' ) return ;
42
+
43
+ exports . push (
44
+ `export const ${ node . left . property . name } = module.exports.${ node . left . property . name } ;`
45
+ ) ;
46
+
47
+ context . next ( ) ;
33
48
}
34
49
} ) ;
35
50
@@ -44,7 +59,8 @@ const plugin: Plugin = {
44
59
require ,
45
60
`const exports = {}; const module = { exports };` ,
46
61
code ,
47
- `export default module.exports;`
62
+ `export default module.exports;` ,
63
+ exports . join ( '\n' )
48
64
] . join ( '\n\n' ) ;
49
65
50
66
return {
You can’t perform that action at this time.
0 commit comments