mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
more underscore, and removing custom_assign and return from conditional compilation
This commit is contained in:
parent
097bede5c8
commit
d7dd18b476
2 changed files with 24 additions and 27 deletions
|
@ -93,31 +93,26 @@ _.reduceRight: obj, memo, iterator, context =>
|
|||
if obj and _.isFunction(obj.filter) then return obj.filter(iterator, context).
|
||||
results: []
|
||||
_.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.
|
||||
|
||||
#
|
||||
# # Return all the elements for which a truth test fails.
|
||||
# _.reject = function(obj, iterator, context) {
|
||||
# var results = [];
|
||||
# _.each(obj, function(value, index, list) {
|
||||
# !iterator.call(context, value, index, list) && results.push(value);
|
||||
# });
|
||||
# return results;
|
||||
# };
|
||||
#
|
||||
# # Determine whether all of the elements match a truth test. Delegate to
|
||||
# # JavaScript 1.6's every(), if it is present.
|
||||
# _.all = function(obj, iterator, context) {
|
||||
# iterator = iterator || _.identity;
|
||||
# if (obj && _.isFunction(obj.every)) return obj.every(iterator, context);
|
||||
# var result = true;
|
||||
# _.each(obj, function(value, index, list) {
|
||||
# if (!(result = result && iterator.call(context, value, index, list))) _.breakLoop();
|
||||
# });
|
||||
# return result;
|
||||
# };
|
||||
#
|
||||
# Return all the elements for which a truth test fails.
|
||||
_.reject: obj, iterator, context =>
|
||||
results: []
|
||||
_.each(obj, (value, index, list =>
|
||||
results.push(value) if not iterator.call(context, value, index, list).))
|
||||
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 =>
|
||||
iterator ||= _.identity
|
||||
return obj.every(iterator, context) if obj and _.isFunction(obj.every)
|
||||
result: true
|
||||
_.each(obj, (value, index, list =>
|
||||
_.breakLoop() unless result: result and iterator.call(context, value, index, list).))
|
||||
result.
|
||||
|
||||
# # Determine if at least one element in the object matches a truth test. Use
|
||||
# # JavaScript 1.6's some(), if it exists.
|
||||
# _.any = function(obj, iterator, context) {
|
||||
|
|
|
@ -377,12 +377,11 @@ module CoffeeScript
|
|||
last = @variable.last.to_s
|
||||
proto = name[PROTO_ASSIGN, 1]
|
||||
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)}#{postfix}") if @variable.properties? && !@value.custom_assign?
|
||||
o[:scope].find(name) unless @variable.properties?
|
||||
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
|
||||
|
||||
|
@ -728,8 +727,11 @@ module CoffeeScript
|
|||
# force sub-else bodies into statement form.
|
||||
def compile_statement(o)
|
||||
indent = o[:indent]
|
||||
cond_o = o.dup
|
||||
cond_o.delete(:assign)
|
||||
cond_o.delete(:return)
|
||||
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
|
||||
else_part = chain? ?
|
||||
" else #{@else_body.compile(o.merge(:indent => indent))}" :
|
||||
|
|
Loading…
Reference in a new issue