From ef9428676b8868aeb051ddd34a6b3276241788ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Mon, 14 Nov 2022 21:23:27 +0900 Subject: [PATCH] perf: regexp perf issues, refactor regexp stylistic issues (#10905) fix https://github.com/vitejs/vite/issues/10900 --- package.json | 1 + packages/plugin-react/src/fast-refresh.ts | 2 +- packages/plugin-react/src/index.ts | 6 +++--- scripts/rollupLicensePlugin.mjs | 2 +- scripts/verifyCommit.ts | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 06dff56..e04e96d 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "eslint-define-config": "^1.11.0", "eslint-plugin-import": "^2.26.0", "eslint-plugin-node": "^11.1.0", + "eslint-plugin-regexp": "^1.10.0", "execa": "^6.1.0", "fast-glob": "^3.2.12", "fs-extra": "^10.1.0", diff --git a/packages/plugin-react/src/fast-refresh.ts b/packages/plugin-react/src/fast-refresh.ts index b0b38a8..1461b4d 100644 --- a/packages/plugin-react/src/fast-refresh.ts +++ b/packages/plugin-react/src/fast-refresh.ts @@ -56,7 +56,7 @@ if (import.meta.hot) { RefreshRuntime.register(type, __SOURCE__ + " " + id) }; window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform; -}`.replace(/[\n]+/gm, '') +}`.replace(/\n+/g, '') const timeout = ` if (!window.__vite_plugin_react_timeout) { diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index fe7b209..ad54bb9 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -110,10 +110,10 @@ export default function viteReact(opts: Options = {}): PluginOption[] { // - import * as React from 'react'; // - import React from 'react'; // - import React, {useEffect} from 'react'; - const importReactRE = /(^|\n)import\s+(\*\s+as\s+)?React(,|\s+)/ + const importReactRE = /(?:^|\n)import\s+(?:\*\s+as\s+)?React(?:,|\s+)/ // Any extension, including compound ones like '.bs.js' - const fileExtensionRE = /\.[^\/\s\?]+$/ + const fileExtensionRE = /\.[^/\s?]+$/ const viteBabel: Plugin = { name: 'vite:react-babel', @@ -202,7 +202,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] { filepath.match(fileExtensionRE) || [] - if (/\.(mjs|[tj]sx?)$/.test(extension)) { + if (/\.(?:mjs|[tj]sx?)$/.test(extension)) { const isJSX = extension.endsWith('x') const isNodeModules = id.includes('/node_modules/') const isProjectFile = diff --git a/scripts/rollupLicensePlugin.mjs b/scripts/rollupLicensePlugin.mjs index 1a3e242..fedbd34 100644 --- a/scripts/rollupLicensePlugin.mjs +++ b/scripts/rollupLicensePlugin.mjs @@ -90,7 +90,7 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) { '\n' + licenseText .trim() - .replace(/(\r\n|\r)/gm, '\n') + .replace(/(\r\n|\r)/g, '\n') .split('\n') .map((line) => `> ${line}`) .join('\n') + diff --git a/scripts/verifyCommit.ts b/scripts/verifyCommit.ts index 848295d..4d149d9 100644 --- a/scripts/verifyCommit.ts +++ b/scripts/verifyCommit.ts @@ -9,7 +9,7 @@ const msg = readFileSync(msgPath, 'utf-8').trim() const releaseRE = /^v\d/ const commitRE = - /^(revert: )?(feat|fix|docs|dx|refactor|perf|test|workflow|build|ci|chore|types|wip|release|deps)(\(.+\))?: .{1,50}/ + /^(?:revert: )?(?:feat|fix|docs|dx|refactor|perf|test|workflow|build|ci|chore|types|wip|release|deps)(?:\(.+\))?: .{1,50}/ if (!releaseRE.test(msg) && !commitRE.test(msg)) { console.log()