|
14 | 14 | } |
15 | 15 | }); |
16 | 16 | } |
17 | | - |
18 | | - // https://github.com/estools/esquery/issues/68 |
19 | | - // Inside all /regexp/ literals, we replace escaped-backslashes with the \x2F equivalent. |
20 | | - input = input.replaceAll(/\/((?:[^\/\\]|\\.)*?)\//g, (match) => { |
21 | | - return match.replaceAll("\\/", "\\\\x2F"); |
22 | | - }); |
23 | 17 | } |
24 | 18 |
|
25 | 19 | start |
@@ -103,13 +97,18 @@ attr |
103 | 97 | path = i:identifierName { return { type: 'literal', value: i }; } |
104 | 98 | type = "type(" _ t:[^ )]+ _ ")" { return { type: 'type', value: t.join('') }; } |
105 | 99 | flags = [imsu]+ |
106 | | - regex = "/" d:[^/]+ "/" flgs:flags? { |
107 | | - // https://github.com/estools/esquery/issues/68 |
108 | | - const text = d.join('').replaceAll("\\\\x2F", "\\/"); |
| 100 | + regex = "/" pattern:(regex_cc / regex_hex_escape / regex_single_char_escape / regex_chars)+ "/" flgs:flags? { |
109 | 101 | return { |
110 | | - type: 'regexp', value: new RegExp(text, flgs ? flgs.join('') : '') |
| 102 | + type: 'regexp', value: new RegExp(pattern.join(''), flgs ? flgs.join('') : '') |
111 | 103 | }; |
112 | 104 | } |
| 105 | + regex_cc = "[" cs:([^\]\\] / regex_hex_escape / regex_single_char_escape)+ "]" { return '[' + cs.join('') + ']'; } |
| 106 | + regex_hex_escape = "\\x" a:[A-Fa-f0-9] b:[A-Fa-f0-9] { return '\\x' + a + b; } |
| 107 | + regex_single_char_escape = "\\" a:. { |
| 108 | + let hex = a.charCodeAt(0).toString(16); |
| 109 | + return '\\x' + (hex.length > 1 ? hex : '0' + hex) ; |
| 110 | + } |
| 111 | + regex_chars = cs:[^/\\\[]+ { return cs.join(''); } |
113 | 112 |
|
114 | 113 | field = "." i:identifierName is:("." identifierName)* { |
115 | 114 | return { type: 'field', name: is.reduce(function(memo, p){ return memo + p[0] + p[1]; }, i)}; |
|
0 commit comments