daniellmb / JavaScript-Scope-Context-Coloring

An experiment in switching between syntax highlighting and scope colorizing built on JSLint and CodeMirror.
Other
579 stars 68 forks source link

Missing hoisting of variables? #4

Closed JonAbrams closed 11 years ago

JonAbrams commented 11 years ago

First of all, this project is absolutely brilliant, great job!

The issue: If I have code in a function that references a variable from the parent scope that's declared after the function, it doesn't get coloured correctly.

For example (the variable late belongs to the 'white' scope not the 'green' scope): Screen Shot 2013-04-07 at 2 14 04 PM

daniellmb commented 11 years ago

Closing this issue, as using variables before they are defined is in general an anti-pattern.

michaelficarra commented 11 years ago

That's not a good reason to close this. This could lead to deceptive highlighting, where an accidentally shadowed reference is highlighted as if it wasn't.

daniellmb commented 11 years ago

Hmmm I see your point, I wonder if you could use the lint warning information to correct the coloring.

michaelficarra commented 11 years ago

Just do real scope analysis instead of this naive scanner approach. See Constellation/escope.

JonAbrams commented 11 years ago

I'll try a better example. Is this an anti-pattern?

Screen Shot 2013-04-13 at 10 15 43 AM

Example taken from: http://stackoverflow.com/questions/8597501/which-design-patterns-take-advantage-of-javascripts-hoisting-behavior