Skip to content

Commit 386444e

Browse files
committed
Add support for top-level await
1 parent 78c7b36 commit 386444e

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lib/parser/nodejs/exported_function_parser.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@ class ExportedFunctionParser {
279279
try {
280280
moduleStatement = this.parseModuleExportsStatement(fileString);
281281
} catch (e) {
282-
if (e.message.startsWith(`'return' outside of function`)) {
282+
if (
283+
e.message.startsWith(`'return' outside of function`) ||
284+
e.message.startsWith(`Unexpected token, expected ;`)
285+
) {
283286
moduleStatement = this.parseModuleExportsStatement(`async function __inline__ (context) {\n${fileString}\n}`);
284287
moduleStatement = null;
285288
} else {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "functionscript",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"description": "A language and specification for turning JavaScript functions into typed HTTP APIs",
55
"author": "Keith Horwood <[email protected]>",
66
"main": "index.js",

tests/gateway/tests.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,6 +2804,19 @@ module.exports = (expect) => {
28042804
});
28052805
});
28062806

2807+
it('Should allow you to use "await"', done => {
2808+
request('POST', {}, '/inline/await/', {}, (err, res, result) => {
2809+
2810+
expect(err).to.not.exist;
2811+
expect(res.statusCode).to.equal(200);
2812+
expect(res.headers['content-type']).to.equal('application/json');
2813+
expect(result).to.exist;
2814+
expect(result).to.equal('hello world');
2815+
done();
2816+
2817+
});
2818+
});
2819+
28072820
after(() => FaaSGateway.close());
28082821

28092822
};

0 commit comments

Comments
 (0)