@@ -8,22 +8,28 @@ require.extensions['.js'] = function(module, filename) {
8
8
const exports = [ ] ;
9
9
10
10
let code = fs . readFileSync ( filename , 'utf-8' )
11
- . replace ( / ^ i m p o r t \* a s ( \w + ) f r o m [ ' " ] ( [ ^ ' " ] + ) [ ' " ] ; ? / gm, 'var $1 = require("$2");' )
12
- . replace ( / ^ i m p o r t ( \w + ) f r o m [ ' " ] ( [ ^ ' " ] + ) [ ' " ] ; ? / gm, 'var {default: $1} = require("$2");' )
13
- . replace ( / ^ i m p o r t { ( [ ^ } ] + ) } f r o m [ ' " ] ( .+ ) [ ' " ] ; ? / gm, 'var {$1} = require("$2");' )
14
- . replace ( / ^ e x p o r t d e f a u l t / gm, 'exports.default = ' )
15
- . replace ( / ^ e x p o r t ( c o n s t | l e t | v a r | c l a s s | f u n c t i o n ) ( \w + ) / gm, ( match , type , name ) => {
11
+ . replace ( / ^ i m p o r t \s + \* \s + a s \s + ( \w + ) \s + f r o m \s + ( [ ' " ] ) ( .+ ?) \2; ? / gm, 'var $1 = require($2$3$2);' )
12
+ . replace ( / ^ i m p o r t \s + ( \w + ) \s + f r o m \s + ( [ ' " ] ) ( .+ ?) \2; ? / gm, 'var {default: $1} = require($2$3$2);' )
13
+ . replace ( / ^ i m p o r t \s + (?: ( \w + ) \s * , \s * ) ? { ( [ ^ } ] + ) } (?: \s * , \s * ( \w + ) ) ? \s + f r o m \s + ( [ ' " ] ) ( .+ ?) \4; ? / gm,
14
+ ( match , default_name_1 , names , default_name_2 , quote , source ) => {
15
+ names = names . replace ( / \s + a s \s + / g, ': ' ) ;
16
+ let default_name = default_name_1 || default_name_2 ;
17
+ default_name = default_name ? `default: ${ default_name } , ` : '' ;
18
+ return `var {${ default_name } ${ names } } = require(${ quote } ${ source } ${ quote } );` ;
19
+ } )
20
+ . replace ( / ^ e x p o r t \s + d e f a u l t \s + / gm, 'exports.default = ' )
21
+ . replace ( / ^ e x p o r t \s + ( c o n s t | l e t | v a r | c l a s s | f u n c t i o n ) \s + ( \w + ) / gm, ( match , type , name ) => {
16
22
exports . push ( name ) ;
17
23
return `${ type } ${ name } ` ;
18
24
} )
19
- . replace ( / ^ e x p o r t \ {( [ ^ } ] + ) \} (?: f r o m [ ' " ] ( [ ^ ' " ] + ) [ ' " ] ; ? ) ? / gm, ( match , names , source ) => {
25
+ . replace ( / ^ e x p o r t \s + \ {( [ ^ } ] + ) \} (?: \s + f r o m \s + ( [ ' " ] ) ( . + ? ) \2 ; ? ) ? / gm, ( match , names , quote , source ) => {
20
26
names . split ( ',' ) . filter ( Boolean ) . forEach ( name => {
21
27
exports . push ( name ) ;
22
28
} ) ;
23
29
24
- return source ? `const { ${ names } } = require(" ${ source } " );` : '' ;
30
+ return source ? `const { ${ names } } = require(${ quote } ${ source } ${ quote } );` : '' ;
25
31
} )
26
- . replace ( / ^ e x p o r t f u n c t i o n ( \w + ) / gm, 'exports.$1 = function $1' ) ;
32
+ . replace ( / ^ e x p o r t \s + f u n c t i o n \s + ( \w + ) / gm, 'exports.$1 = function $1' ) ;
27
33
28
34
exports . forEach ( name => {
29
35
code += `\nexports.${ name } = ${ name } ;` ;
0 commit comments