From bd99b004137961b3b604fcd55602835bf6ffc522 Mon Sep 17 00:00:00 2001 From: Anthony Van de Gejuchte Date: Thu, 17 Dec 2015 23:02:35 +0100 Subject: [PATCH 1/3] Semicolon after do...while statement is optional --- lib/parse.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index de27d987..4d06ae05 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -724,9 +724,9 @@ function parse($TEXT, options) { ); }; - function semicolon() { + function semicolon(optional) { if (is("punc", ";")) next(); - else if (!can_insert_semicolon()) unexpected(); + else if (!optional && !can_insert_semicolon()) unexpected(); }; function parenthesised() { @@ -814,7 +814,7 @@ function parse($TEXT, options) { case "do": return new AST_Do({ body : in_loop(statement), - condition : (expect_token("keyword", "while"), tmp = parenthesised(), semicolon(), tmp) + condition : (expect_token("keyword", "while"), tmp = parenthesised(), semicolon(true), tmp) }); case "while": From 5cd26c005b3b171f4da8b6732de224089e55ae8a Mon Sep 17 00:00:00 2001 From: Anthony Van de Gejuchte Date: Fri, 18 Dec 2015 14:39:48 +0100 Subject: [PATCH 2/3] Add tests --- test/compress/loops.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/compress/loops.js b/test/compress/loops.js index cdf1f045..b7194fed 100644 --- a/test/compress/loops.js +++ b/test/compress/loops.js @@ -121,3 +121,25 @@ drop_if_else_break_4: { for (; bar() && (x(), y(), foo());) baz(), z(), k(); } } + +parse_do_while_with_semicolon: { + input: { + do { + x(); + } while (false);y() + } + expect: { + do x(); while (false);y(); + } +} + +parse_do_while_without_semicolon: { + input: { + do { + x(); + } while (false)y() + } + expect: { + do x(); while (false);y(); + } +} \ No newline at end of file From 0cabedc52617cef9623627b390703c011ab6c0b6 Mon Sep 17 00:00:00 2001 From: Anthony Van de Gejuchte Date: Fri, 18 Dec 2015 15:25:24 +0100 Subject: [PATCH 3/3] Disable loop optimization for parse-only tests --- test/compress/loops.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/compress/loops.js b/test/compress/loops.js index b7194fed..91aa1c5f 100644 --- a/test/compress/loops.js +++ b/test/compress/loops.js @@ -123,6 +123,7 @@ drop_if_else_break_4: { } parse_do_while_with_semicolon: { + options = { loops: false }; input: { do { x(); @@ -134,6 +135,7 @@ parse_do_while_with_semicolon: { } parse_do_while_without_semicolon: { + options = { loops: false }; input: { do { x();