removing block literals in favor of implicit calls

This commit is contained in:
Jeremy Ashkenas
2010-01-26 21:05:26 -05:00
parent aa93d3c387
commit e998a81b63
4 changed files with 728 additions and 738 deletions

View File

@@ -568,7 +568,7 @@
# Add all mutator Array functions to the wrapper.
_.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift']) (name) ->
_.each ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], (name) ->
method: Array.prototype[name]
wrapper.prototype[name]: ->
method.apply(this._wrapped, arguments)
@@ -576,7 +576,7 @@
# Add all accessor Array functions to the wrapper.
_.each(['concat', 'join', 'slice']) (name) ->
_.each ['concat', 'join', 'slice'], (name) ->
method: Array.prototype[name]
wrapper.prototype[name]: ->
result(method.apply(this._wrapped, arguments), this._chain)

View File

@@ -292,7 +292,6 @@ rule
# The list of arguments to a function invocation.
Arguments:
CALL_START ArgList CALL_END { result = val[1] }
| CALL_START ArgList CALL_END Code { result = val[1] << val[3] }
;
# Calling super.

File diff suppressed because it is too large Load Diff

View File

@@ -20,10 +20,11 @@ module CoffeeScript
# Tokens pairs that, in immediate succession, indicate an implicit call.
IMPLICIT_FUNC = [:IDENTIFIER, :SUPER]
IMPLICIT_END = [:IF, :UNLESS, :FOR, :WHILE, "\n", :PARAM_START, :OUTDENT]
IMPLICIT_END = [:IF, :UNLESS, :FOR, :WHILE, "\n", :OUTDENT]
IMPLICIT_CALL = [:IDENTIFIER, :NUMBER, :STRING, :JS, :REGEX, :NEW, :PARAM_START,
:TRY, :DELETE, :INSTANCEOF, :TYPEOF, :SWITCH, :ARGUMENTS,
:TRUE, :FALSE, :YES, :NO, :ON, :OFF, '!', '!!', :NOT, '->', '=>']
:TRUE, :FALSE, :YES, :NO, :ON, :OFF, '!', '!!', :NOT,
'->', '=>', '[', '(', '{']
# The inverse mappings of token pairs we're trying to fix up.
INVERSES = BALANCED_PAIRS.inject({}) do |memo, pair|
@@ -193,8 +194,7 @@ module CoffeeScript
last = stack.pop
stack[-1] += last
end
if (stack.last > 0 && (IMPLICIT_END.include?(token[0]) || post.nil?)) &&
!(token[0] == :PARAM_START && prev[0] == ',')
if stack.last > 0 && (IMPLICIT_END.include?(token[0]) || post.nil?)
idx = token[0] == :OUTDENT ? i + 1 : i
stack.last.times { @tokens.insert(idx, [:CALL_END, Value.new(')', token[1].line)]) }
size, stack[-1] = stack[-1] + 1, 0
@@ -203,7 +203,7 @@ module CoffeeScript
next 1 unless IMPLICIT_FUNC.include?(prev[0]) && IMPLICIT_CALL.include?(token[0])
@tokens.insert(i, [:CALL_START, Value.new('(', token[1].line)])
stack[-1] += 1
next token[0] == :PARAM_START ? 1 : 2
next 2
end
end