Skip to content

Commit

Permalink
fixed hang with #if (macro) (#245)
Browse files Browse the repository at this point in the history
* fixed hang with #if (macro)
* support Binop(OpAssignOp(_)) for indentation
  • Loading branch information
AlexHaxe authored Oct 16, 2018
1 parent f4699a7 commit d365a22
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## dev branch / next version (1.x.x)

- Added indentation support for `Binop(OpAssignOp(_))` [#245](https://github.com/HaxeCheckstyle/haxe-formatter/issues/245)
- Fixed endless loop during wrapping of `#if (macro)` [#245](https://github.com/HaxeCheckstyle/haxe-formatter/issues/245)

## version 1.1.1 (2018-10-13)

- Added support for key-value iterators, fixes [#232](https://github.com/HaxeCheckstyle/haxe-formatter/issues/232) ([#233](https://github.com/HaxeCheckstyle/haxe-formatter/issues/233))
Expand Down
2 changes: 1 addition & 1 deletion buildCpp.hxml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
buildCommon.hxml
-cpp out
-cpp out
4 changes: 3 additions & 1 deletion src/formatter/codedata/TokenList.hx
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ class TokenList {
case Kwd(KwdFunction), Kwd(KwdMacro):
var lastChild:TokenTree = TokenTreeCheckUtils.getLastToken(info.token);
if (lastChild != null) {
index = lastChild.index;
if (lastChild.index > index) {
index = lastChild.index;
}
continue;
}
default:
Expand Down
8 changes: 4 additions & 4 deletions src/formatter/marker/Indenter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Indenter {
if (parent.parent.is(Kwd(KwdFunction))) {
return findEffectiveParent(parent.parent);
}
case Binop(OpAssign):
case Binop(OpAssign), Binop(OpAssignOp(_)):
var access:TokenTreeAccessHelper = parent.access().parent().parent().is(Kwd(KwdTypedef));
if (access.exists()) {
return access.token;
Expand Down Expand Up @@ -202,7 +202,7 @@ class Indenter {
} else {
continue;
}
case Binop(OpAssign):
case Binop(OpAssign), Binop(OpAssignOp(_)):
case Kwd(KwdReturn), Kwd(KwdUntyped), Kwd(KwdNew):
if (!parsedCode.tokenList.isNewLineBefore(prevToken)) {
continue;
Expand All @@ -229,7 +229,7 @@ class Indenter {
if (!parsedCode.tokenList.isNewLineBefore(prevToken)) {
continue;
}
case Binop(OpAssign):
case Binop(OpAssign), Binop(OpAssignOp(_)):
if (currentToken.access().parent().parent().is(Kwd(KwdTypedef)).exists()) {
continue;
}
Expand Down Expand Up @@ -316,7 +316,7 @@ class Indenter {
switch (token.tok) {
case BrOpen, BkOpen, POpen, Dot:
return true;
case Binop(OpAssign):
case Binop(OpAssign), Binop(OpAssignOp(_)):
return true;
case Binop(OpLt):
return TokenTreeCheckUtils.isTypeParameter(token);
Expand Down
1 change: 1 addition & 0 deletions src/formatter/marker/MarkWrapping.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class MarkWrapping extends MarkerBase {
whitespace(close, After);
}
case POpen:
wrapAfter(close, true);
case Semicolon, Dot:
whitespace(close, NoneAfter);
case Binop(OpGt):
Expand Down
5 changes: 5 additions & 0 deletions test/testcases/indentation/nested_method_chain.hxtest
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Main {
.addChild (Tag.imgTag (Url.parse ("images.png"), "16", "", null)
.addClass ("innerClass"))
.addClass ("outerClass"));
form.addElement (new SelectElement ("type").addOption (new Option (transHtml ("Image"), "Image")).addOption (new Option (transHtml ("PDF"), "PDF")).addOption (new Option (transHtml ("Other"), "Media")));
}
}

Expand All @@ -41,5 +42,9 @@ class Main
.addChild(Tag.imgTag(Url.parse("images.png"), "16", "", null)
.addClass("innerClass"))
.addClass("outerClass"));
form.addElement(new SelectElement("type")
.addOption(new Option(transHtml("Image"), "Image"))
.addOption(new Option(transHtml("PDF"), "PDF"))
.addOption(new Option(transHtml("Other"), "Media")));
}
}
26 changes: 26 additions & 0 deletions test/testcases/indentation/opassignop.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{}

---


class Main {
public function main(){
profiles.get (className)
.get (methodName)
.elapsedTime += t - profiles.get (className)
.get (methodName)
.startTime;
}
}

---

class Main {
public function main() {
profiles.get(className)
.get(methodName)
.elapsedTime += t - profiles.get(className)
.get(methodName)
.startTime;
}
}
18 changes: 18 additions & 0 deletions test/testcases/other/sharp_if_parens_macro_hang.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{}

---

class Main {
#if (macro)
static function main() {
}
#end
}

---

class Main {
#if (macro)
static function main() {}
#end
}

0 comments on commit d365a22

Please sign in to comment.