Skip to content

Commit

Permalink
Merge pull request #20 from botsman/fix-call-with-await
Browse files Browse the repository at this point in the history
fix call with await function as an argument
  • Loading branch information
botsman authored Jan 1, 2022
2 parents 6a3c6e1 + 3eee9ad commit 40bfc69
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
4 changes: 2 additions & 2 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"javascript"
],
"description": "This library provides a macros to add 'async' and 'await' keywords for Python and JavaScript and does nothing for other platoforms.",
"version": "1.1.2",
"version": "1.1.3",
"classPath": "src",
"releasenote": "Remove development files",
"releasenote": "Fix call with await function as an argument",
"contributors": [
"botsman"
],
Expand Down
4 changes: 3 additions & 1 deletion src/hxasync/AsyncMacro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class AsyncMacro {
}

public static function handleAny(expr: Expr, isAsyncContext: Bool) {
// TODO: handle more Expr types
if (expr == null) {
return null;
}
Expand All @@ -110,6 +109,9 @@ class AsyncMacro {
}
case ECall(e, params):
handleAny(e, isAsyncContext);
for (param in params) {
handleAny(param, isAsyncContext);
}
case EConst(s):
null;
case EField(e, field):
Expand Down
41 changes: 41 additions & 0 deletions tests/Tests.hx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,43 @@ class Cases {
return (@await nestedFunction()).a;
}

@async public static function testAnonymousStructure() {
var someAsyncFunction = @async function() {
return 1;
}
return {
a: @await someAsyncFunction()
}
}

@async public static function testAnonymousStructureInArray() {
var someAsyncFunction = @async function() {
return 1;
}
var arr: Array<Dynamic> = [];
arr.push({
a: @await someAsyncFunction()
});
return arr;
}

@async public static function testStringInterpolation() {
var someAsyncFunction = @async function() {
return 1;
}
return 'asd ${@await someAsyncFunction()}';
}

@async public static function testAsyncCallAsArgument() {
var someAsyncFunction = @async function() {
return 1;
}
var anotherFunction = function(arg: Int) {
return arg;
}
return anotherFunction(@await someAsyncFunction());
}

@async public function returnDynamic() {
var a = 10;
return {
Expand All @@ -72,6 +109,10 @@ class Cases {
@await testFunctionWithDefaultArgs();
@await testNestedFunction();
@await testBrackets();
@await testAnonymousStructure();
@await testAnonymousStructureInArray();
@await testStringInterpolation();
@await testAsyncCallAsArgument();
}
}

Expand Down

0 comments on commit 40bfc69

Please sign in to comment.