_this to __this, for consistency. (StanAngeloff)
This commit is contained in:
parent
85ed376748
commit
93d77e2354
|
@ -205,7 +205,7 @@
|
|||
};
|
||||
Expressions.prototype.rewriteThis = function() {
|
||||
return this.traverseChildren(false, function(child) {
|
||||
return child instanceof ValueNode && child.base.value === 'this' ? (child.base = literal('_this')) : null;
|
||||
return child instanceof ValueNode && child.base.value === 'this' ? (child.base = literal('__this')) : null;
|
||||
});
|
||||
};
|
||||
Expressions.prototype.compile = function(o) {
|
||||
|
@ -999,7 +999,7 @@
|
|||
if (!(this.bound)) {
|
||||
return func;
|
||||
}
|
||||
return "(function(_this) {\n" + (this.idt(1)) + "return " + func + ";\n" + this.tab + "})(this)";
|
||||
return "(function(__this) {\n" + (this.idt(1)) + "return " + func + ";\n" + this.tab + "})(this)";
|
||||
};
|
||||
CodeNode.prototype.topSensitive = function() {
|
||||
return true;
|
||||
|
|
|
@ -37,24 +37,24 @@
|
|||
return true;
|
||||
};
|
||||
Rewriter.prototype.adjustComments = function() {
|
||||
return this.scanTokens((function(_this) {
|
||||
return this.scanTokens((function(__this) {
|
||||
return function(prev, token, post, i) {
|
||||
var _c, _d, after, before;
|
||||
if (!(token[0] === 'HERECOMMENT')) {
|
||||
return 1;
|
||||
}
|
||||
_c = [_this.tokens[i - 2], _this.tokens[i + 2]];
|
||||
_c = [__this.tokens[i - 2], __this.tokens[i + 2]];
|
||||
before = _c[0];
|
||||
after = _c[1];
|
||||
if (after && after[0] === 'INDENT') {
|
||||
_this.tokens.splice(i + 2, 1);
|
||||
before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR') ? _this.tokens.splice(i - 2, 1) : _this.tokens.splice(i, 0, after);
|
||||
__this.tokens.splice(i + 2, 1);
|
||||
before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR') ? __this.tokens.splice(i - 2, 1) : __this.tokens.splice(i, 0, after);
|
||||
} else if (prev && !('TERMINATOR' === (_d = prev[0]) || 'INDENT' === _d || 'OUTDENT' === _d)) {
|
||||
if (post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT') {
|
||||
_this.tokens.splice.apply(_this.tokens, [i + 2, 0].concat(_this.tokens.splice(i, 2)));
|
||||
_this.tokens[i + 2][0] !== 'TERMINATOR' ? _this.tokens.splice(i + 2, 0, ['TERMINATOR', "\n", prev[2]]) : null;
|
||||
__this.tokens.splice.apply(__this.tokens, [i + 2, 0].concat(__this.tokens.splice(i, 2)));
|
||||
__this.tokens[i + 2][0] !== 'TERMINATOR' ? __this.tokens.splice(i + 2, 0, ['TERMINATOR', "\n", prev[2]]) : null;
|
||||
} else {
|
||||
_this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
|
||||
__this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
@ -71,12 +71,12 @@
|
|||
return _c;
|
||||
};
|
||||
Rewriter.prototype.removeMidExpressionNewlines = function() {
|
||||
return this.scanTokens((function(_this) {
|
||||
return this.scanTokens((function(__this) {
|
||||
return function(prev, token, post, i) {
|
||||
if (!(post && include(EXPRESSION_CLOSE, post[0]) && token[0] === 'TERMINATOR')) {
|
||||
return 1;
|
||||
}
|
||||
_this.tokens.splice(i, 1);
|
||||
__this.tokens.splice(i, 1);
|
||||
return 0;
|
||||
};
|
||||
})(this));
|
||||
|
@ -85,7 +85,7 @@
|
|||
var brackets, parens;
|
||||
parens = [0];
|
||||
brackets = [0];
|
||||
return this.scanTokens((function(_this) {
|
||||
return this.scanTokens((function(__this) {
|
||||
return function(prev, token, post, i) {
|
||||
var _c;
|
||||
if ((_c = token[0]) === 'CALL_START') {
|
||||
|
@ -118,19 +118,19 @@
|
|||
Rewriter.prototype.addImplicitParentheses = function() {
|
||||
var closeCalls, stack;
|
||||
stack = [0];
|
||||
closeCalls = (function(_this) {
|
||||
closeCalls = (function(__this) {
|
||||
return function(i) {
|
||||
var _c, size, tmp;
|
||||
_c = stack[stack.length - 1];
|
||||
for (tmp = 0; (0 <= _c ? tmp < _c : tmp > _c); (0 <= _c ? tmp += 1 : tmp -= 1)) {
|
||||
_this.tokens.splice(i, 0, ['CALL_END', ')', _this.tokens[i][2]]);
|
||||
__this.tokens.splice(i, 0, ['CALL_END', ')', __this.tokens[i][2]]);
|
||||
}
|
||||
size = stack[stack.length - 1] + 1;
|
||||
stack[stack.length - 1] = 0;
|
||||
return size;
|
||||
};
|
||||
})(this);
|
||||
return this.scanTokens((function(_this) {
|
||||
return this.scanTokens((function(__this) {
|
||||
return function(prev, token, post, i) {
|
||||
var _c, _d, j, nx, open, size, tag;
|
||||
tag = token[0];
|
||||
|
@ -139,7 +139,7 @@
|
|||
}
|
||||
open = stack[stack.length - 1] > 0;
|
||||
if (prev && prev.spaced && include(IMPLICIT_FUNC, prev[0]) && include(IMPLICIT_CALL, tag) && !(tag === '!' && (('IN' === (_c = post[0]) || 'OF' === _c)))) {
|
||||
_this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
|
||||
__this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
|
||||
stack[stack.length - 1] += 1;
|
||||
if (include(EXPRESSION_START, tag)) {
|
||||
stack.push(0);
|
||||
|
@ -157,12 +157,12 @@
|
|||
}
|
||||
if (open && !token.generated && prev[0] !== ',' && (!post || include(IMPLICIT_END, tag))) {
|
||||
j = 1;
|
||||
while ((typeof (_d = (nx = _this.tokens[i + j])) !== "undefined" && _d !== null) && include(IMPLICIT_END, nx[0])) {
|
||||
while ((typeof (_d = (nx = __this.tokens[i + j])) !== "undefined" && _d !== null) && include(IMPLICIT_END, nx[0])) {
|
||||
j++;
|
||||
}
|
||||
if ((typeof nx !== "undefined" && nx !== null) && nx[0] === ',' && _this.tokens[i + j - 1][0] === 'OUTDENT') {
|
||||
if ((typeof nx !== "undefined" && nx !== null) && nx[0] === ',' && __this.tokens[i + j - 1][0] === 'OUTDENT') {
|
||||
if (tag === 'TERMINATOR') {
|
||||
_this.tokens.splice(i, 1);
|
||||
__this.tokens.splice(i, 1);
|
||||
}
|
||||
} else {
|
||||
size = closeCalls(i);
|
||||
|
@ -181,35 +181,35 @@
|
|||
})(this));
|
||||
};
|
||||
Rewriter.prototype.addImplicitIndentation = function() {
|
||||
return this.scanTokens((function(_this) {
|
||||
return this.scanTokens((function(__this) {
|
||||
return function(prev, token, post, i) {
|
||||
var _c, idx, indent, insertion, outdent, parens, pre, starter, tok;
|
||||
if (token[0] === 'ELSE' && prev[0] !== 'OUTDENT') {
|
||||
_this.tokens.splice.apply(_this.tokens, [i, 0].concat(_this.indentation(token)));
|
||||
__this.tokens.splice.apply(__this.tokens, [i, 0].concat(__this.indentation(token)));
|
||||
return 2;
|
||||
}
|
||||
if (token[0] === 'CATCH' && (_this.tokens[i + 2][0] === 'TERMINATOR' || _this.tokens[i + 2][0] === 'FINALLY')) {
|
||||
_this.tokens.splice.apply(_this.tokens, [i + 2, 0].concat(_this.indentation(token)));
|
||||
if (token[0] === 'CATCH' && (__this.tokens[i + 2][0] === 'TERMINATOR' || __this.tokens[i + 2][0] === 'FINALLY')) {
|
||||
__this.tokens.splice.apply(__this.tokens, [i + 2, 0].concat(__this.indentation(token)));
|
||||
return 4;
|
||||
}
|
||||
if (!(include(SINGLE_LINERS, token[0]) && post[0] !== 'INDENT' && !(token[0] === 'ELSE' && post[0] === 'IF'))) {
|
||||
return 1;
|
||||
}
|
||||
starter = token[0];
|
||||
_c = _this.indentation(token);
|
||||
_c = __this.indentation(token);
|
||||
indent = _c[0];
|
||||
outdent = _c[1];
|
||||
indent.generated = (outdent.generated = true);
|
||||
_this.tokens.splice(i + 1, 0, indent);
|
||||
__this.tokens.splice(i + 1, 0, indent);
|
||||
idx = i + 1;
|
||||
parens = 0;
|
||||
while (true) {
|
||||
idx += 1;
|
||||
tok = _this.tokens[idx];
|
||||
pre = _this.tokens[idx - 1];
|
||||
tok = __this.tokens[idx];
|
||||
pre = __this.tokens[idx - 1];
|
||||
if ((!tok || (include(SINGLE_CLOSERS, tok[0]) && tok[1] !== ';' && parens === 0) || (tok[0] === ')' && parens === 0)) && !(tok[0] === 'ELSE' && !('IF' === starter || 'THEN' === starter))) {
|
||||
insertion = pre[0] === "," ? idx - 1 : idx;
|
||||
_this.tokens.splice(insertion, 0, outdent);
|
||||
__this.tokens.splice(insertion, 0, outdent);
|
||||
break;
|
||||
}
|
||||
if (tok[0] === '(') {
|
||||
|
@ -222,7 +222,7 @@
|
|||
if (!(token[0] === 'THEN')) {
|
||||
return 1;
|
||||
}
|
||||
_this.tokens.splice(i, 1);
|
||||
__this.tokens.splice(i, 1);
|
||||
return 0;
|
||||
};
|
||||
})(this));
|
||||
|
@ -231,7 +231,7 @@
|
|||
var _c, _d, key, levels, line, open, openLine, unclosed, value;
|
||||
levels = {};
|
||||
openLine = {};
|
||||
this.scanTokens((function(_this) {
|
||||
this.scanTokens((function(__this) {
|
||||
return function(prev, token, post, i) {
|
||||
var _c, _d, _e, _f, close, open, pair;
|
||||
_d = pairs;
|
||||
|
@ -282,7 +282,7 @@
|
|||
val = _c[key];
|
||||
(debt[key] = 0);
|
||||
}
|
||||
return this.scanTokens((function(_this) {
|
||||
return this.scanTokens((function(__this) {
|
||||
return function(prev, token, post, i) {
|
||||
var inv, match, mtag, oppos, tag;
|
||||
tag = token[0];
|
||||
|
@ -293,7 +293,7 @@
|
|||
} else if (include(EXPRESSION_END, tag)) {
|
||||
if (debt[inv] > 0) {
|
||||
debt[inv] -= 1;
|
||||
_this.tokens.splice(i, 1);
|
||||
__this.tokens.splice(i, 1);
|
||||
return 0;
|
||||
} else {
|
||||
match = stack.pop();
|
||||
|
@ -304,11 +304,11 @@
|
|||
}
|
||||
debt[mtag] += 1;
|
||||
val = [oppos, mtag === 'INDENT' ? match[1] : oppos];
|
||||
if ((_this.tokens[i + 2] == undefined ? undefined : _this.tokens[i + 2][0]) === mtag) {
|
||||
_this.tokens.splice(i + 3, 0, val);
|
||||
if ((__this.tokens[i + 2] == undefined ? undefined : __this.tokens[i + 2][0]) === mtag) {
|
||||
__this.tokens.splice(i + 3, 0, val);
|
||||
stack.push(match);
|
||||
} else {
|
||||
_this.tokens.splice(i, 0, val);
|
||||
__this.tokens.splice(i, 0, val);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -185,11 +185,11 @@ exports.Expressions: class Expressions extends BaseNode
|
|||
@expressions[idx]: last.makeReturn()
|
||||
this
|
||||
|
||||
# A bound function uses a local `_this` variable instead of the real `this`.
|
||||
# A bound function uses a local `__this` variable instead of the real `this`.
|
||||
rewriteThis: ->
|
||||
@traverseChildren false, (child) ->
|
||||
if child instanceof ValueNode and child.base.value is 'this'
|
||||
child.base: literal '_this'
|
||||
child.base: literal '__this'
|
||||
|
||||
# An **Expressions** is the only node that can serve as the root.
|
||||
compile: (o) ->
|
||||
|
@ -892,7 +892,7 @@ exports.CodeNode: class CodeNode extends BaseNode
|
|||
func: "function(${ params.join(', ') }) {$code${ code and @idt(if @bound then 1 else 0) }}"
|
||||
func: "($func)" if top and not @bound
|
||||
return func unless @bound
|
||||
"(function(_this) {\n${@idt(1)}return $func;\n$@tab})(this)"
|
||||
"(function(__this) {\n${@idt(1)}return $func;\n$@tab})(this)"
|
||||
|
||||
topSensitive: ->
|
||||
true
|
||||
|
|
Loading…
Reference in New Issue