mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
merged matehat's utility branch, arraySlice -> slice, removed dead dependency...
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
(function(){
|
(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 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
|
// 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,
|
// 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
|
// a token is produced, we consume the match, and start again. Tokens are in the
|
||||||
@@ -237,7 +237,7 @@
|
|||||||
// balanced (ie. strings, JS literals).
|
// balanced (ie. strings, JS literals).
|
||||||
Lexer.prototype.balanced_token = function balanced_token() {
|
Lexer.prototype.balanced_token = function balanced_token() {
|
||||||
var delimited;
|
var delimited;
|
||||||
delimited = __arraySlice.call(arguments, 0, arguments.length - 0);
|
delimited = __slice.call(arguments, 0, arguments.length - 0);
|
||||||
return balanced_string(this.chunk, delimited);
|
return balanced_string(this.chunk, delimited);
|
||||||
};
|
};
|
||||||
// Matches and conumes comments. We pass through comments into JavaScript,
|
// 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) {
|
}, __bind = function(func, obj, args) {
|
||||||
obj = obj || {};
|
obj = obj || {};
|
||||||
return (typeof args !== 'undefined' && args !== null) ? function() {
|
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() {
|
} : function() {
|
||||||
return func.apply(obj, arguments);
|
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.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),
|
// 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
|
// 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 + "]");
|
o.scope.assign(trailing.compile(o), "arguments[arguments.length - " + this.trailings.length + " + " + i + "]");
|
||||||
i += 1;
|
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
|
// A compiling a splat as a destructuring assignment means slicing arguments
|
||||||
// from the right-hand-side's corresponding array.
|
// from the right-hand-side's corresponding array.
|
||||||
SplatNode.prototype.compile_value = function compile_value(o, name, index, trailings) {
|
SplatNode.prototype.compile_value = function compile_value(o, name, index, trailings) {
|
||||||
if ((typeof trailings !== "undefined" && trailings !== null)) {
|
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 {
|
} 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
|
// Utility function that converts arbitrary number of elements, mixed with
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
arguments: []
|
arguments: []
|
||||||
};
|
};
|
||||||
args = normalize_arguments(args);
|
args = normalize_arguments(args);
|
||||||
while (arg = args.shift()) {
|
while ((arg = args.shift())) {
|
||||||
is_option = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
|
is_option = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
|
||||||
matched_rule = false;
|
matched_rule = false;
|
||||||
_b = this.rules;
|
_b = this.rules;
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
var __bind = function(func, obj, args) {
|
var __bind = function(func, obj, args) {
|
||||||
obj = obj || {};
|
obj = obj || {};
|
||||||
return (typeof args !== 'undefined' && args !== null) ? function() {
|
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() {
|
} : function() {
|
||||||
return func.apply(obj, arguments);
|
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,
|
// The CoffeeScript language has a good deal of optional syntax, implicit syntax,
|
||||||
// and shorthand syntax. This can greatly complicate a grammar and bloat
|
// 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
|
// 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');
|
return "" + (utilities.key(key)) + " = " + (utilities.functions[key].replace(/\n/g, "\n" + tab) || 'undefined');
|
||||||
};
|
};
|
||||||
utilities.dependencies = {
|
utilities.dependencies = {
|
||||||
bind: ['arraySlice'],
|
bind: ['slice']
|
||||||
splice: ['range']
|
|
||||||
};
|
};
|
||||||
utilities.functions = {
|
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}",
|
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}",
|
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',
|
hasProp: 'Object.prototype.hasOwnProperty',
|
||||||
arraySlice: 'Array.prototype.slice'
|
slice: 'Array.prototype.slice'
|
||||||
};
|
};
|
||||||
return utilities;
|
return utilities;
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|||||||
@@ -845,13 +845,13 @@ exports.SplatNode: class SplatNode extends BaseNode
|
|||||||
for trailing in @trailings
|
for trailing in @trailings
|
||||||
o.scope.assign(trailing.compile(o), "arguments[arguments.length - $@trailings.length + $i]")
|
o.scope.assign(trailing.compile(o), "arguments[arguments.length - $@trailings.length + $i]")
|
||||||
i: + 1
|
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
|
# A compiling a splat as a destructuring assignment means slicing arguments
|
||||||
# from the right-hand-side's corresponding array.
|
# from the right-hand-side's corresponding array.
|
||||||
compile_value: (o, name, index, trailings) ->
|
compile_value: (o, name, index, trailings) ->
|
||||||
if trailings? then "${o.scope.utility('arraySlice')}.call($name, $index, ${name}.length - $trailings)" \
|
if trailings? then "${o.scope.utility('slice')}.call($name, $index, ${name}.length - $trailings)" \
|
||||||
else "${o.scope.utility('arraySlice')}.call($name, $index)"
|
else "${o.scope.utility('slice')}.call($name, $index)"
|
||||||
|
|
||||||
# Utility function that converts arbitrary number of elements, mixed with
|
# Utility function that converts arbitrary number of elements, mixed with
|
||||||
# splats, to a proper array
|
# splats, to a proper array
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ this.exports: this unless process?
|
|||||||
exports.utilities: class utilities
|
exports.utilities: class utilities
|
||||||
@key: (name) ->
|
@key: (name) ->
|
||||||
"__$name"
|
"__$name"
|
||||||
|
|
||||||
@format: (key, tab) ->
|
@format: (key, tab) ->
|
||||||
"${utilities.key(key)} = ${utilities.functions[key].replace(/\n/g, "\n$tab") or 'undefined'}"
|
"${utilities.key(key)} = ${utilities.functions[key].replace(/\n/g, "\n$tab") or 'undefined'}"
|
||||||
|
|
||||||
@dependencies: {
|
@dependencies: {
|
||||||
bind: ['arraySlice']
|
bind: ['slice']
|
||||||
splice: ['range']
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@functions: {
|
@functions: {
|
||||||
|
|
||||||
extend: """
|
extend: """
|
||||||
function(child, parent) {
|
function(child, parent) {
|
||||||
var ctor = function(){ };
|
var ctor = function(){ };
|
||||||
@@ -22,16 +22,18 @@ exports.utilities: class utilities
|
|||||||
child.prototype.constructor = child;
|
child.prototype.constructor = child;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
bind: """
|
bind: """
|
||||||
function(func, obj, args) {
|
function(func, obj, args) {
|
||||||
obj = obj || {};
|
obj = obj || {};
|
||||||
return (typeof args !== 'undefined' && args !== null) ? function() {
|
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() {
|
} : function() {
|
||||||
return func.apply(obj, arguments);
|
return func.apply(obj, arguments);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
range: """
|
range: """
|
||||||
function(array, from, to, exclusive) {
|
function(array, from, to, exclusive) {
|
||||||
return [
|
return [
|
||||||
@@ -40,6 +42,8 @@ exports.utilities: class utilities
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hasProp: 'Object.prototype.hasOwnProperty'
|
hasProp: 'Object.prototype.hasOwnProperty'
|
||||||
arraySlice: 'Array.prototype.slice'
|
|
||||||
|
slice: 'Array.prototype.slice'
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user