Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
metatoaster opened this issue Jun 22, 2017 · 0 comments

Comments

@metatoaster
Copy link

metatoaster commented Jun 22, 2017

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 metatoaster changed the title Switch default statement location not preserved Switch default statement position not preserved Jun 22, 2017
@metatoaster metatoaster changed the title Switch default statement position not preserved Switch default statement position not preserved (it is not always the last statement) Jun 22, 2017
metatoaster added a commit to metatoaster/calmjs.parse that referenced this issue Jun 22, 2017
- Only doing this on the sourcemap/pprint compatible layout due to the
  amount of work that will need to be done to make the previous string
  based visitors work again (mostly the testing).
- Yes, existing API is now verified to be broken in this one way.
- Now more conformant to the grammar as specified in ECMA-262 12.11.
- Fixes rspivak/slimit#94
metatoaster added a commit to metatoaster/calmjs.parse that referenced this issue Jun 22, 2017
- Only doing this on the sourcemap/pprint compatible layout due to the
  amount of work that will need to be done to make the previous string
  based visitors work again (mostly the testing).
- Yes, existing API is now verified to be broken in this one way.
- Now more conformant to the grammar as specified in ECMA-262 12.11.
- Fixes rspivak/slimit#94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant