mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
More tweaks to Slice#compileNode
This commit is contained in:
@@ -795,12 +795,12 @@
|
||||
Slice.__super__.constructor.call(this);
|
||||
}
|
||||
Slice.prototype.compileNode = function(o) {
|
||||
var compiled, definition, from, fromStr, reference, to, toStr, _ref, _ref2;
|
||||
var compiled, from, fromStr, to, toStr, _ref;
|
||||
_ref = this.range, to = _ref.to, from = _ref.from;
|
||||
fromStr = from && from.compile(o, LEVEL_PAREN) || '0';
|
||||
compiled = to && to.compile(o, LEVEL_PAREN);
|
||||
if (to && !(!this.range.exclusive && +compiled === -1)) {
|
||||
toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? (+compiled + 1).toString() : ((_ref2 = to.cache(o, LEVEL_PAREN), definition = _ref2[0], reference = _ref2[1], _ref2), reference === definition ? "" + reference + " + 1 ? " + reference + " + 1 : 9e9" : "(" + definition + " + 1) ? " + reference + " : 9e9"));
|
||||
toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? (+compiled + 1).toString() : "(" + compiled + " + 1) || 9e9");
|
||||
}
|
||||
return ".slice(" + fromStr + (toStr || '') + ")";
|
||||
};
|
||||
|
||||
@@ -112,13 +112,13 @@
|
||||
start = null;
|
||||
startIndent = 0;
|
||||
condition = function(token, i) {
|
||||
var one, tag, three, two, _ref, _ref2, _ref3;
|
||||
_ref2 = this.tokens.slice(i + 1, (_ref = i + 3 + 1) ? _ref : 9e9), one = _ref2[0], two = _ref2[1], three = _ref2[2];
|
||||
var one, tag, three, two, _ref, _ref2;
|
||||
_ref = this.tokens.slice(i + 1, (i + 3 + 1) || 9e9), one = _ref[0], two = _ref[1], three = _ref[2];
|
||||
if ('HERECOMMENT' === (one != null ? one[0] : void 0)) {
|
||||
return false;
|
||||
}
|
||||
tag = token[0];
|
||||
return ((tag === 'TERMINATOR' || tag === 'OUTDENT') && !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':')) || (tag === ',' && one && ((_ref3 = one[0]) !== 'IDENTIFIER' && _ref3 !== 'NUMBER' && _ref3 !== 'STRING' && _ref3 !== '@' && _ref3 !== 'TERMINATOR' && _ref3 !== 'OUTDENT'));
|
||||
return ((tag === 'TERMINATOR' || tag === 'OUTDENT') && !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':')) || (tag === ',' && one && ((_ref2 = one[0]) !== 'IDENTIFIER' && _ref2 !== 'NUMBER' && _ref2 !== 'STRING' && _ref2 !== '@' && _ref2 !== 'TERMINATOR' && _ref2 !== 'OUTDENT'));
|
||||
};
|
||||
action = function(token, i) {
|
||||
return this.tokens.splice(i, 0, ['}', '}', token[2]]);
|
||||
@@ -159,13 +159,13 @@
|
||||
return this.tokens.splice(idx, 0, ['CALL_END', ')', token[2]]);
|
||||
};
|
||||
return this.scanTokens(function(token, i, tokens) {
|
||||
var callObject, current, next, prev, seenSingle, tag, _ref, _ref2, _ref3, _ref4;
|
||||
var callObject, current, next, prev, seenSingle, tag, _ref, _ref2, _ref3;
|
||||
tag = token[0];
|
||||
if (tag === 'CLASS' || tag === 'IF' || tag === 'UNLESS') {
|
||||
noCall = true;
|
||||
}
|
||||
_ref2 = tokens.slice(i - 1, (_ref = i + 1 + 1) ? _ref : 9e9), prev = _ref2[0], current = _ref2[1], next = _ref2[2];
|
||||
callObject = !noCall && tag === 'INDENT' && next && next.generated && next[0] === '{' && prev && (_ref3 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref3) >= 0);
|
||||
_ref = tokens.slice(i - 1, (i + 1 + 1) || 9e9), prev = _ref[0], current = _ref[1], next = _ref[2];
|
||||
callObject = !noCall && tag === 'INDENT' && next && next.generated && next[0] === '{' && prev && (_ref2 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref2) >= 0);
|
||||
seenSingle = false;
|
||||
if (__indexOf.call(LINEBREAKS, tag) >= 0) {
|
||||
noCall = false;
|
||||
@@ -173,7 +173,7 @@
|
||||
if (prev && !prev.spaced && tag === '?') {
|
||||
token.call = true;
|
||||
}
|
||||
if (!(callObject || (prev != null ? prev.spaced : void 0) && (prev.call || (_ref4 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref4) >= 0)) && (__indexOf.call(IMPLICIT_CALL, tag) >= 0 || !(token.spaced || token.newLine) && __indexOf.call(IMPLICIT_UNSPACED_CALL, tag) >= 0))) {
|
||||
if (!(callObject || (prev != null ? prev.spaced : void 0) && (prev.call || (_ref3 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref3) >= 0)) && (__indexOf.call(IMPLICIT_CALL, tag) >= 0 || !(token.spaced || token.newLine) && __indexOf.call(IMPLICIT_UNSPACED_CALL, tag) >= 0))) {
|
||||
return 1;
|
||||
}
|
||||
tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
|
||||
|
||||
@@ -677,11 +677,7 @@ exports.Slice = class Slice extends Base
|
||||
else if SIMPLENUM.test compiled
|
||||
(+compiled + 1).toString()
|
||||
else
|
||||
[definition, reference] = to.cache o, LEVEL_PAREN
|
||||
if reference is definition
|
||||
"#{reference} + 1 ? #{reference} + 1 : 9e9"
|
||||
else
|
||||
"(#{definition} + 1) ? #{reference} : 9e9"
|
||||
"(#{compiled} + 1) || 9e9"
|
||||
".slice(#{ fromStr }#{ toStr or '' })"
|
||||
|
||||
#### Obj
|
||||
|
||||
Reference in New Issue
Block a user