Skip to content

Commit c567df7

Browse files
committed
Upgrade Babel dep, add async boolean to function declarations/expressions
1 parent 2a5800c commit c567df7

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

bin/compileCLI.js

100644100755
File mode changed.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"dependencies": {
4444
"acorn": "^6.0.4",
4545
"acorn-walk": "^6.1.1",
46-
"babel-core": "^6.26.3",
46+
"@babel/core": "",
4747
"command-line-args": "^5.0.2",
4848
"escodegen": "^1.11.0"
4949
}

src/BabelPlugin.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ function Plugin(babel) {
1818
function addTailCallBool(seqExp) {
1919
seqExp.expressions[0].argument.arguments.push(t.booleanLiteral(true));
2020
}
21+
function getParentNode(path) {
22+
const parentPath = path.getFunctionParent();
23+
if (parentPath === null) return path.scope.getProgramParent().block;
24+
return parentPath.node;
25+
}
2126
// HzTokens are unique single-instance objects for wrapping user instructions and data.
2227
// Type 1: Invocation Tokens,
2328
// Wrap userland functors and any operands needed to invoke them.
@@ -239,7 +244,8 @@ function Plugin(babel) {
239244
null,
240245
funcDec.params,
241246
funcDec.body,
242-
true
247+
true,
248+
funcDec.async
243249
))
244250
)
245251
]);
@@ -253,7 +259,8 @@ function Plugin(babel) {
253259
null,
254260
funcDec.params,
255261
funcDec.body,
256-
true
262+
true,
263+
funcDec.async
257264
))
258265
)
259266
]);
@@ -303,9 +310,9 @@ function Plugin(babel) {
303310
if (path.node.generator) var varDec = declareHzGenerator(path.node);
304311
else var varDec = declareHzCoroutine(path.node);
305312
path.node.generator = true;
306-
const parentPath = path.getFunctionParent();
307-
if (Array.isArray(parentPath.node.body)) parentPath.node.body.unshift(varDec);
308-
else parentPath.node.body.body.unshift(varDec);
313+
const parentNode = getParentNode(path);
314+
if (Array.isArray(parentNode.body)) parentNode.body.unshift(varDec);
315+
else parentNode.body.body.unshift(varDec);
309316
path.remove();
310317
}
311318
},
@@ -415,7 +422,7 @@ function Plugin(babel) {
415422
// Check for TCO validity if the call is within a TryStatement
416423
if (tryStack.length > 0) {
417424
const tryData = tryStack[tryStack.length - 1];
418-
const parentNode = path.getFunctionParent().node;
425+
const parentNode = getParentNode(path);
419426
if (parentNode === tryData.functionParent) {
420427
if (
421428
tryData.blockType === "finalizer"
@@ -440,7 +447,7 @@ function Plugin(babel) {
440447
},
441448
// Transforms a ReturnStatement into an Instruction Token
442449
exit: function (path) {
443-
if (path.getFunctionParent().node.generator) {
450+
if (getParentNode(path).generator) {
444451
path.node.argument = hzReturnArg(t.ObjectExpression([
445452
t.ObjectProperty(
446453
t.identifier("value"),
@@ -489,7 +496,7 @@ function Plugin(babel) {
489496
// Records entry into a TryStatement
490497
enter: function (path) {
491498
tryStack.push({
492-
functionParent: path.getFunctionParent().node,
499+
functionParent: getParentNode(path),
493500
blockType: null
494501
});
495502
},

src/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs');
22
const { join } = require('path');
3-
const babel = require('babel-core');
3+
const babel = require('@babel/core');
44
const hzBabelPlugin = require('./BabelPlugin.js');
55
const compileSpawn = require("./compileSpawn.js");
66
module.exports = function hzCompile(source, mod = false, standalone = false, spawn = false) {

0 commit comments

Comments
 (0)