Closed
Description
Consider the following enum definition:
enum Flags {
A = 1,
B = 2,
C = A | B // Should be constant folded to 3.
}
In most cases, JS engines can optimize simple expressions like these. But they can't do much about accesses to Flags.C
.
switch (x) {
case Flags.A: ... break; // Compiled as case 1: ...
case Flags.B: ... break; // Compiled as case 2: ...
case Flags.C: ... break; // Compiled as Flags.C: ...
}
This prevents JS engines from using a table jump and causes them to fall back on a sequential if/else if implementation for the switch which is all sorts of terrible.