From e826973b76e356f7aabb3bedd96d82bf336da4ee Mon Sep 17 00:00:00 2001 From: kzc Date: Thu, 16 Nov 2017 12:34:57 -0500 Subject: [PATCH] fix template expression parse of regex and sequence (#2488) fixes #2487 --- lib/parse.js | 3 +- test/compress/template-string.js | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index 35615752..867383bf 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -2107,7 +2107,8 @@ function parse($TEXT, options) { })); while (S.token.end === false) { next(); - segments.push(expression()); + handle_regexp(); + segments.push(expression(true)); if (!is_token("template_substitution")) { unexpected(); diff --git a/test/compress/template-string.js b/test/compress/template-string.js index a84c1042..e93bdd15 100644 --- a/test/compress/template-string.js +++ b/test/compress/template-string.js @@ -458,3 +458,51 @@ semicolons: { } expect_exact: "foo;`bar`\n" } + +regex_1: { + input: { + console.log(`${/a/} ${6/2} ${/b/.test("b")} ${1?/c/:/d/}`); + } + expect_exact: 'console.log(`${/a/} ${6/2} ${/b/.test("b")} ${1?/c/:/d/}`);' + expect_stdout: "/a/ 3 true /c/" + node_version: ">=4" +} + +regex_2: { + options = { + evaluate: true, + unsafe: true, + } + input: { + console.log(`${/a/} ${6/2} ${/b/.test("b")} ${1?/c/:/d/}`); + } + expect: { + console.log("/a/ 3 true /c/"); + } + expect_stdout: "/a/ 3 true /c/" + node_version: ">=4" +} + +sequence_1: { + input: { + console.log(`${1,2} ${/a/,/b/}`); + } + expect_exact: 'console.log(`${1,2} ${/a/,/b/}`);' + expect_stdout: "2 /b/" + node_version: ">=4" +} + +sequence_2: { + options = { + evaluate: true, + side_effects: true, + } + input: { + console.log(`${1,2} ${/a/,/b/}`); + } + expect: { + console.log("2 /b/"); + } + expect_stdout: "2 /b/" + node_version: ">=4" +}