diff --git a/lib/parse.js b/lib/parse.js index c2d5ac8..66a7167 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -276,9 +276,9 @@ function ConditionBlock(entry, buffer, os) { let ros = os - 1; while ((ch = buffer[ros]) && ~_nb_white.indexOf(ch)) ros--; - // if there is and it's not a ';' then it's not a block at all, + // if there is and it's not a newline or ';' then it's not a block at all, // just set the exit at the end of the line - if (~_eol.indexOf(ch)) { + if (!~_eol.indexOf(ch)) { os += entry.length; while ((ch = buffer[os]) && !~_eol.indexOf(ch) && ch !== '#') os++; return { diff --git a/test/parse.js b/test/parse.js index 4f9badc..e23ca0a 100644 --- a/test/parse.js +++ b/test/parse.js @@ -151,7 +151,7 @@ def other! end`; check(contextString); }); - it("recognises a while", function() { + it("recognises two whiles", function() { const contextString = ` def fn a = 1 while false @@ -161,6 +161,29 @@ def fn end end +def other! +end`; + check(contextString); + }); + it("recognises a single while", function() { + const contextString = ` +def fn + while true + a = 1 + break + end +end + +def other! +end`; + check(contextString); + }); + it("recognises a while modifier", function() { + const contextString = ` +def fn + a = 1 while false +end + def other! end`; check(contextString);