Skip to content

Commit 8704759

Browse files
Sam Baxterbaxtersa
Sam Baxter
authored andcommitted
Clean up lazy/eager transforms a bit
1 parent 4730b98 commit 8704759

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

src/callcc/jumper.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@ function lazyCaptureLogic(path: NodePath<t.AssignmentExpression>): void {
220220
locals.push(path.scope.getBinding(x)!.identifier);
221221
}
222222

223-
const nodeStmt = t.isStatement(path.node) ?
224-
path.node :
225-
t.expressionStatement(path.node);
223+
const nodeStmt = t.expressionStatement(path.node);
226224

227225
const restoreNode =
228226
t.assignmentExpression(path.node.operator,
@@ -253,14 +251,9 @@ function lazyCaptureLogic(path: NodePath<t.AssignmentExpression>): void {
253251
t.throwStatement(exn)
254252
])));
255253

256-
const tryApply = t.callExpression(t.arrowFunctionExpression([],
257-
t.blockStatement([tryStmt])), []);
258254
const stmtParent = path.getStatementParent();
259-
path.isStatement() ?
260-
(path.replaceWith(tryStmt), path.skip()) :
261-
t.isStatement(path.parent) ?
262-
(stmtParent.replaceWith(tryStmt), stmtParent.skip()) :
263-
(path.replaceWith(tryApply), path.skip());
255+
stmtParent.replaceWith(tryStmt);
256+
stmtParent.skip();
264257
}
265258

266259
/**
@@ -306,9 +299,7 @@ function eagerCaptureLogic(path: NodePath<t.AssignmentExpression>): void {
306299
locals.push(path.scope.getBinding(x)!.identifier);
307300
}
308301

309-
const nodeStmt = t.isStatement(path.node) ?
310-
path.node :
311-
t.expressionStatement(path.node);
302+
const nodeStmt = t.expressionStatement(path.node);
312303

313304
const stackFrame = t.objectExpression([
314305
t.objectProperty(t.identifier('kind'), t.stringLiteral('rest')),
@@ -340,15 +331,9 @@ function eagerCaptureLogic(path: NodePath<t.AssignmentExpression>): void {
340331
])));
341332
(<any>ifStmt).isTransformed = true;
342333

343-
344-
const ifApply = t.callExpression(t.arrowFunctionExpression([],
345-
t.blockStatement([ifStmt])), []);
346334
const stmtParent = path.getStatementParent();
347-
path.isStatement() ?
348-
(path.replaceWith(ifStmt), path.skip()) :
349-
t.isStatement(path.parent) ?
350-
(stmtParent.replaceWith(ifStmt), stmtParent.skip()) :
351-
(path.replaceWith(ifApply), path.skip());
335+
stmtParent.replaceWith(ifStmt);
336+
stmtParent.skip();
352337
}
353338

354339
/**

0 commit comments

Comments
 (0)