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

throw could be a function #309

Closed
derekchiang opened this issue Jul 12, 2013 · 3 comments · Fixed by #439
Closed

throw could be a function #309

derekchiang opened this issue Jul 12, 2013 · 3 comments · Fixed by #439

Comments

@derekchiang
Copy link

Apparently JsBeautifier is making the assumption that throw won't be override, but this is clearly not necessarily true. Consider this piece of code from should.js:

(function(){
  // do something
}).should.not.throw();

This will be beautified to:

(function() {
  // do something
}).should.not.
throw ();

which, of course, will break the code.

@bitwiseman
Copy link
Member

Yeah, throw is not a keyword when it follows a ..

Here's another case:

{ throw: true };

Can you think of any others?

This is same thing is true for all keywords, isn't it?

a.should.return(1);

@einars
Copy link
Contributor

einars commented Jul 12, 2013

Ref #200, "Javascript not fully parsed". I don't think this is actually possible to fix in a good way under the current parser model without some weird error-prone hacks :(

@bitwiseman
Copy link
Member

We can fix parts of it, like when a keyword follows a .. Is there a case where this is not true?

We can then file issues for the remaining scenarios and note them the same as you did above.

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