perf: regexp perf issues, refactor regexp stylistic issues#10905
Merged
patak-cat merged 10 commits intovitejs:mainfrom Nov 14, 2022
Merged
perf: regexp perf issues, refactor regexp stylistic issues#10905patak-cat merged 10 commits intovitejs:mainfrom
patak-cat merged 10 commits intovitejs:mainfrom
Conversation
sapphi-red
commented
Nov 14, 2022
| // simply be ignored. | ||
| export const importsRE = | ||
| /(?<!\/\/.*)(?<=^|;|\*\/)\s*import(?!\s+type)(?:[\w*{}\n\r\t, ]+from\s*)?\s*("[^"]+"|'[^']+')\s*(?=$|;|\/\/|\/\*)/gm | ||
| /(?<!\/\/.*)(?<=^|;|\*\/)\s*import(?!\s+type)(?:[\w*{}\n\r\t, ]+from)?\s*("[^"]+"|'[^']+')\s*(?=$|;|\/\/|\/\*)/gm |
Member
Author
There was a problem hiding this comment.
This \s* can be matched by the next \s*.
| const scriptModuleRE = | ||
| /(<script\b[^>]*type\s*=\s*(?:"module"|'module')[^>]*>)(.*?)<\/script>/gims | ||
| export const scriptRE = /(<script\b(?:\s[^>]*>|>))(.*?)<\/script>/gims | ||
| /(<script\b[^>]+type\s*=\s*(?:"module"|'module')[^>]*>)(.*?)<\/script>/gis |
Member
Author
There was a problem hiding this comment.
Because \b exists [^>] will always match more than one char.
| /(<script\b[^>]*type\s*=\s*(?:"module"|'module')[^>]*>)(.*?)<\/script>/gims | ||
| export const scriptRE = /(<script\b(?:\s[^>]*>|>))(.*?)<\/script>/gims | ||
| /(<script\b[^>]+type\s*=\s*(?:"module"|'module')[^>]*>)(.*?)<\/script>/gis | ||
| export const scriptRE = /(<script(?:\s[^>]*>|>))(.*?)<\/script>/gis |
Member
Author
There was a problem hiding this comment.
Because \s and > both matches \b, this \b isn't needed.
| let s: MagicString | undefined | ||
| const assetImportMetaUrlRE = | ||
| /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*,?\s*\)/g | ||
| /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*(?:,\s*)?\)/g |
Member
Author
There was a problem hiding this comment.
\s*,?\s* is same with \s*(?:,\s*)?.
Comment on lines
-1178
to
+1181
| /(?<=^|[^\w\-\u0080-\uffff])url\(\s*('[^']+'|"[^"]+"|[^'")]+)\s*\)/ | ||
| /(?<=^|[^\w\-\u0080-\uffff])url\((\s*('[^']+'|"[^"]+")\s*|[^'")]+)\)/ | ||
| export const cssDataUriRE = | ||
| /(?<=^|[^\w\-\u0080-\uffff])data-uri\(\s*('[^']+'|"[^"]+"|[^'")]+)\s*\)/ | ||
| /(?<=^|[^\w\-\u0080-\uffff])data-uri\((\s*('[^']+'|"[^"]+")\s*|[^'")]+)\)/ |
Member
Author
There was a problem hiding this comment.
\s*('[^']+'|"[^"]+"|[^'")]+)\s* is same with (\s*('[^']+'|"[^"]+")\s*|[^'")]+). (String::trim() needs to be run later.)
Comment on lines
-1394
to
+1397
| /@import\s*(?:url\([^\)]*\)|"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'|[^;]*).*?;/gm | ||
| /@import(?:\s*(?:url\([^)]*\)|"(?:[^"]|(?<=\\)")*"|'(?:[^']|(?<=\\)')*').*?|[^;]*);/g |
Member
Author
There was a problem hiding this comment.
[^;]* matches \s*. So splitted [^;]*.
| .map((line) => { | ||
| return line.replace( | ||
| /^ {4}at (?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?)\)?/, | ||
| /^ {4}at (?:(\S.*?)\s\()?(.+?):(\d+)(?::(\d+))?\)?/, |
Member
Author
There was a problem hiding this comment.
(.+?)\s+ is same with (\S.*?)\s. (String::trim() needs to be run later.)
patak-cat
approved these changes
Nov 14, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add
eslint-plugin-regexpto detect some perf issues.I guess this will fix #10900 along the way.Actually it wasn't catched byeslint-plugin-regexp. But I included a fix for it in this PR.Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).