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

Document what happens with superfluous parens #105

Open
Yoric opened this issue Dec 7, 2018 · 4 comments
Open

Document what happens with superfluous parens #105

Yoric opened this issue Dec 7, 2018 · 4 comments
Labels

Comments

@Yoric
Copy link

Yoric commented Dec 7, 2018

While superfluous parens have no official semantics, they are actually used by browsers to perform laziness tricks:

var foo = function() { ... }; // Parsed lazily by the browser.
var bar = (function() { ... }); // Parsed eagerly by the browser.

It would be very useful to keep superfluous parens in such a case (or perhaps always). I don't know if that's what ratel does currently, so documenting the choice would be useful, too!

Perhaps it should be a parsing option?

@maciejhirsz
Copy link
Member

Superfluous parens are always dropped. I don't particularly see a reason to change it since the goal is to produce an AST, not a parse tree. In either case, we do need a proper book for all of this stuff.

@Yoric
Copy link
Author

Yoric commented Dec 7, 2018

Well, these superfluous parens turn out to have an observable (by timing) effect, so they are de facto part of the language. For instance, in Binary AST, we make the difference between EagerFunctionDeclaration and LazyFunctionDeclaration.

Would it be possible to somehow store the information somewhere?

@maciejhirsz
Copy link
Member

Is that the only difference? We can attach a eager|lazy flag to functions if that's the case.

@Yoric
Copy link
Author

Yoric commented Dec 9, 2018

That would work very well for my usecase (and I believe a number of other usecases).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants