tc39 / proposal-binary-ast

Binary AST proposal for ECMAScript
965 stars 23 forks source link

Why feature post-default cases with `SwitchStatementWithDefault`? #39

Closed dead-claudia closed 6 years ago

dead-claudia commented 6 years ago

Semantically, the labels are meaningless after parsing, so why include them as part of the AST?

In case you're wondering what precedent there is for just ignoring the extra case labels:

bakkot commented 6 years ago

Semantically, the labels are meaningless after parsing

Not sure what this means. The obvious interpretation is false: for example,

switch (0) {
  default: break;
  case console.log(42):
}

will print 42. Contrast

switch (0) {
  case 0:
  default: break;
  case console.log(42):
}

which has no effects.

Similarly,

switch (0) {
  case -1: console.log(-1); break;
  default: console.log('default'); break;
  case 1: console.log(1); break;
  case 0: console.log(0); break;
  case 2: console.log(2); break;
}

will print 0.

See step 9 of the third item under CaseBlockEvaluation (the CaseBlock : { CaseClauses DefaultClause CaseClauses } production).

dead-claudia commented 6 years ago

Oh, then on that note, nevermind.