Skip to content

Optimization: label not needed #1995

@allonhadaya

Description

@allonhadaya

Hey, I'm using this version:

--version
Closure Compiler (http://github.com/google/closure-compiler)
Version: v20160517
Built on: 2016/05/18 16:21

and my example program is:

label: for(var i = 0; i < 10; i++) {
  if (i == 1) {
    continue label;
  }
  console.log(i);
}

which compiles to:

var i=0;a:for(;10>i;i++){if(1==i)continue a;console.log(i)};

Notice that continue label was translated to continue a. Since the target of a bare continue statement would be the same as continue label in this case, a could be omitted.

I know it might be silly to save two bytes on a case that doesn't happen very often, but I figured I'd document the behaviour in case it's a new observation.

I think the idea could be generalized to, "labels can be omitted from continue statements when the label is equal to the current loop" AND "labels can be omitted from break statements when the label is equal to the current loop, switch, or label"... Something like that.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions