Lexer: Chaining: Variable scope varies depending on whether its calling function starts with a leading dot
I have a question about the scoping of "myVar" here:
# CoffeeScript: foo myVar = 1 .bar -> myVar = 2 # Generates this Javascript: var myVar; foo(myVar = 1).bar(function() { var myVar; return myVar = 2; });
In the example above, myVar gets scoped in two places, but if we remove the dot (.), it's only scoped in the enclosing scope:
# CoffeeScript: foo myVar = 1 bar -> myVar = 2 # Generates this Javascript: var myVar; foo(myVar = 1); bar(function() { return myVar = 2; });
My understanding of CoffeeScript scoping is: if the variable is assigned in the enclosing scope lexically-before it is used in a function sub-scope, the sub-scope will use that binding. The first case above breaks this rule. Is this a bug? Or am I not understanding CoffeeScript scoping fully?