haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Trailing commas

Open Aurel300 opened this issue 4 years ago • 3 comments
trafficstars

Allow trailing commas in various positions:

class Main {
  public static function main():Void {
    foobar(
      1,
      2,
    );
    function blah(
      a:Int,
      b:Int,
    ):Void {}
    var a = (
      a:Int,
      b:Int,
    ) -> 0;
    var a:(
      a:Int,
      b:Int,
    )->Int = null;
  }

  static function foobar(
    a:Int,
    b:Int,
  ):Void {}
}

enum Foo {
  Bar(
    a:Int,
    b:Int,
  );
}

function moduleFoobar(
  a:Int,
  b:Int,
):Void {}
  • [x] (the actual parser change)
  • [ ] tests?
  • [ ] update the syntax used for haxe highlighting here and in the IDE?

Aurel300 avatar Mar 06 '21 22:03 Aurel300

Fixes https://github.com/HaxeFoundation/haxe/issues/1989

RblSb avatar Dec 10 '21 14:12 RblSb

These display test failures don't seem to be random, we'll have to check what's going on there.

Simn avatar Apr 18 '22 10:04 Simn

evil idea: "automatic comma insertion" just like ecmascript's "automatic semicolon insertion", insert a comma on line break when applicable.

btw some previously-in-my-mind other idea about next-line parentheses, or to be honest, semicolons:

an opening parenthesis is a function call (-like thing) iif it's directly preceded by an identifier (or keyword?) or ) ] } with no whitespace in between. // still no clear idea at declaration site. be consistent?

may also extend to "indexing bracket" vs "array/map literal beginning". // but will never work for braces (unless we ban "naked block"? allow do{}; without while? only if(true){}? bbbtw do{}while() executes the body at least once, should it be allowed as value?)

farteryhr avatar Jun 15 '22 18:06 farteryhr

Superseded by #11009.

Aurel300 avatar Mar 12 '23 12:03 Aurel300