Skip to content

Commit 66e966f

Browse files
committed
Add ArrayExpression as an irreducibleNode
1 parent 96e8300 commit 66e966f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/substituter.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ function isIrreducible(node: substituterNodes) {
2929
return irreducibleTypes.has(node.type)
3030
}
3131

32+
type irreducibleNodes =
33+
| es.Identifier
34+
| es.FunctionExpression
35+
| es.ArrowFunctionExpression
36+
| es.Literal
37+
| es.ArrayExpression
38+
3239
/* tslint:disable:no-shadowed-variable */
3340
// wrapper function, calls substitute immediately.
3441
function substituteMain(
3542
name: es.Identifier,
36-
replacement: es.FunctionExpression | es.Literal | es.ArrowFunctionExpression,
43+
replacement: irreducibleNodes,
3744
target: substituterNodes
3845
): substituterNodes {
3946
const seenBefore: Map<substituterNodes, substituterNodes> = new Map()
@@ -281,7 +288,7 @@ function substituteMain(
281288
*/
282289
function apply(
283290
callee: es.FunctionExpression | es.ArrowFunctionExpression,
284-
args: Array<es.Identifier | es.Literal | es.FunctionExpression | es.ArrowFunctionExpression>
291+
args: irreducibleNodes[]
285292
): BlockExpression | es.Expression {
286293
let substedBody = callee.body
287294
for (let i = 0; i < args.length; i++) {
@@ -543,10 +550,10 @@ const reducers = {
543550
if (declarator.id.type !== 'Identifier') {
544551
// TODO: source does not allow destructuring
545552
return [dummyProgram(), context]
546-
} else if (rhs.type === 'Literal') {
553+
} else if (rhs.type === 'Literal' || rhs.type === 'ArrayExpression') {
547554
const remainingProgram = ast.program(otherStatements as es.Statement[])
548555
return [substituteMain(declarator.id, rhs, remainingProgram), context]
549-
} else if (rhs.type === 'ArrowFunctionExpression') {
556+
} else if (rhs.type === 'ArrowFunctionExpression' || rhs.type === 'FunctionExpression') {
550557
let funDecExp = ast.functionDeclarationExpression(
551558
declarator.id,
552559
rhs.params,
@@ -640,10 +647,10 @@ const reducers = {
640647
if (declarator.id.type !== 'Identifier') {
641648
// TODO: source does not allow destructuring
642649
return [dummyBlockStatement(), context]
643-
} else if (rhs.type === 'Literal') {
650+
} else if (rhs.type === 'Literal' || rhs.type === 'ArrayExpression') {
644651
const remainingBlockStatement = ast.blockStatement(otherStatements as es.Statement[])
645652
return [substituteMain(declarator.id, rhs, remainingBlockStatement), context]
646-
} else if (rhs.type === 'ArrowFunctionExpression') {
653+
} else if (rhs.type === 'ArrowFunctionExpression' || rhs.type === 'FunctionExpression') {
647654
let funDecExp = ast.functionDeclarationExpression(
648655
declarator.id,
649656
rhs.params,
@@ -740,10 +747,10 @@ const reducers = {
740747
if (declarator.id.type !== 'Identifier') {
741748
// TODO: source does not allow destructuring
742749
return [dummyBlockExpression(), context]
743-
} else if (rhs.type === 'Literal') {
750+
} else if (rhs.type === 'Literal' || rhs.type === 'ArrayExpression') {
744751
const remainingBlockExpression = ast.blockExpression(otherStatements as es.Statement[])
745752
return [substituteMain(declarator.id, rhs, remainingBlockExpression), context]
746-
} else if (rhs.type === 'ArrowFunctionExpression') {
753+
} else if (rhs.type === 'ArrowFunctionExpression' || rhs.type === 'FunctionExpression') {
747754
let funDecExp = ast.functionDeclarationExpression(
748755
declarator.id,
749756
rhs.params,

0 commit comments

Comments
 (0)