@@ -29,11 +29,18 @@ function isIrreducible(node: substituterNodes) {
29
29
return irreducibleTypes . has ( node . type )
30
30
}
31
31
32
+ type irreducibleNodes =
33
+ | es . Identifier
34
+ | es . FunctionExpression
35
+ | es . ArrowFunctionExpression
36
+ | es . Literal
37
+ | es . ArrayExpression
38
+
32
39
/* tslint:disable:no-shadowed-variable */
33
40
// wrapper function, calls substitute immediately.
34
41
function substituteMain (
35
42
name : es . Identifier ,
36
- replacement : es . FunctionExpression | es . Literal | es . ArrowFunctionExpression ,
43
+ replacement : irreducibleNodes ,
37
44
target : substituterNodes
38
45
) : substituterNodes {
39
46
const seenBefore : Map < substituterNodes , substituterNodes > = new Map ( )
@@ -281,7 +288,7 @@ function substituteMain(
281
288
*/
282
289
function apply (
283
290
callee : es . FunctionExpression | es . ArrowFunctionExpression ,
284
- args : Array < es . Identifier | es . Literal | es . FunctionExpression | es . ArrowFunctionExpression >
291
+ args : irreducibleNodes [ ]
285
292
) : BlockExpression | es . Expression {
286
293
let substedBody = callee . body
287
294
for ( let i = 0 ; i < args . length ; i ++ ) {
@@ -543,10 +550,10 @@ const reducers = {
543
550
if ( declarator . id . type !== 'Identifier' ) {
544
551
// TODO: source does not allow destructuring
545
552
return [ dummyProgram ( ) , context ]
546
- } else if ( rhs . type === 'Literal' ) {
553
+ } else if ( rhs . type === 'Literal' || rhs . type === 'ArrayExpression' ) {
547
554
const remainingProgram = ast . program ( otherStatements as es . Statement [ ] )
548
555
return [ substituteMain ( declarator . id , rhs , remainingProgram ) , context ]
549
- } else if ( rhs . type === 'ArrowFunctionExpression' ) {
556
+ } else if ( rhs . type === 'ArrowFunctionExpression' || rhs . type === 'FunctionExpression' ) {
550
557
let funDecExp = ast . functionDeclarationExpression (
551
558
declarator . id ,
552
559
rhs . params ,
@@ -640,10 +647,10 @@ const reducers = {
640
647
if ( declarator . id . type !== 'Identifier' ) {
641
648
// TODO: source does not allow destructuring
642
649
return [ dummyBlockStatement ( ) , context ]
643
- } else if ( rhs . type === 'Literal' ) {
650
+ } else if ( rhs . type === 'Literal' || rhs . type === 'ArrayExpression' ) {
644
651
const remainingBlockStatement = ast . blockStatement ( otherStatements as es . Statement [ ] )
645
652
return [ substituteMain ( declarator . id , rhs , remainingBlockStatement ) , context ]
646
- } else if ( rhs . type === 'ArrowFunctionExpression' ) {
653
+ } else if ( rhs . type === 'ArrowFunctionExpression' || rhs . type === 'FunctionExpression' ) {
647
654
let funDecExp = ast . functionDeclarationExpression (
648
655
declarator . id ,
649
656
rhs . params ,
@@ -740,10 +747,10 @@ const reducers = {
740
747
if ( declarator . id . type !== 'Identifier' ) {
741
748
// TODO: source does not allow destructuring
742
749
return [ dummyBlockExpression ( ) , context ]
743
- } else if ( rhs . type === 'Literal' ) {
750
+ } else if ( rhs . type === 'Literal' || rhs . type === 'ArrayExpression' ) {
744
751
const remainingBlockExpression = ast . blockExpression ( otherStatements as es . Statement [ ] )
745
752
return [ substituteMain ( declarator . id , rhs , remainingBlockExpression ) , context ]
746
- } else if ( rhs . type === 'ArrowFunctionExpression' ) {
753
+ } else if ( rhs . type === 'ArrowFunctionExpression' || rhs . type === 'FunctionExpression' ) {
747
754
let funDecExp = ast . functionDeclarationExpression (
748
755
declarator . id ,
749
756
rhs . params ,
0 commit comments