From 0cf8b0f362b62a268e597e092ba23da26829cce7 Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Mon, 27 Oct 2014 06:01:19 +0300 Subject: [PATCH] StateBlock() cleanup --- lib/common/html_re.js | 1 - lib/ruler.js | 4 ++-- lib/rules_block/state_block.js | 24 +++--------------------- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/lib/common/html_re.js b/lib/common/html_re.js index f059e22..f4264dc 100644 --- a/lib/common/html_re.js +++ b/lib/common/html_re.js @@ -12,7 +12,6 @@ function replace(regex, options) { return new RegExp(regex, options); } val = val.source || val; - //val = val.replace(/(^|[^\[])\^/g, '$1'); regex = regex.replace(name, val); return self; }; diff --git a/lib/ruler.js b/lib/ruler.js index 38a3803..9721022 100644 --- a/lib/ruler.js +++ b/lib/ruler.js @@ -181,7 +181,7 @@ Ruler.prototype.enable = function (list, strict) { list.forEach(function (name) { var idx = this.find(name); - if (idx < 0) { throw new Error('Rules namager: invalid rule name ' + name);} + if (idx < 0) { throw new Error('Rules namager: invalid rule name ' + name); } this.rules[idx].enabled = true; }, this); @@ -201,7 +201,7 @@ Ruler.prototype.disable = function (list) { list.forEach(function (name) { var idx = this.find(name); - if (idx < 0) { throw new Error('Rules namager: invalid rule name ' + name);} + if (idx < 0) { throw new Error('Rules namager: invalid rule name ' + name); } this.rules[idx].enabled = false; }, this); diff --git a/lib/rules_block/state_block.js b/lib/rules_block/state_block.js index 512ca22..dedd7b2 100644 --- a/lib/rules_block/state_block.js +++ b/lib/rules_block/state_block.js @@ -6,11 +6,6 @@ function StateBlock(src, parser, tokens, options, env) { var ch, s, start, pos, len, indent, indent_found; - // Prepare string to parse: - // - // - replace tabs with spaces - // - remove `\r` to simplify newlines check (???) - this.src = src; // Shortcuts to simplify nested calls @@ -57,24 +52,20 @@ function StateBlock(src, parser, tokens, options, env) { indent++; continue; } else { - this.tShift.push(indent); indent_found = true; } } - if (ch === 0x0A) { + if (ch === 0x0A || pos === len - 1) { this.bMarks.push(start); this.eMarks.push(pos); + this.tShift.push(indent); + indent_found = false; indent = 0; start = pos + 1; } } - if (ch !== 0x0A) { - this.bMarks.push(start); - this.eMarks.push(len); - if (!indent_found) { this.tShift.push(indent); } - } // Push fake entry to simplify cache bounds checks this.bMarks.push(s.length); @@ -161,14 +152,5 @@ StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF return queue.join(''); }; -// Create shadow clone of curent state with new input data -StateBlock.prototype.clone = function clone(src) { - return new StateBlock( - src, - this.parser, - this.tokens, - this.options - ); -}; module.exports = StateBlock;