Content-Length: 310436 | pFad | http://github.com/vitejs/vite/pull/8040/commits/ba02475cb37eb77f363158b6ecc302691e458739

D2 fix: use Vitest for unit testing, clean regex bug by antfu · Pull Request #8040 · vitejs/vite · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use Vitest for unit testing, clean regex bug #8040

Merged
merged 6 commits into from
May 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: empty regex for clean string
  • Loading branch information
antfu committed May 6, 2022
commit ba02475cb37eb77f363158b6ecc302691e458739
Binary file modified packages/vite/src/node/__tests__/cleanString.spec.ts
Binary file not shown.
9 changes: 6 additions & 3 deletions packages/vite/src/node/cleanString.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import { multilineCommentsRE, singlelineCommentsRE } from './utils'
// /`([^`\$\{\}]|\$\{(`|\g<1>)*\})*`/g can match nested string template
// but js not support match expression(\g<0>). so clean string template(`...`) in other ways.
const stringsRE = /"([^"\r\n]|(?<=\\)")*"|'([^'\r\n]|(?<=\\)')*'/g
const regexRE = /\/.*?(?<!\\)\/[gimsuy]*/g
const cleanerRE = new RegExp(
`${stringsRE.source}|${multilineCommentsRE.source}|${singlelineCommentsRE.source}`,
'g'
@@ -15,9 +16,11 @@ const stringBlankReplacer = (s: string) =>
`${s[0]}${'\0'.repeat(s.length - 2)}${s[0]}`

export function emptyString(raw: string): string {
let res = raw.replace(cleanerRE, (s: string) =>
s[0] === '/' ? blankReplacer(s) : stringBlankReplacer(s)
)
let res = raw
.replace(cleanerRE, (s: string) =>
s[0] === '/' ? blankReplacer(s) : stringBlankReplacer(s)
)
.replace(regexRE, (s) => stringBlankReplacer(s))

let lastEnd = 0
let start = 0
3 changes: 2 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,8 @@ export default defineConfig({
exclude: [
'**/node_modules/**',
'**/dist/**',
'./packages/playground/**/*.*'
'./packages/playground/**/*.*',
'./packages/temp/**/*.*'
]
}
})








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/vitejs/vite/pull/8040/commits/ba02475cb37eb77f363158b6ecc302691e458739

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy