From bf77f06892e855f037021ca14beb05e2f8415a74 Mon Sep 17 00:00:00 2001 From: chenying <1770365139@qq.com> Date: Sat, 17 Sep 2022 14:21:19 +0800 Subject: [PATCH 1/3] fix: singlelineCommentsRE incorrect matching --- src/regex.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/regex.ts b/src/regex.ts index 7acc773..aa41bc5 100644 --- a/src/regex.ts +++ b/src/regex.ts @@ -1,5 +1,5 @@ const multilineCommentsRE = /\/\*.*?\*\//gms -const singlelineCommentsRE = /\/\/.*$/gm +const singlelineCommentsRE = /(?:^|\n|\r)\s*\/\/.*(?:\r|\n|$)/gm const templateLiteralRE = /\$\{(\s*(?:(?!\$\{).|\n|\r)*?\s*)\}/g const quotesRE = [ /(["'`])((?:\\\1|(?!\1)|.|\r)*?)\1/gm, From 618a81b8567c916c299b239cbdb44c3839c03312 Mon Sep 17 00:00:00 2001 From: chenying <1770365139@qq.com> Date: Sun, 18 Sep 2022 12:37:30 +0800 Subject: [PATCH 2/3] chore: add test --- test/index.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/index.test.ts b/test/index.test.ts index d0ae0a8..a25306e 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -188,3 +188,21 @@ test('forgiving', () => { " `) }) + +test('// in string', () => { + const str = [ + 'const url= `http://www.xx.com`;', + `const url1= 'http://www.xx.com';`, + 'onMounted(() => console.log(123))', + 'const str = `hello world`', + '// Notes' + ].join('\n') + + expect(executeWithVerify(str)).toMatchInlineSnapshot(` + "const url= \` \`; + const url1= \' \'; + onMounted(() => console.log(123)) + const str = \` \` + " + `) +}) From dbd69f3b43dc8ffb445dc18d944b69480cfb72a4 Mon Sep 17 00:00:00 2001 From: chenying <1770365139@qq.com> Date: Sun, 18 Sep 2022 15:33:15 +0800 Subject: [PATCH 3/3] chore: lint --- test/index.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.test.ts b/test/index.test.ts index a25306e..4f2772a 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -192,10 +192,10 @@ test('forgiving', () => { test('// in string', () => { const str = [ 'const url= `http://www.xx.com`;', - `const url1= 'http://www.xx.com';`, + 'const url1= \'http://www.xx.com\';', 'onMounted(() => console.log(123))', 'const str = `hello world`', - '// Notes' + '// Notes', ].join('\n') expect(executeWithVerify(str)).toMatchInlineSnapshot(`