using the new in-tests for the Rewriter.
This commit is contained in:
parent
0fcfb80be4
commit
b7faa4a7f2
|
@ -61,7 +61,7 @@
|
||||||
Rewriter.prototype.adjustComments = function() {
|
Rewriter.prototype.adjustComments = function() {
|
||||||
return this.scanTokens((function(__this) {
|
return this.scanTokens((function(__this) {
|
||||||
var __func = function(prev, token, post, i) {
|
var __func = function(prev, token, post, i) {
|
||||||
var _c, after, before;
|
var _c, _d, after, before;
|
||||||
if (!(include(COMMENTS, token[0]))) {
|
if (!(include(COMMENTS, token[0]))) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@
|
||||||
if (after && after[0] === 'INDENT') {
|
if (after && after[0] === 'INDENT') {
|
||||||
this.tokens.splice(i + 2, 1);
|
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);
|
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 && prev[0] !== 'TERMINATOR' && prev[0] !== 'INDENT' && prev[0] !== 'OUTDENT') {
|
} else if (prev && !('TERMINATOR' === (_d = prev[0]) || 'INDENT' === _d || 'OUTDENT' === _d)) {
|
||||||
post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT' ? this.tokens.splice.apply(this.tokens, [i, 0].concat(this.tokens.splice(i + 2, 2))) : this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
|
post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT' ? this.tokens.splice.apply(this.tokens, [i, 0].concat(this.tokens.splice(i + 2, 2))) : this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
|
||||||
return 2;
|
return 2;
|
||||||
} else if (before && before[0] === 'OUTDENT' && prev && prev[0] === 'TERMINATOR' && post && post[0] === 'TERMINATOR' && after && after[0] === 'ELSE') {
|
} else if (before && before[0] === 'OUTDENT' && prev && prev[0] === 'TERMINATOR' && post && post[0] === 'TERMINATOR' && after && after[0] === 'ELSE') {
|
||||||
|
@ -174,13 +174,13 @@
|
||||||
})(this);
|
})(this);
|
||||||
return this.scanTokens((function(__this) {
|
return this.scanTokens((function(__this) {
|
||||||
var __func = function(prev, token, post, i) {
|
var __func = function(prev, token, post, i) {
|
||||||
var _c, j, nx, open, size, tag;
|
var _c, _d, j, nx, open, size, tag;
|
||||||
tag = token[0];
|
tag = token[0];
|
||||||
if (tag === 'OUTDENT') {
|
if (tag === 'OUTDENT') {
|
||||||
stack[stack.length - 2] += stack.pop();
|
stack[stack.length - 2] += stack.pop();
|
||||||
}
|
}
|
||||||
open = stack[stack.length - 1] > 0;
|
open = stack[stack.length - 1] > 0;
|
||||||
if (prev && prev.spaced && include(IMPLICIT_FUNC, prev[0]) && include(IMPLICIT_CALL, tag) && !(tag === '!' && (post[0] === 'IN' || post[0] === 'OF'))) {
|
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;
|
stack[stack.length - 1] += 1;
|
||||||
if (include(EXPRESSION_START, tag)) {
|
if (include(EXPRESSION_START, tag)) {
|
||||||
|
@ -199,7 +199,7 @@
|
||||||
}
|
}
|
||||||
if (open && !token.generated && (!post || include(IMPLICIT_END, tag))) {
|
if (open && !token.generated && (!post || include(IMPLICIT_END, tag))) {
|
||||||
j = 1;
|
j = 1;
|
||||||
while ((typeof (_c = (nx = this.tokens[i + j])) !== "undefined" && _c !== null) && include(IMPLICIT_END, nx[0])) {
|
while ((typeof (_d = (nx = this.tokens[i + j])) !== "undefined" && _d !== null) && include(IMPLICIT_END, nx[0])) {
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
if ((typeof nx !== "undefined" && nx !== null) && nx[0] === ',') {
|
if ((typeof nx !== "undefined" && nx !== null) && nx[0] === ',') {
|
||||||
|
|
|
@ -61,7 +61,7 @@ exports.Rewriter: class Rewriter
|
||||||
@tokens.splice i - 2, 1
|
@tokens.splice i - 2, 1
|
||||||
else
|
else
|
||||||
@tokens.splice i, 0, after
|
@tokens.splice i, 0, after
|
||||||
else if prev and prev[0] isnt 'TERMINATOR' and prev[0] isnt 'INDENT' and prev[0] isnt 'OUTDENT'
|
else if prev and prev[0] not in ['TERMINATOR', 'INDENT', 'OUTDENT']
|
||||||
if post and post[0] is 'TERMINATOR' and after and after[0] is 'OUTDENT'
|
if post and post[0] is 'TERMINATOR' and after and after[0] is 'OUTDENT'
|
||||||
@tokens.splice(i, 0, @tokens.splice(i + 2, 2)...)
|
@tokens.splice(i, 0, @tokens.splice(i + 2, 2)...)
|
||||||
else
|
else
|
||||||
|
@ -127,7 +127,7 @@ exports.Rewriter: class Rewriter
|
||||||
stack[stack.length - 2]: + stack.pop() if tag is 'OUTDENT'
|
stack[stack.length - 2]: + stack.pop() if tag is 'OUTDENT'
|
||||||
open: stack[stack.length - 1] > 0
|
open: stack[stack.length - 1] > 0
|
||||||
if prev and prev.spaced and include(IMPLICIT_FUNC, prev[0]) and include(IMPLICIT_CALL, tag) and
|
if prev and prev.spaced and include(IMPLICIT_FUNC, prev[0]) and include(IMPLICIT_CALL, tag) and
|
||||||
not (tag is '!' and (post[0] is 'IN' or post[0] is 'OF'))
|
not (tag is '!' and (post[0] in ['IN', 'OF']))
|
||||||
@tokens.splice i, 0, ['CALL_START', '(', token[2]]
|
@tokens.splice i, 0, ['CALL_START', '(', token[2]]
|
||||||
stack[stack.length - 1]: + 1
|
stack[stack.length - 1]: + 1
|
||||||
stack.push 0 if include(EXPRESSION_START, tag)
|
stack.push 0 if include(EXPRESSION_START, tag)
|
||||||
|
|
Loading…
Reference in New Issue