merged matehat's utility branch, arraySlice -> slice, removed dead dependency...
This commit is contained in:
parent
a6248d03e5
commit
f0d731009f
|
@ -1,6 +1,6 @@
|
|||
(function(){
|
||||
var ACCESSORS, ASSIGNMENT, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMMENT_CLEANER, CONVERSIONS, HALF_ASSIGNMENTS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, INTERPOLATION, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, Lexer, MULTILINER, MULTI_DENT, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_ESCAPE, REGEX_FLAGS, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, STRING_NEWLINES, WHITESPACE, _a, _b, _c, _d, balanced_string, compact, count, helpers, include, k, starts, u;
|
||||
var __arraySlice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
|
||||
var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
|
||||
// The CoffeeScript Lexer. Uses a series of token-matching regexes to attempt
|
||||
// matches against the beginning of the source code. When a match is found,
|
||||
// a token is produced, we consume the match, and start again. Tokens are in the
|
||||
|
@ -237,7 +237,7 @@
|
|||
// balanced (ie. strings, JS literals).
|
||||
Lexer.prototype.balanced_token = function balanced_token() {
|
||||
var delimited;
|
||||
delimited = __arraySlice.call(arguments, 0, arguments.length - 0);
|
||||
delimited = __slice.call(arguments, 0, arguments.length - 0);
|
||||
return balanced_string(this.chunk, delimited);
|
||||
};
|
||||
// Matches and conumes comments. We pass through comments into JavaScript,
|
||||
|
|
10
lib/nodes.js
10
lib/nodes.js
|
@ -14,11 +14,11 @@
|
|||
}, __bind = function(func, obj, args) {
|
||||
obj = obj || {};
|
||||
return (typeof args !== 'undefined' && args !== null) ? function() {
|
||||
return func.apply(obj, args.concat(__arraySlice.call(arguments, 0)));
|
||||
return func.apply(obj, args.concat(__slice.call(arguments, 0)));
|
||||
} : function() {
|
||||
return func.apply(obj, arguments);
|
||||
};
|
||||
}, __arraySlice = Array.prototype.slice;
|
||||
}, __slice = Array.prototype.slice;
|
||||
// `nodes.coffee` contains all of the node classes for the syntax tree. Most
|
||||
// nodes are created as the result of actions in the [grammar](grammar.html),
|
||||
// but some are created by other nodes as a method of code generation. To convert
|
||||
|
@ -1157,15 +1157,15 @@
|
|||
o.scope.assign(trailing.compile(o), "arguments[arguments.length - " + this.trailings.length + " + " + i + "]");
|
||||
i += 1;
|
||||
}
|
||||
return "" + name + " = " + (o.scope.utility('arraySlice')) + ".call(arguments, " + this.index + ", arguments.length - " + (this.trailings.length) + ")";
|
||||
return "" + name + " = " + (o.scope.utility('slice')) + ".call(arguments, " + this.index + ", arguments.length - " + (this.trailings.length) + ")";
|
||||
};
|
||||
// A compiling a splat as a destructuring assignment means slicing arguments
|
||||
// from the right-hand-side's corresponding array.
|
||||
SplatNode.prototype.compile_value = function compile_value(o, name, index, trailings) {
|
||||
if ((typeof trailings !== "undefined" && trailings !== null)) {
|
||||
return "" + (o.scope.utility('arraySlice')) + ".call(" + name + ", " + index + ", " + (name) + ".length - " + trailings + ")";
|
||||
return "" + (o.scope.utility('slice')) + ".call(" + name + ", " + index + ", " + (name) + ".length - " + trailings + ")";
|
||||
} else {
|
||||
return "" + (o.scope.utility('arraySlice')) + ".call(" + name + ", " + index + ")";
|
||||
return "" + (o.scope.utility('slice')) + ".call(" + name + ", " + index + ")";
|
||||
}
|
||||
};
|
||||
// Utility function that converts arbitrary number of elements, mixed with
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
arguments: []
|
||||
};
|
||||
args = normalize_arguments(args);
|
||||
while (arg = args.shift()) {
|
||||
while ((arg = args.shift())) {
|
||||
is_option = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
|
||||
matched_rule = false;
|
||||
_b = this.rules;
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
var __bind = function(func, obj, args) {
|
||||
obj = obj || {};
|
||||
return (typeof args !== 'undefined' && args !== null) ? function() {
|
||||
return func.apply(obj, args.concat(__arraySlice.call(arguments, 0)));
|
||||
return func.apply(obj, args.concat(__slice.call(arguments, 0)));
|
||||
} : function() {
|
||||
return func.apply(obj, arguments);
|
||||
};
|
||||
}, __arraySlice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
|
||||
}, __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
|
||||
// The CoffeeScript language has a good deal of optional syntax, implicit syntax,
|
||||
// and shorthand syntax. This can greatly complicate a grammar and bloat
|
||||
// the resulting parse table. Instead of making the parser handle it all, we take
|
||||
|
|
|
@ -12,15 +12,14 @@
|
|||
return "" + (utilities.key(key)) + " = " + (utilities.functions[key].replace(/\n/g, "\n" + tab) || 'undefined');
|
||||
};
|
||||
utilities.dependencies = {
|
||||
bind: ['arraySlice'],
|
||||
splice: ['range']
|
||||
bind: ['slice']
|
||||
};
|
||||
utilities.functions = {
|
||||
extend: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n}",
|
||||
bind: "function(func, obj, args) {\n obj = obj || {};\n return (typeof args !== 'undefined' && args !== null) ? function() {\n return func.apply(obj, args.concat(" + (utilities.key('arraySlice')) + ".call(arguments, 0)));\n } : function() {\n return func.apply(obj, arguments);\n };\n}",
|
||||
bind: "function(func, obj, args) {\n obj = obj || {};\n return (typeof args !== 'undefined' && args !== null) ? function() {\n return func.apply(obj, args.concat(" + (utilities.key('slice')) + ".call(arguments, 0)));\n } : function() {\n return func.apply(obj, arguments);\n };\n}",
|
||||
range: "function(array, from, to, exclusive) {\n return [\n (from < 0 ? from + array.length : from || 0),\n (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)\n ];\n}",
|
||||
hasProp: 'Object.prototype.hasOwnProperty',
|
||||
arraySlice: 'Array.prototype.slice'
|
||||
slice: 'Array.prototype.slice'
|
||||
};
|
||||
return utilities;
|
||||
}).call(this);
|
||||
|
|
|
@ -845,13 +845,13 @@ exports.SplatNode: class SplatNode extends BaseNode
|
|||
for trailing in @trailings
|
||||
o.scope.assign(trailing.compile(o), "arguments[arguments.length - $@trailings.length + $i]")
|
||||
i: + 1
|
||||
"$name = ${o.scope.utility('arraySlice')}.call(arguments, $@index, arguments.length - ${@trailings.length})"
|
||||
"$name = ${o.scope.utility('slice')}.call(arguments, $@index, arguments.length - ${@trailings.length})"
|
||||
|
||||
# A compiling a splat as a destructuring assignment means slicing arguments
|
||||
# from the right-hand-side's corresponding array.
|
||||
compile_value: (o, name, index, trailings) ->
|
||||
if trailings? then "${o.scope.utility('arraySlice')}.call($name, $index, ${name}.length - $trailings)" \
|
||||
else "${o.scope.utility('arraySlice')}.call($name, $index)"
|
||||
if trailings? then "${o.scope.utility('slice')}.call($name, $index, ${name}.length - $trailings)" \
|
||||
else "${o.scope.utility('slice')}.call($name, $index)"
|
||||
|
||||
# Utility function that converts arbitrary number of elements, mixed with
|
||||
# splats, to a proper array
|
||||
|
|
|
@ -3,16 +3,16 @@ this.exports: this unless process?
|
|||
exports.utilities: class utilities
|
||||
@key: (name) ->
|
||||
"__$name"
|
||||
|
||||
|
||||
@format: (key, tab) ->
|
||||
"${utilities.key(key)} = ${utilities.functions[key].replace(/\n/g, "\n$tab") or 'undefined'}"
|
||||
|
||||
|
||||
@dependencies: {
|
||||
bind: ['arraySlice']
|
||||
splice: ['range']
|
||||
bind: ['slice']
|
||||
}
|
||||
|
||||
|
||||
@functions: {
|
||||
|
||||
extend: """
|
||||
function(child, parent) {
|
||||
var ctor = function(){ };
|
||||
|
@ -22,16 +22,18 @@ exports.utilities: class utilities
|
|||
child.prototype.constructor = child;
|
||||
}
|
||||
"""
|
||||
|
||||
bind: """
|
||||
function(func, obj, args) {
|
||||
obj = obj || {};
|
||||
return (typeof args !== 'undefined' && args !== null) ? function() {
|
||||
return func.apply(obj, args.concat(${utilities.key('arraySlice')}.call(arguments, 0)));
|
||||
return func.apply(obj, args.concat(${utilities.key('slice')}.call(arguments, 0)));
|
||||
} : function() {
|
||||
return func.apply(obj, arguments);
|
||||
};
|
||||
}
|
||||
"""
|
||||
|
||||
range: """
|
||||
function(array, from, to, exclusive) {
|
||||
return [
|
||||
|
@ -40,6 +42,8 @@ exports.utilities: class utilities
|
|||
];
|
||||
}
|
||||
"""
|
||||
|
||||
hasProp: 'Object.prototype.hasOwnProperty'
|
||||
arraySlice: 'Array.prototype.slice'
|
||||
|
||||
slice: 'Array.prototype.slice'
|
||||
}
|
Loading…
Reference in New Issue