From b7faa4a7f23fa6f4e3fa90fccd91a5c615144ccf Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 21 Jun 2010 23:54:43 -0400 Subject: [PATCH] using the new in-tests for the Rewriter. --- lib/rewriter.js | 10 +++++----- src/rewriter.coffee | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/rewriter.js b/lib/rewriter.js index 63152670..ecab3a0b 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -61,7 +61,7 @@ Rewriter.prototype.adjustComments = function() { return this.scanTokens((function(__this) { var __func = function(prev, token, post, i) { - var _c, after, before; + var _c, _d, after, before; if (!(include(COMMENTS, token[0]))) { return 1; } @@ -71,7 +71,7 @@ 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); - } 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]]); return 2; } else if (before && before[0] === 'OUTDENT' && prev && prev[0] === 'TERMINATOR' && post && post[0] === 'TERMINATOR' && after && after[0] === 'ELSE') { @@ -174,13 +174,13 @@ })(this); return this.scanTokens((function(__this) { 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]; if (tag === 'OUTDENT') { stack[stack.length - 2] += stack.pop(); } 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]]); stack[stack.length - 1] += 1; if (include(EXPRESSION_START, tag)) { @@ -199,7 +199,7 @@ } if (open && !token.generated && (!post || include(IMPLICIT_END, tag))) { 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++; } if ((typeof nx !== "undefined" && nx !== null) && nx[0] === ',') { diff --git a/src/rewriter.coffee b/src/rewriter.coffee index 1b147d10..79a1255f 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -61,7 +61,7 @@ exports.Rewriter: class Rewriter @tokens.splice i - 2, 1 else @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' @tokens.splice(i, 0, @tokens.splice(i + 2, 2)...) else @@ -127,7 +127,7 @@ exports.Rewriter: class Rewriter stack[stack.length - 2]: + stack.pop() if tag is 'OUTDENT' open: stack[stack.length - 1] > 0 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]] stack[stack.length - 1]: + 1 stack.push 0 if include(EXPRESSION_START, tag)