Skip to content

Commit 086dc36

Browse files
authored
perf: regexp perf issues, refactor regexp stylistic issues (#10905)
fix vitejs/vite#10900
1 parent 50f55fd commit 086dc36

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

.eslintrc.cjs

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ module.exports = defineConfig({
77
extends: [
88
'eslint:recommended',
99
'plugin:node/recommended',
10-
'plugin:@typescript-eslint/recommended'
10+
'plugin:@typescript-eslint/recommended',
11+
'plugin:regexp/recommended'
1112
],
12-
plugins: ['import'],
13+
plugins: ['import', 'regexp'],
1314
parser: '@typescript-eslint/parser',
1415
parserOptions: {
1516
sourceType: 'module',
@@ -97,7 +98,9 @@ module.exports = defineConfig({
9798
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
9899
allowSeparatedGroups: false
99100
}
100-
]
101+
],
102+
103+
'regexp/no-contradiction-with-assertion': 'error'
101104
},
102105
overrides: [
103106
{

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"eslint-define-config": "^1.11.0",
6767
"eslint-plugin-import": "^2.26.0",
6868
"eslint-plugin-node": "^11.1.0",
69+
"eslint-plugin-regexp": "^1.10.0",
6970
"execa": "^6.1.0",
7071
"fast-glob": "^3.2.12",
7172
"fs-extra": "^10.1.0",

packages/plugin-vue/src/handleHotUpdate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { ResolvedOptions } from '.'
1111

1212
const debug = _debug('vite:hmr')
1313

14-
const directRequestRE = /(\?|&)direct\b/
14+
const directRequestRE = /(?:\?|&)direct\b/
1515

1616
/**
1717
* Vite-specific HMR handling
@@ -148,7 +148,7 @@ export async function handleHotUpdate(
148148
affectedModules.add(mainModule)
149149
} else if (mainModule && !affectedModules.has(mainModule)) {
150150
const styleImporters = [...mainModule.importers].filter((m) =>
151-
/\.css($|\?)/.test(m.url)
151+
/\.css(?:$|\?)/.test(m.url)
152152
)
153153
styleImporters.forEach((m) => affectedModules.add(m))
154154
}

playground/vue-server-origin/__tests__/vue-server-origin.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isBuild, page } from '~utils'
33

44
test('should render', async () => {
55
const expected = isBuild
6-
? /assets\/asset\.[0-9a-f]+\.png/
6+
? /assets\/asset\.[\da-f]+\.png/
77
: 'http://localhost/server-origin/test/assets/asset.png'
88

99
expect(await page.getAttribute('img', 'src')).toMatch(expected)

scripts/rollupLicensePlugin.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) {
9090
'\n' +
9191
licenseText
9292
.trim()
93-
.replace(/(\r\n|\r)/gm, '\n')
93+
.replace(/(\r\n|\r)/g, '\n')
9494
.split('\n')
9595
.map((line) => `> ${line}`)
9696
.join('\n') +

scripts/verifyCommit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const msg = readFileSync(msgPath, 'utf-8').trim()
99

1010
const releaseRE = /^v\d/
1111
const commitRE =
12-
/^(revert: )?(feat|fix|docs|dx|refactor|perf|test|workflow|build|ci|chore|types|wip|release|deps)(\(.+\))?: .{1,50}/
12+
/^(?:revert: )?(?:feat|fix|docs|dx|refactor|perf|test|workflow|build|ci|chore|types|wip|release|deps)(?:\(.+\))?: .{1,50}/
1313

1414
if (!releaseRE.test(msg) && !commitRE.test(msg)) {
1515
console.log()

0 commit comments

Comments
 (0)