IE allows a semicolon between if block and else

Just for the brainparsers our there: A semicolon between a closing curly bracket of an if block and the following else keyword only works in IE:

ie-only-if-else.htm

Should this work or would you consider such JS code broken beyond repair?

Advertisements

5 thoughts on “IE allows a semicolon between if block and else

  1. Of course, you have jumbled the compliance values, since the ie behaviour is wrong and other browsers are right.And yes, such code should be considered broken beyond repair. The if-else syntax must be atomic. If if-clause is separated by a statement from the else-clause, then what is the logical meaning of whatever goes in between them? In this case it's an empty statement, so what ie does doesn't harm anything. Except for other browsers, since they might have to make changes to their JavaScript parser if they wanted to support content like that.

  2. I think it's broken beyond repair.Supposed you have this:

    if(...){
        if(...) {};
        else {}
    }

    Was a curly bracket forgotten after if(…) {}; and should the one on the last line match a different opening bracket?

  3. Clearly not — the ECMA-262 grammar sez:IfStatement: if ( Expression ) Statement else StatementStatement: Block … EmptyStatement …{} is a Block, ';' is an EmptyStatement. None of the possible matches allow two Statements to be interpreted as a single Statement, so this must be a syntax error.

  4. I agree. Thanks for the input. Sorry to be too lazy to look at ES-262 prose (it was the end of my working session and for some reason I hit lots of small parsing quirks today so I just felt I'd rather blog and pick your brains than read yet another part of the spec closely..)Quirks day.. I've filed two new bugs on weird corners of the new Futhark engine. (One was summarised as "There is no catch. No, really. And we parse it anyway" – so you can guess what the bug is..) I don't think there currently is any place to file "weird parsing quirk bugs" for IE.. :pAnd liorean: I've fixed the test case to flag IE's behaviour as a failure 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s