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

Not able to use semicolons for proper JavaScript in blocks #27

Closed
goloroden opened this issue Dec 31, 2013 · 4 comments
Closed

Not able to use semicolons for proper JavaScript in blocks #27

goloroden opened this issue Dec 31, 2013 · 4 comments

Comments

@goloroden
Copy link

Supposed I have the following file index.vash:

@html.extend('layout', function (model) {
  @html.block('content', function (model) {
    <p>Hallo Welt!</p>
  })
})

Then the code is "broken" due to missing semicolons at the end of the two lines containing the }) characters. But if I add them I won't get the result I'd like to, as they are sent to the client instead.

How to fix this?

@kirbysayshi
Copy link
Owner

Could you clarify what you mean by "broken"? You mean rely on ASI as opposed to manual semicolon insertion?

It was a trade off I made to make the parser/compiler slightly less complex. Perhaps I should revisit this. Are you running into a tooling issue, aside from personal compulsions :) ?

@goloroden
Copy link
Author

Hm, okay, perhaps broken was the wrong word.

Let's say it like this: If I insert the (missing) semicolon, it is not ignored, but Vash sends it as normal output to the HTML. So it is not possible to use final semicolons (or I am missing something here).

And, no it's not a tooling issue, just personal style ;-)

@kirbysayshi
Copy link
Owner

No, you're not missing anything, unfortunately that's a limitation in vash. It's very difficult for vash to know the difference between @something.cb(function() {}); and @();, where a semicolon should be consumed by the first and should be output by the second. In both cases it just knows that an expression is ending (signified by the )).

I could put in an exception/hack specifically for blocks containing callbacks, but I've resisted since it would break consistency (aside from within a block, all semicolons are treated as content).

@kirbysayshi
Copy link
Owner

I've been thinking about this some more, and I think it's actually impossible for vash to know when a trailing semicolon is meant to be code or content. However, you can force the semicolons to be parsed as code by wrapping the layout calls in an anonymous code "block":

@{
  html.extend('layout', function (model) {
    @html.block('content', function (model) {
      <p>Hallo Welt!</p>
    });
  });
}

Going to close this for now, as the case of @something.hey(function() { return 'yo' }); (semicolon should be content) is ambiguously close to @html.block('layout', function() {}); (semicolon should be code).

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

2 participants