mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
more underscore, and removing custom_assign and return from conditional compilation
This commit is contained in:
@@ -93,31 +93,26 @@ _.reduceRight: obj, memo, iterator, context =>
|
|||||||
if obj and _.isFunction(obj.filter) then return obj.filter(iterator, context).
|
if obj and _.isFunction(obj.filter) then return obj.filter(iterator, context).
|
||||||
results: []
|
results: []
|
||||||
_.each(obj, (value, index, list =>
|
_.each(obj, (value, index, list =>
|
||||||
iterator.call(context, value, index, list) and results.push(value).))
|
results.push(value) if iterator.call(context, value, index, list).))
|
||||||
results.
|
results.
|
||||||
|
|
||||||
#
|
# Return all the elements for which a truth test fails.
|
||||||
# # Return all the elements for which a truth test fails.
|
_.reject: obj, iterator, context =>
|
||||||
# _.reject = function(obj, iterator, context) {
|
results: []
|
||||||
# var results = [];
|
_.each(obj, (value, index, list =>
|
||||||
# _.each(obj, function(value, index, list) {
|
results.push(value) if not iterator.call(context, value, index, list).))
|
||||||
# !iterator.call(context, value, index, list) && results.push(value);
|
results.
|
||||||
# });
|
|
||||||
# return results;
|
# Determine whether all of the elements match a truth test. Delegate to
|
||||||
# };
|
# JavaScript 1.6's every(), if it is present.
|
||||||
#
|
_.all: obj, iterator, context =>
|
||||||
# # Determine whether all of the elements match a truth test. Delegate to
|
iterator ||= _.identity
|
||||||
# # JavaScript 1.6's every(), if it is present.
|
return obj.every(iterator, context) if obj and _.isFunction(obj.every)
|
||||||
# _.all = function(obj, iterator, context) {
|
result: true
|
||||||
# iterator = iterator || _.identity;
|
_.each(obj, (value, index, list =>
|
||||||
# if (obj && _.isFunction(obj.every)) return obj.every(iterator, context);
|
_.breakLoop() unless result: result and iterator.call(context, value, index, list).))
|
||||||
# var result = true;
|
result.
|
||||||
# _.each(obj, function(value, index, list) {
|
|
||||||
# if (!(result = result && iterator.call(context, value, index, list))) _.breakLoop();
|
|
||||||
# });
|
|
||||||
# return result;
|
|
||||||
# };
|
|
||||||
#
|
|
||||||
# # Determine if at least one element in the object matches a truth test. Use
|
# # Determine if at least one element in the object matches a truth test. Use
|
||||||
# # JavaScript 1.6's some(), if it exists.
|
# # JavaScript 1.6's some(), if it exists.
|
||||||
# _.any = function(obj, iterator, context) {
|
# _.any = function(obj, iterator, context) {
|
||||||
|
|||||||
@@ -377,12 +377,11 @@ module CoffeeScript
|
|||||||
last = @variable.last.to_s
|
last = @variable.last.to_s
|
||||||
proto = name[PROTO_ASSIGN, 1]
|
proto = name[PROTO_ASSIGN, 1]
|
||||||
o = o.merge(:assign => @variable, :last_assign => last, :proto_assign => proto)
|
o = o.merge(:assign => @variable, :last_assign => last, :proto_assign => proto)
|
||||||
postfix = o[:return] ? ";\n#{o[:indent]}return #{name}" : ''
|
|
||||||
return write("#{name}: #{@value.compile(o)}") if @context == :object
|
return write("#{name}: #{@value.compile(o)}") if @context == :object
|
||||||
return write("#{name} = #{@value.compile(o)}#{postfix}") if @variable.properties? && !@value.custom_assign?
|
|
||||||
o[:scope].find(name) unless @variable.properties?
|
o[:scope].find(name) unless @variable.properties?
|
||||||
return write(@value.compile(o)) if @value.custom_assign?
|
return write(@value.compile(o)) if @value.custom_assign?
|
||||||
write("#{name} = #{@value.compile(o)}#{postfix}")
|
val = "#{name} = #{@value.compile(o)}"
|
||||||
|
write(o[:return] && !@value.custom_return? ? "return (#{val})" : val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -728,8 +727,11 @@ module CoffeeScript
|
|||||||
# force sub-else bodies into statement form.
|
# force sub-else bodies into statement form.
|
||||||
def compile_statement(o)
|
def compile_statement(o)
|
||||||
indent = o[:indent]
|
indent = o[:indent]
|
||||||
|
cond_o = o.dup
|
||||||
|
cond_o.delete(:assign)
|
||||||
|
cond_o.delete(:return)
|
||||||
o[:indent] += TAB
|
o[:indent] += TAB
|
||||||
if_part = "if (#{@condition.compile(o)}) {\n#{Expressions.wrap(@body).compile(o)}\n#{indent}}"
|
if_part = "if (#{@condition.compile(cond_o)}) {\n#{Expressions.wrap(@body).compile(o)}\n#{indent}}"
|
||||||
return if_part unless @else_body
|
return if_part unless @else_body
|
||||||
else_part = chain? ?
|
else_part = chain? ?
|
||||||
" else #{@else_body.compile(o.merge(:indent => indent))}" :
|
" else #{@else_body.compile(o.merge(:indent => indent))}" :
|
||||||
|
|||||||
Reference in New Issue
Block a user