1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

removing arguments-to-array-conversion from coffee

This commit is contained in:
Jeremy Ashkenas 2010-03-15 20:46:14 -07:00
parent 119b80d449
commit 73074daa07
4 changed files with 9 additions and 22 deletions

View file

@ -228,14 +228,8 @@
// Compile the expressions body for the contents of a function, with
// declarations of all inner variables pushed up to the top.
Expressions.prototype.compile_with_declarations = function compile_with_declarations(o) {
var args, code;
var code;
code = this.compile_node(o);
args = this.contains(function(node) {
return node instanceof ValueNode && node.is_arguments();
});
if (args) {
code = '' + (this.tab) + "arguments = Array.prototype.slice.call(arguments, 0);\n" + code;
}
if (o.scope.has_assignments(this)) {
code = '' + (this.tab) + "var " + (o.scope.compiled_assignments()) + ";\n" + code;
}
@ -355,9 +349,6 @@
ValueNode.prototype.is_splice = function is_splice() {
return this.has_properties() && this.properties[this.properties.length - 1] instanceof SliceNode;
};
ValueNode.prototype.is_arguments = function is_arguments() {
return this.base.value === 'arguments';
};
// The value can be unwrapped as its inner node, if there are no attached
// properties.
ValueNode.prototype.unwrap = function unwrap() {

View file

@ -20,7 +20,6 @@
// flag. Instead, you're responsible for interpreting the options object.
OptionParser.prototype.parse = function parse(args) {
var _a, _b, _c, arg, is_option, matched_rule, options, rule;
arguments = Array.prototype.slice.call(arguments, 0);
options = {
arguments: []
};

View file

@ -167,8 +167,6 @@ exports.Expressions: class Expressions extends BaseNode
# declarations of all inner variables pushed up to the top.
compile_with_declarations: (o) ->
code: @compile_node(o)
args: @contains (node) -> node instanceof ValueNode and node.is_arguments()
code: "${@tab}arguments = Array.prototype.slice.call(arguments, 0);\n$code" if args
code: "${@tab}var ${o.scope.compiled_assignments()};\n$code" if o.scope.has_assignments(this)
code: "${@tab}var ${o.scope.compiled_declarations()};\n$code" if o.scope.has_declarations(this)
code
@ -266,9 +264,6 @@ exports.ValueNode: class ValueNode extends BaseNode
is_splice: ->
@has_properties() and @properties[@properties.length - 1] instanceof SliceNode
is_arguments: ->
@base.value is 'arguments'
# The value can be unwrapped as its inner node, if there are no attached
# properties.
unwrap: ->

View file

@ -17,12 +17,6 @@ ok(area(
) is 100, 'newline delimited arguments')
curried: ->
ok area.apply(this, arguments.concat(20, 20)) is 100, 'arguments converted into an array'
curried 10, 10
func: ->
arguments: 25
arguments
@ -32,3 +26,11 @@ ok func(100) is 25, 'arguments as a regular identifier'
this.arguments: 10
ok @arguments is 10, 'arguments accessed as a property'
sum_of_args: ->
sum: 0
sum += val for val in arguments
sum
ok sum_of_args(1, 2, 3, 4, 5) is 15