Skip to content

Commit

Permalink
Fixed conversion of 'setTimeout(callback, (a + b) * 1000, args)'. fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SlavaRa authored Oct 25, 2017
1 parent bae573e commit 59b23ad
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## dev
- Fixed conversion of `setTimeout(callback, (a + b) * 1000)`. fixes #293
- Fixed conversion of `parseInt('0xFFFFFF', 16)`. fixes #265

## 2017-10-24(1.0.6)
Expand Down
8 changes: 6 additions & 2 deletions src/as3hx/parsers/StructureParser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,12 @@ class StructureParser {
var t = tokenizer.token();
switch(t) {
case TPOpen: parCount++;
case TPClose: parCount--;
case TPClose:
parCount--;
if(params.length > 0) params[params.length - 1] = EParent(params[params.length - 1]);
case TComma:
case TOp(op) if(params.length > 0):
params[params.length - 1] = ParserUtils.makeBinop(tokenizer, op, params[params.length - 1], parseExpr(false));
case _:
tokenizer.add(t);
if(params.length < 2) params.push(parseExpr(false));
Expand All @@ -331,8 +335,8 @@ class StructureParser {
switch(params[2]) {
case EArrayDecl(e): e.push(parseExpr(false));
case _:
}
}
}
}
}
params;
Expand Down
10 changes: 10 additions & 0 deletions test/issues/Issue293.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package {
import flash.utils.setTimeout;
public class Issue293 {
public function Issue293() {
var i:int = setTimeout(function(...args) {
trace(args);
}, (1 + 1) * 1000, 1, 2, 3);
}
}
}
11 changes: 11 additions & 0 deletions test/issues/Issue293.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

class Issue293
{
public function new()
{
var i : Int = as3hx.Compat.setTimeout(function(args : Array<Dynamic> = null)
{
trace(args);
}, (1 + 1) * 1000, [1, 2, 3]);
}
}
5 changes: 5 additions & 0 deletions test/unit/as3hx/AS3HXTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,11 @@ class AS3HXTest {
generate("Issue273.as", "Issue273.hx");
}

@Test("setTimeout(callback, (a + b) * 1000, args)")
public function issue293() {
generate("Issue293.as", "Issue293.hx");
}

function generate(as3FileName:String, expectedHaxeFileName:String) {
var issuesDirectory = FileSystem.absolutePath("test/issues");
var generatedDirectoryPath = '$issuesDirectory/generated';
Expand Down

0 comments on commit 59b23ad

Please sign in to comment.