Skip to content

Commit

Permalink
fix(pluginutils): improve regex performance (#1753)
Browse files Browse the repository at this point in the history
perf(pluginutils): improve regex performance
  • Loading branch information
bluwy authored Sep 22, 2024
1 parent 369a768 commit 184d81a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/pluginutils/src/attachScopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const attachScopes: AttachScopes = function attachScopes(ast, propertyName = 'sc
const node = n as estree.Node;
// function foo () {...}
// class Foo {...}
if (/(Function|Class)Declaration/.test(node.type)) {
if (/(?:Function|Class)Declaration/.test(node.type)) {
scope.addDeclaration(node, false, false);
}

Expand Down Expand Up @@ -98,7 +98,7 @@ const attachScopes: AttachScopes = function attachScopes(ast, propertyName = 'sc
}

// create new for scope
if (/For(In|Of)?Statement/.test(node.type)) {
if (/For(?:In|Of)?Statement/.test(node.type)) {
newScope = new Scope({
parent: scope,
block: true
Expand Down
2 changes: 1 addition & 1 deletion packages/pluginutils/src/dataToEsm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const dataToEsm: DataToEsm = function dataToEsm(data, options = {}) {

let maxUnderbarPrefixLength = 0;
for (const key of Object.keys(data)) {
const underbarPrefixLength = key.match(/^(_+)/)?.[0].length ?? 0;
const underbarPrefixLength = /^(_+)/.exec(key)?.[0].length ?? 0;
if (underbarPrefixLength > maxUnderbarPrefixLength) {
maxUnderbarPrefixLength = underbarPrefixLength;
}
Expand Down

0 comments on commit 184d81a

Please sign in to comment.