Skip to content

Commit

Permalink
perf: regexp perf issues, refactor regexp stylistic issues (#10905)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Nov 14, 2022
1 parent d2980c7 commit ef94286
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-react/src/fast-refresh.ts
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-react/src/index.ts
Expand Up @@ -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',
Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion scripts/rollupLicensePlugin.mjs
Expand Up @@ -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') +
Expand Down
2 changes: 1 addition & 1 deletion scripts/verifyCommit.ts
Expand Up @@ -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()
Expand Down

0 comments on commit ef94286

Please sign in to comment.