mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Merging Tesco's invoking-this-fix
This commit is contained in:
parent
8fc631269b
commit
f99b5ad463
3 changed files with 14 additions and 9 deletions
|
@ -370,7 +370,7 @@
|
|||
tag = 'SOAKED_INDEX_END';
|
||||
this.soaked_index = false;
|
||||
} else if (include(CALLABLE, this.tag()) && !prev_spaced) {
|
||||
if (value === '(' && this.tag() !== 'THIS') {
|
||||
if (value === '(') {
|
||||
tag = 'CALL_START';
|
||||
}
|
||||
if (value === '[') {
|
||||
|
|
|
@ -269,7 +269,7 @@ exports.Lexer: class Lexer
|
|||
tag: 'SOAKED_INDEX_END'
|
||||
@soaked_index: false
|
||||
else if include(CALLABLE, @tag()) and not prev_spaced
|
||||
tag: 'CALL_START' if value is '(' and @tag() isnt 'THIS'
|
||||
tag: 'CALL_START' if value is '('
|
||||
tag: 'INDEX_START' if value is '['
|
||||
@i: + value.length
|
||||
return @tag_half_assignment tag if space and prev_spaced and @prev()[0] is 'ASSIGN' and include HALF_ASSIGNMENTS, tag
|
||||
|
|
|
@ -33,8 +33,6 @@ obj.unbound()
|
|||
obj.bound()
|
||||
|
||||
|
||||
# The named function should be cleared out before a call occurs:
|
||||
|
||||
# Python decorator style wrapper that memoizes any function
|
||||
memoize: (fn) ->
|
||||
cache: {}
|
||||
|
@ -74,14 +72,12 @@ ok result is 10
|
|||
|
||||
|
||||
# More fun with optional parens.
|
||||
|
||||
fn: (arg) -> arg
|
||||
|
||||
ok fn(fn {prop: 101}).prop is 101
|
||||
|
||||
|
||||
# Multi-blocks with optional parens.
|
||||
|
||||
result: fn( ->
|
||||
fn ->
|
||||
"Wrapped"
|
||||
|
@ -91,7 +87,6 @@ ok result()() is 'Wrapped'
|
|||
|
||||
|
||||
# And even with strange things like this:
|
||||
|
||||
funcs: [((x) -> x), ((x) -> x * x)]
|
||||
result: funcs[1] 5
|
||||
|
||||
|
@ -103,7 +98,6 @@ ok result is 'lo'
|
|||
|
||||
|
||||
# And with multiple single-line functions on the same line.
|
||||
|
||||
func: (x) -> (x) -> (x) -> x
|
||||
ok func(1)(2)(3) is 3
|
||||
|
||||
|
@ -113,7 +107,6 @@ del: -> 5
|
|||
ok del() is 5
|
||||
|
||||
# Ensure that functions can have a trailing comma in their argument list
|
||||
|
||||
mult: (x, mids..., y) ->
|
||||
x: * n for n in mids
|
||||
x: * y
|
||||
|
@ -129,6 +122,7 @@ result: combine (-> 1 + 2), 3
|
|||
|
||||
ok result is 9
|
||||
|
||||
|
||||
# Test for calls/parens/multiline-chains.
|
||||
f: (x) -> x
|
||||
result: (f 1).toString()
|
||||
|
@ -137,3 +131,14 @@ result: (f 1).toString()
|
|||
ok result is 1
|
||||
|
||||
|
||||
# Test that `this` is "callable".
|
||||
obj: {
|
||||
greet: (salutation) ->
|
||||
"Hello $salutation"
|
||||
|
||||
hello: ->
|
||||
this['greet'] "You"
|
||||
}
|
||||
|
||||
ok obj.hello() is 'Hello You'
|
||||
|
||||
|
|
Loading…
Reference in a new issue