apache / royale-compiler

Apache Royale Compiler
https://royale.apache.org/
Apache License 2.0
95 stars 49 forks source link

Compiler can output invalid javascript for multiple catch blocks #199

Closed greg-dove closed 2 years ago

greg-dove commented 2 years ago

Actionscript supports multiple catch blocks, javascript does not.

try {
    //something
} catch(error:ReferenceError) {
   //doStuff
} catch(error:TypeError) {
   //doOtherStuff
} //otherwise if it is neither of the above it will not be caught.

The above currently generates invalid javascript code (Syntax error).

It should be rewritten in js something more like:

try {
   //something
} catch(error:Error) {
   if (error is ReferenceError) {
       //doStuff
    } else (if error is TypeError) {
      //doOtherStuff
    } else {
     //otherwise if it is neither of the above it will not be caught.
     throw error;
   }
} 

Apparently other "Typed Language"-to-JS solutions already do this type of thing. Needs investigation and fixes in compiler-jx.

piotrzarzycki21 commented 2 years ago

@greg-dove I edited your issue to be more readable.