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

[CS2] Remove unnecessary utility helper functions (#4526)

* Uncomment module test that was waiting for classes to be supported

* Rely on native indexOf

* Replace `bind` helper with native `bind` (no shortcut necessary)

* Update output

* Update modules class tests

* Remove helper for prototype extends

* Update docs to reflect removed extends operator

* Add shortcut for splice, like we have for slice
This commit is contained in:
Geoffrey Booth 2017-04-25 07:10:42 -07:00 committed by GitHub
parent 7e35c2c3da
commit 07ae1edb44
12 changed files with 70 additions and 96 deletions

View file

@ -1,7 +1,8 @@
// Generated by CoffeeScript 2.0.0-beta1
(function() {
var Access, Arr, Assign, AwaitReturn, Base, Block, BooleanLiteral, Call, Class, Code, CodeFragment, Comment, ExecutableClassBody, Existence, Expansion, ExportAllDeclaration, ExportDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, ExportSpecifier, ExportSpecifierList, Extends, For, HoistTarget, IdentifierLiteral, If, ImportClause, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, ImportSpecifierList, In, Index, InfinityLiteral, JS_FORBIDDEN, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, ModuleDeclaration, ModuleSpecifier, ModuleSpecifierList, NEGATE, NO, NaNLiteral, NullLiteral, NumberLiteral, Obj, Op, Param, Parens, PassthroughLiteral, PropertyName, Range, RegexLiteral, RegexWithInterpolations, Return, SIMPLENUM, Scope, Slice, Splat, StatementLiteral, StringLiteral, StringWithInterpolations, Super, SuperCall, Switch, TAB, THIS, TaggedTemplateCall, ThisLiteral, Throw, Try, UTILITIES, UndefinedLiteral, Value, While, YES, YieldReturn, addLocationDataFn, compact, del, ends, extend, flatten, fragmentsToText, isLiteralArguments, isLiteralThis, isUnassignable, locationDataToString, merge, multident, shouldCacheOrIsAssignable, some, starts, throwSyntaxError, unfoldSoak, utility,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
splice = [].splice,
indexOf = [].indexOf,
slice = [].slice;
Error.stackTraceLimit = 2e308;
@ -241,7 +242,7 @@
for (i = k = 0, len2 = children.length; k < len2; i = ++k) {
child = children[i];
if (match(child)) {
[].splice.apply(children, [i, i - i + 1].concat(ref2 = replacement(child, this))), ref2;
splice.apply(children, [i, i - i + 1].concat(ref2 = replacement(child, this))), ref2;
return true;
} else {
if (child.replaceInContext(match, replacement)) {
@ -341,7 +342,7 @@
for (i = j = fragments.length - 1; j >= 0; i = j += -1) {
fragment = fragments[i];
if (fragment.fragments) {
[].splice.apply(fragments, [i, i - i + 1].concat(ref1 = this.expand(fragment.fragments))), ref1;
splice.apply(fragments, [i, i - i + 1].concat(ref1 = this.expand(fragment.fragments))), ref1;
}
}
return fragments;
@ -1830,7 +1831,7 @@
end++;
}
pushSlice();
[].splice.apply(expressions, [i, i - i + 1].concat(exprs)), exprs;
splice.apply(expressions, [i, i - i + 1].concat(exprs)), exprs;
i += exprs.length;
} else {
if (initializerExpression = this.addInitializerExpression(expression)) {
@ -1942,7 +1943,7 @@
for (j = ref1.length - 1; j >= 0; j += -1) {
name = ref1[j];
name = new Value(new ThisLiteral, [name]).compile(o);
results.push(new Literal(`${name} = ${utility('bind', o)}(${name}, this)`));
results.push(new Literal(`${name} = ${name}.bind(this)`));
}
return results;
}).call(this);
@ -2629,7 +2630,7 @@
to = "9e9";
}
[valDef, valRef] = this.value.cache(o, LEVEL_LIST);
answer = [].concat(this.makeCode(`[].splice.apply(${name}, [${fromDecl}, ${to}].concat(`), valDef, this.makeCode(")), "), valRef);
answer = [].concat(this.makeCode(`${utility('splice', o)}.apply(${name}, [${fromDecl}, ${to}].concat(`), valDef, this.makeCode(")), "), valRef);
if (o.level > LEVEL_TOP) {
return this.wrapInParentheses(answer);
} else {
@ -4180,23 +4181,20 @@
})();
UTILITIES = {
extend: function(o) {
return `function(child, parent) { for (var key in parent) { if (${utility('hasProp', o)}.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); return child; }`;
},
bind: function() {
return 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }';
},
indexOf: function() {
return "[].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }";
},
modulo: function() {
return "function(a, b) { return (+a % (b = +b) + b) % b; }";
return 'function(a, b) { return (+a % (b = +b) + b) % b; }';
},
hasProp: function() {
return '{}.hasOwnProperty';
},
indexOf: function() {
return '[].indexOf';
},
slice: function() {
return '[].slice';
},
splice: function() {
return '[].splice';
}
};