slightly optimizing return values of AssignNodes. Issue #539

This commit is contained in:
Jeremy Ashkenas
2010-07-24 12:27:11 -07:00
parent 87226b6f44
commit dc1288d319
7 changed files with 22 additions and 25 deletions

View File

@@ -17,12 +17,11 @@
action = _a[0];
description = _a[1];
}
tasks[name] = {
return (tasks[name] = {
name: name,
description: description,
action: action
};
return tasks[name];
});
},
option: function(letter, flag, description) {
return switches.push([letter, flag, description]);

View File

@@ -51,8 +51,7 @@
},
setInput: function(tokens) {
this.tokens = tokens;
this.pos = 0;
return this.pos;
return (this.pos = 0);
},
upcomingInput: function() {
return "";

View File

@@ -195,8 +195,7 @@
options.compile = options.compile || !!o.output;
options.run = !(o.compile || o.print || o.lint);
options.print = !!(o.print || (o.eval || o.stdio && o.compile));
sources = options.arguments;
return sources;
return (sources = options.arguments);
};
compileOptions = function(source) {
var o;

View File

@@ -399,8 +399,7 @@
} else if (_d === ')') {
tok[0] = 'PARAM_END';
} else if (_d === '(' || _d === 'CALL_START') {
tok[0] = 'PARAM_START';
return tok[0];
return (tok[0] = 'PARAM_START');
}
}
return true;
@@ -555,8 +554,7 @@
return null;
}
if (typeof newTag !== "undefined" && newTag !== null) {
tok[0] = newTag;
return tok[0];
return (tok[0] = newTag);
}
return tok[0];
};
@@ -566,8 +564,7 @@
return null;
}
if (typeof val !== "undefined" && val !== null) {
tok[1] = val;
return tok[1];
return (tok[1] = val);
}
return tok[1];
};

View File

@@ -394,8 +394,7 @@
part = prop.compile(o);
baseline += part;
complete += part;
this.last = part;
return this.last;
return (this.last = part);
}
}).call(this);
}
@@ -447,7 +446,7 @@
CallNode.prototype.superReference = function(o) {
var meth, methname;
methname = o.scope.method.name;
meth = (function() {
return (meth = (function() {
if (o.scope.method.proto) {
return "" + (o.scope.method.proto) + ".__superClass__." + methname;
} else if (methname) {
@@ -455,8 +454,7 @@
} else {
throw new Error("cannot call super on an anonymous function.");
}
})();
return meth;
})());
};
CallNode.prototype.compileNode = function(o) {
var _b, _c, _d, _e, _f, _g, _h, arg, args, compilation;
@@ -836,7 +834,11 @@
return this.variable instanceof ValueNode;
};
AssignNode.prototype.makeReturn = function() {
return new Expressions([this, new ReturnNode(this.variable)]);
if (this.isStatement()) {
return new Expressions([this, new ReturnNode(this.variable)]);
} else {
return AssignNode.__superClass__.makeReturn.call(this);
}
};
AssignNode.prototype.isStatement = function() {
return this.isValue() && (this.variable.isArray() || this.variable.isObject());

View File

@@ -41,8 +41,7 @@
return false;
};
Scope.prototype.parameter = function(name) {
this.variables[name] = 'param';
return this.variables[name];
return (this.variables[name] = 'param');
};
Scope.prototype.check = function(name) {
if (this.variables.hasOwnProperty(name)) {
@@ -60,11 +59,10 @@
return this.tempVar;
};
Scope.prototype.assign = function(name, value) {
this.variables[name] = {
return (this.variables[name] = {
value: value,
assigned: true
};
return this.variables[name];
});
};
Scope.prototype.hasDeclarations = function(body) {
return body === this.expressions && this.any(function(k, val) {

View File

@@ -758,7 +758,10 @@ exports.AssignNode: class AssignNode extends BaseNode
@variable instanceof ValueNode
makeReturn: ->
return new Expressions [this, new ReturnNode(@variable)]
if @isStatement()
return new Expressions [this, new ReturnNode(@variable)]
else
super()
isStatement: ->
@isValue() and (@variable.isArray() or @variable.isObject())