@@ -11,6 +11,7 @@ import * as Option from "effect/Option"
11
11
import * as Order from "effect/Order"
12
12
import * as Predicate from "effect/Predicate"
13
13
import * as ReadonlyArray from "effect/ReadonlyArray"
14
+ import * as regexp from "effect/RegExp"
14
15
import type { Concurrency } from "effect/Types"
15
16
import * as util_ from "./internal/util.js"
16
17
import type { ParseIssue } from "./ParseResult.js"
@@ -1834,29 +1835,22 @@ export const annotations = (ast: AST, annotations: Annotations): AST => {
1834
1835
*/
1835
1836
export const keyof = ( ast : AST ) : AST => Union . unify ( _keyof ( ast ) )
1836
1837
1837
- const specialCharsRegex = / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g
1838
-
1839
- const escapeSpecialChars = ( s : string ) : string =>
1840
- specialCharsRegex . test ( s ) ?
1841
- s . replace ( specialCharsRegex , "\\$&" ) // $& means the whole matched string
1842
- : s
1843
-
1844
1838
const STRING_KEYWORD_PATTERN = ".*"
1845
1839
const NUMBER_KEYWORD_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?"
1846
1840
1847
1841
/**
1848
1842
* @since 1.0.0
1849
1843
*/
1850
1844
export const getTemplateLiteralRegExp = ( ast : TemplateLiteral ) : RegExp => {
1851
- let pattern = `^${ escapeSpecialChars ( ast . head ) } `
1845
+ let pattern = `^${ regexp . escape ( ast . head ) } `
1852
1846
1853
1847
for ( const span of ast . spans ) {
1854
1848
if ( isStringKeyword ( span . type ) ) {
1855
1849
pattern += STRING_KEYWORD_PATTERN
1856
1850
} else if ( isNumberKeyword ( span . type ) ) {
1857
1851
pattern += NUMBER_KEYWORD_PATTERN
1858
1852
}
1859
- pattern += escapeSpecialChars ( span . literal )
1853
+ pattern += regexp . escape ( span . literal )
1860
1854
}
1861
1855
1862
1856
pattern += "$"
0 commit comments