jsx / JSX

JSX - a faster, safer, easier JavaScript
http://jsx.github.io/
MIT License
1.46k stars 102 forks source link

Block not accepted after label; error suggests it should be #338

Open ojwb opened 8 years ago

ojwb commented 8 years ago

Compiling the follow code (verified using http://jsx.github.io/try-on-web/):

class _Main {
  static function main(args :string[]) : void {
    lab: {
      log 42;
    }
  }
}

Gives the rather unhelpful error:

ERROR!
[source-map/add.jsx:3:9] only blocks, iteration statements, and switch statements are allowed after a label
    lab: {
         ^
[source-map/add.jsx:7:0] expected keyword: class interface mixin abstract final native __fake__ __export__
}
^

Looking at the compiler source, the check is:

                var token = this._expectOpt([
                        "{", "var", ";", "if", "do", "while", "for", "continue", "break", "return", "switch", "throw", "try", "assert", "log", "delete", "debugger", "function", "void", "const"
                ]);
                if (label != null) {
                        if (! (token != null && token.getValue().match(/^(?:do|while|for|switch)$/) != null)) { 
                                this._newError("only blocks, iteration statements, and switch statements are allowed after a label"); 
                                return false; 
                        } 
                }

So the check doesn't allow {. Either the check or the error message is incorrect.