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, diff --git a/test/index.test.ts b/test/index.test.ts index d0ae0a8..4f2772a 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 = \` \` + " + `) +})