slimit icon indicating copy to clipboard operation
slimit copied to clipboard

Switch default statement position not preserved (it is not always the last statement)

Open metatoaster opened this issue 7 years ago • 0 comments

The intent of the following code is that every other number than 0 or 2 will trigger the default condition, and every default condition will also trigger 2. However, the switch statement pulls that attribute out and this results in loss of information which results in the code not being correctly regenerated (i.e. the default is the last to be printed, instead of being printed before case 2: case statements).

>>> tree = p.parse("""
... switch (v) {
...   case 0:
...     console.log('0');
...     break;
...   default:
...     console.log('default');
...   case 2:
...     console.log('2');
... };
... """)
>>> print(tree.to_ecma())
switch (v) {
  case 0:
    console.log('0');
    break;
  case 2:
    console.log('2');
  default:
    console.log('default');
}
;

metatoaster avatar Jun 22 '17 06:06 metatoaster