Skip to content

Commit

Permalink
fix: singlelineCommentsRE incorrect matching (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: chenying <1770365139@qq.com>
  • Loading branch information
YIngChenIt and chenying333 committed Sep 18, 2022
1 parent a6fda8c commit 6d87f32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 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,
Expand Down
18 changes: 18 additions & 0 deletions test/index.test.ts
Expand Up @@ -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 = \` \`
"
`)
})

0 comments on commit 6d87f32

Please sign in to comment.