diff --git a/packages/vite/src/node/cleanString.ts b/packages/vite/src/node/cleanString.ts index 2e273f8dab57a5..d68f08502a8344 100644 --- a/packages/vite/src/node/cleanString.ts +++ b/packages/vite/src/node/cleanString.ts @@ -2,9 +2,9 @@ import type { RollupError } from 'rollup' // bank on the non-overlapping nature of regex matches and combine all filters into one giant regex // /`([^`\$\{\}]|\$\{(`|\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 = /"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'/ -const commentsRE = /\/\*(.|[\r\n])*?\*\/|\/\/.*/ -const regexpRE = /\/([^\/\r\n]|(?<=\\)\/)*\// +const stringsRE = /"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'/.source +const commentsRE = /\/\*(.|[\r\n])*?\*\/|\/\/.*/.source +const regexpRE = /\/([^\/\r\n]|(?<=\\)\/)*\//.source const cleanerRE = new RegExp(`${stringsRE}|${commentsRE}|${regexpRE}`, 'g') const blankReplacer = (s: string) => ' '.repeat(s.length)