Skip to content

Statements and ; #29

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

Open
vkz opened this issue Apr 29, 2015 · 1 comment
Open

Statements and ; #29

vkz opened this issue Apr 29, 2015 · 1 comment

Comments

@vkz
Copy link

vkz commented Apr 29, 2015

BSJS grammars seem to be quite frivolous with how they parse and particularly generate JS code.

var source = "function test() { for(var i = 0;i < 2;i++) { }; return [];}";

Of interest are ; before return and the one before the last }. Parsing and then generating JS using ometa BSJS grammars will produce:

function test(){for(var i = 0;i < 2;i++){};undefined;return []}
  • undefined; is there because at the moment empty statements are parsed into ['stmt', ['get', 'undefined']]. We should probably have a separate type for those
  • ; after the very last statement gets dropped completely. This is because curlyTrans rule in BSJSTranslator simply joins all statements with rs.join(';'). Another consequence of joining is pervasive ; even after statements that didn't have semicolons after them in the original source. Latter is mostly problematic if we want to preserve the code-style of the origin (more or less). Esprima + Escodegen do the right thing here.
@vkz
Copy link
Author

vkz commented Apr 29, 2015

Not submitting PRs cause the issue may appear subjective and therefore we should discuss before moving fwd with changes.

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