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

Support reserved words as property names #378

Closed
moretti opened this issue Jan 6, 2014 · 2 comments · Fixed by #439
Closed

Support reserved words as property names #378

moretti opened this issue Jan 6, 2014 · 2 comments · Fixed by #439

Comments

@moretti
Copy link

moretti commented Jan 6, 2014

I'm using Q and some of its methods are reserved words, like catch and finally.

In Q for example you can write:

Q($.ajax(...))
  .catch(function (response) {
    console.error(response);
  });

But this is formatted by js-beautifier in:

Q($.ajax(...))
  .
catch (function (response) {
  console.error(response);
});

Because catch is interpreted as a keyword.

Is there a way to format this code properly without using the square bracket notation (i.e. Q($.ajax(...))['catch'](...))?

Thanks!

@bitwiseman
Copy link
Member

Same as #309, #351, #368 but this is another solid description of it. All of these are made more difficult to fix by #200, but not impossible.

@mokkabonna
Copy link
Contributor

+1

Was about to open a ticket for it, here is a testcase at least mokkabonna@1d4f65d

Solution is needed for all kinds of reserved words as method names.

bitwiseman added a commit to bitwiseman/js-beautify that referenced this issue Mar 28, 2014
This supports calling libraries which declare properties of objects using reserved words.
This does not support declaring these fields.

`var a = { 'throw': function() {} }` - works
`a.throw()` - works
`var a = { throw: function() {} }` - does not work

Fixes beautifier#309
Fixes beautifier#351
Fixes beautifier#368
Fixes beautifier#378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants