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

Inconsistent JS hints depending on whitespace #241

Open
dangoor opened this issue Sep 19, 2013 · 5 comments
Open

Inconsistent JS hints depending on whitespace #241

dangoor opened this issue Sep 19, 2013 · 5 comments

Comments

@dangoor
Copy link

dangoor commented Sep 19, 2013

Go to the Tern demo page

Reformat the CTor function with newlines:

function CTor() {
  this.size = 10;
}

Then, add another line to the function, with the new line properly aligned:

function CTor() {
  this.size = 10;
  this.|
}

ctrl-space with the cursor where the | character is above will produce the correct results.

function CTor() {
  this.size = 10;
 this.|
}

However, if the line is not aligned with the line above (as in the example above), ctrl-space produces general results rather than results specific to CTor.

This is likely low priority, because most people align their code. However, I do wonder if there are cases in which whitespace sensitivity could actually trip up Tern.

@marijnh
Copy link
Member

marijnh commented Oct 6, 2013

The error-correcting parser is whitespace sensitive, and thus sometimes produces odd results. I have some plans on how it could be improved (with a separate brace-balancing pass), but it'd require some major work that I currently don't have the time for.

@dangoor
Copy link
Author

dangoor commented Oct 10, 2013

OK, that's good to know. This issue alone is not worth "major work", I should think.

@bfricka
Copy link
Contributor

bfricka commented Jan 20, 2014

I haven't looked at the "error-correcting parser" so this may be stupid, but could you potentially pull in a consistent beautifier (like UglifyJS 2) and normalize input formatting accordingly before handing it to the parser? That way you can make better assumptions about the structure...

@marijnh
Copy link
Member

marijnh commented Jan 20, 2014

No, that does not help -- a beautifier needs to parse the code first, and if it's not syntactically valid, it can't beautify it. The problem exists in the parsing of broken syntax.

@bfricka
Copy link
Contributor

bfricka commented Jan 20, 2014

Ahh, I see now. Knew I should have read the code first.

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

3 participants