Skip to content

Commit

Permalink
initial commit for es2019 support, needs testing and compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
taylordowns2000 committed Apr 11, 2020
1 parent 0a2168c commit 0ec0bf8
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 51 deletions.
43 changes: 22 additions & 21 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const Adaptor = getModule(modulePath(argv.language));
// and the `verify` transform in Compile.
const extensions = Object.assign(
{
__node_version: process.version, // display the node version
console: argv.noConsole ? disabledConsole : console, // --nc or --noConsole
testMode: argv.test, // --t or --test
setTimeout, // We allow as Erlang will handle killing long-running VMs.
Expand All @@ -142,17 +143,17 @@ switch (argv._[0]) {
.then(code => {
const compile = new Compile(code, transforms);

if (compile.errors.length > 0) {
compile.errors
.map(error => {
return formatCompileError(code, error);
})
.map(error => {
console.log(error);
});
// if (compile.errors.length > 0) {
// compile.errors
// .map(error => {
// return formatCompileError(code, error);
// })
// .map(error => {
// console.log(error);
// });

return Promise.reject(new Error('Compilation failed.'));
}
// return Promise.reject(new Error('Compilation failed.'));
// }

return compile.toString();
})
Expand Down Expand Up @@ -190,17 +191,17 @@ switch (argv._[0]) {
readFile(argv.expression).then(code => {
const compile = new Compile(code, transforms);

if (compile.errors.length > 0) {
compile.errors
.map(error => {
return formatCompileError(code, error);
})
.map(error => {
console.log(error);
});

return Promise.reject(new Error('Compilation failed.'));
}
// if (compile.errors.length > 0) {
// compile.errors
// .map(error => {
// return formatCompileError(code, error);
// })
// .map(error => {
// console.log(error);
// });

// return Promise.reject(new Error('Compilation failed.'));
// }

return compile.toString();
}),
Expand Down
10 changes: 10 additions & 0 deletions lib/compile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ class Compile {
ast = recast.parse(ast.replace(/\ $/, ''), {
tolerant: true,
range: true,
parser: {
parse(source) {
return require('acorn').parse(source, {
sourceType: 'script',
ecmaVersion: 10,
allowHashBang: true,
locations: true,
});
},
},
});
}

Expand Down
13 changes: 12 additions & 1 deletion lib/compile/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,18 @@ function transform(ast, { languagePack, doclets }) {
}

if (typeof ast === 'string')
ast = recast.parse(ast)
ast = recast.parse(ast, {
parser: {
parse(source) {
return require('acorn').parse(source, {
sourceType: 'script',
ecmaVersion: 10,
allowHashBang: true,
locations: true,
});
},
},
})

// Inject all the exported members of the module into the top of the AST.
// This is used to infer existence of a call expression for the language pack
Expand Down
71 changes: 44 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "core",
"version": "1.2.0",
"version": "1.3.0",
"description": "The central job processing program used in the OpenFn platform.",
"repository": {
"type": "git",
Expand All @@ -18,11 +18,13 @@
"author": "Open Function Group",
"license": "LGPL-3.0",
"dependencies": {
"acorn": "^7.1.1",
"acorn-loose": "^7.0.0",
"ast-types": "^0.9.0",
"doclet-query": "github:openfn/doclet-query#v0.1.0",
"estemplate": "^0.5.1",
"mitm": "^1.3.2",
"recast": "^0.11.13",
"recast": "0.19.0",
"vm2": "^3.8.4",
"yargs": "^3.30.0"
},
Expand Down

0 comments on commit 0ec0bf8

Please sign in to comment.