Skip to content

Commit

Permalink
fix using new as statement
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed May 23, 2024
1 parent 4d22117 commit 8f5cc40
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 56 deletions.
4 changes: 4 additions & 0 deletions __tests__/__fixtures__/other_syntax.gs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Promise, setTimeout

new Promise(lambda(resolve)
setTimeout(resole, 0)
end)

async do
animate do
exec* "hello, world", 0
Expand Down
3 changes: 3 additions & 0 deletions __tests__/__snapshots__/gaiman.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ exports[`global should parse other syntax 1`] = `
"async function main() {
try {
const $_Promise = Promise, $_setTimeout = setTimeout;
await new $_Promise(async function lambda($_resolve) {
await $_setTimeout($_resole, 0);
});
gaiman['async'](async function () {
await gaiman.animate(async function () {
await gaiman.exec_extra(\`hello, world\`, 0);
Expand Down
23 changes: 7 additions & 16 deletions parser.js

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

3 changes: 2 additions & 1 deletion src/grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,8 @@ zero

DIGIT = [0-9]

keyword = ("if" / "then" / "end" / "else" / "return" / "def" / "do" / "in" / "for" / "while" / "break" / "continue" / "lambda" / "from" / "new" / "try" / "catch") !name
keyword = ("if" / "then" / "end" / "else" / "return" / "def" / "do" / "in" / "for" / "while" / "break" / "continue" / "lambda" / "from" / "try" / "catch") !name


name = [A-Z_$a-z][A-Z_a-z0-9]* { return text(); }

Expand Down
38 changes: 16 additions & 22 deletions umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Copyright (C) 2021 Jakub T. Jankiewicz <https://jcubic.pl/me>
*
* Released under GNU GPL v3 or later
* Buid time: Thu, 23 May 2024 08:13:24 GMT
* Buid time: Thu, 23 May 2024 10:07:46 GMT
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
Expand Down Expand Up @@ -81,6 +81,12 @@
"arguments": args
};
}
function await_expr(expression) {
return {
"type": "AwaitExpression",
"argument": expression
};
}
function declare(names) {
return {
"type": "VariableDeclaration",
Expand Down Expand Up @@ -754,14 +760,11 @@
};
var peg$f22 = function(lambda) { return lambda; };
var peg$f23 = function(expression, args) {
return new_expr(expression, args);
return await_expr(new_expr(expression, args));
};
var peg$f24 = function(expression, args, rest) {
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 Expand Up @@ -7415,29 +7418,20 @@
if (peg$silentFails === 0) { peg$fail(peg$e30); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c22) {
s1 = peg$c22;
if (input.substr(peg$currPos, 3) === peg$c11) {
s1 = peg$c11;
peg$currPos += 3;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e22); }
if (peg$silentFails === 0) { peg$fail(peg$e11); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c11) {
s1 = peg$c11;
peg$currPos += 3;
if (input.substr(peg$currPos, 5) === peg$c12) {
s1 = peg$c12;
peg$currPos += 5;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e11); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 5) === peg$c12) {
s1 = peg$c12;
peg$currPos += 5;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e12); }
}
if (peg$silentFails === 0) { peg$fail(peg$e12); }
}
}
}
Expand Down
34 changes: 17 additions & 17 deletions umd.min.js

Large diffs are not rendered by default.

0 comments on commit 8f5cc40

Please sign in to comment.