Skip to content

Commit d6517bf

Browse files
authored
Use Go regexp for autoImportSpecifierExcludeRegexes, remove regexp2 (#3245)
1 parent 194226e commit d6517bf

4 files changed

Lines changed: 15 additions & 42 deletions

File tree

NOTICE.txt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -338,32 +338,6 @@ BSD-3-Clause AND LicenseRef-scancode-google-patent-license-golang
338338

339339
---------------------------------------------------------
340340

341-
github.com/dlclark/regexp2 v1.11.5 - MIT
342-
343-
344-
(c) 0, ca Pass. Group
345-
(c) 0, abc Pass. Group
346-
(c) 0, abac Pass. Group
347-
Copyright (c) Doug Clark
348-
(c) IgnoreCase, ABC Pass. Group
349-
(c) RightToLeft, abc Pass. Group
350-
Copyright (c) 2012 The Go Authors
351-
Copyright (c) Microsoft Corporation
352-
353-
MIT License
354-
355-
Copyright (c) <year> <copyright holders>
356-
357-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
358-
359-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
360-
361-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
362-
363-
---------------------------------------------------------
364-
365-
---------------------------------------------------------
366-
367341
github.com/klauspost/cpuid/v2 v2.2.10 - MIT
368342

369343

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.26
44

55
require (
66
github.com/Microsoft/go-winio v0.6.2
7-
github.com/dlclark/regexp2 v1.11.5
87
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433
98
github.com/google/go-cmp v0.7.0
109
github.com/peter-evans/patience v0.3.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
22
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
3-
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
4-
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
53
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 h1:vymEbVwYFP/L05h5TKQxvkXoKxNvTpjxYKdF1Nlwuao=
64
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
75
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=

internal/modulespecifiers/util.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package modulespecifiers
22

33
import (
44
"fmt"
5+
"regexp"
56
"slices"
67
"strings"
78
"sync"
89

9-
"github.com/dlclark/regexp2"
1010
"github.com/microsoft/typescript-go/internal/ast"
1111
"github.com/microsoft/typescript-go/internal/collections"
1212
"github.com/microsoft/typescript-go/internal/core"
@@ -17,13 +17,13 @@ import (
1717
)
1818

1919
type regexPatternCacheKey struct {
20-
pattern string
21-
opts regexp2.RegexOptions
20+
pattern string
21+
caseInsensitive bool
2222
}
2323

2424
var (
2525
regexPatternCacheMu sync.RWMutex
26-
regexPatternCache = make(map[regexPatternCacheKey]*regexp2.Regexp)
26+
regexPatternCache = make(map[regexPatternCacheKey]*regexp.Regexp)
2727
)
2828

2929
func comparePathsByRedirect(a ModulePath, b ModulePath, useCaseSensitiveFileNames bool) int {
@@ -46,16 +46,15 @@ func IsExcludedByRegex(moduleSpecifier string, excludes []string) bool {
4646
if re == nil {
4747
continue
4848
}
49-
match, _ := re.MatchString(moduleSpecifier)
50-
if match {
49+
if re.MatchString(moduleSpecifier) {
5150
return true
5251
}
5352
}
5453
return false
5554
}
5655

57-
func stringToRegex(pattern string) *regexp2.Regexp {
58-
options := regexp2.RegexOptions(regexp2.ECMAScript)
56+
func stringToRegex(pattern string) *regexp.Regexp {
57+
caseInsensitive := false
5958

6059
if len(pattern) > 2 && pattern[0] == '/' {
6160
lastSlash := strings.LastIndex(pattern, "/")
@@ -75,15 +74,13 @@ func stringToRegex(pattern string) *regexp2.Regexp {
7574
for _, flag := range flags {
7675
switch flag {
7776
case 'i':
78-
options |= regexp2.IgnoreCase
79-
case 'u':
80-
options |= regexp2.Unicode
77+
caseInsensitive = true
8178
}
8279
}
8380
}
8481
}
8582
}
86-
key := regexPatternCacheKey{pattern, options}
83+
key := regexPatternCacheKey{pattern, caseInsensitive}
8784

8885
regexPatternCacheMu.RLock()
8986
re, ok := regexPatternCache[key]
@@ -107,7 +104,12 @@ func stringToRegex(pattern string) *regexp2.Regexp {
107104
pattern = strings.Clone(pattern)
108105
key.pattern = pattern
109106

110-
compiled, err := regexp2.Compile(pattern, options)
107+
compilePattern := pattern
108+
if caseInsensitive {
109+
compilePattern = "(?i:" + pattern + ")"
110+
}
111+
112+
compiled, err := regexp.Compile(compilePattern)
111113
if err != nil {
112114
regexPatternCache[key] = nil
113115
return nil

0 commit comments

Comments
 (0)