Skip to content

Commit

Permalink
fix unsing new Promise as Gaiman code
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed May 23, 2024
1 parent 69db5c6 commit 4d22117
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions __tests__/__snapshots__/gaiman.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ exports[`global should parse other syntax 1`] = `
});
});
async function $_delay($_time) {
return new $_Promise(async function lambda($_resolve) {
return await new $_Promise(async function lambda($_resolve) {
await $_setTimeout($_resolve, $_time);
});
}
Expand All @@ -366,7 +366,7 @@ exports[`global should parse other syntax 1`] = `
await gaiman.exec_extra($_command, 10);
});
});
let $_stage = new $_canvas.Canvas(await $_cols(), 10);
let $_stage = await new $_canvas.Canvas(await $_cols(), 10);
} catch (e) {
if (!(e instanceof Exit)) {
gaiman.error(e);
Expand Down
13 changes: 8 additions & 5 deletions parser.js

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

13 changes: 8 additions & 5 deletions src/grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
"arguments": args
};
}
function await_expr(expression) {
return {
"type": "AwaitExpression",
"argument": expression
};
}
function declare(names) {
return {
"type": "VariableDeclaration",
Expand Down Expand Up @@ -565,15 +571,12 @@ lambda_value = "(" _ lambda:lambda _ ")" { return lambda; }
call = "(" _ args:(argument_list / null_array) _ ")"

constructor = "new" SP expression:(prop_access / variable) _ "(" _ args:(argument_list / null_array) ")" _ {
return new_expr(expression, args);
return await_expr(new_expr(expression, args));
}

function_call = _ !keyword expression:(prop_access / lambda_value / variable) _ "(" _ args:(argument_list / null_array) ")" _ rest:(call / bracket_prop / dot_prop)* {
if (rest.length === 0) {
return {
"type": "AwaitExpression",
"argument": call(expression, ...args)
};
return await_expr(call(expression, ...args))
}
return rest.reduce(function(acc, item) {
if (acc.type === 'CallExpression') {
Expand Down

0 comments on commit 4d22117

Please sign in to comment.