Skip to content

Commit 4ce39eb

Browse files
authoredMar 6, 2024··
feat(es/parser): Support Regular Expression v flag (#8690)
**Related issue:** - Closes #8462
1 parent 4066dfa commit 4ce39eb

File tree

6 files changed

+10
-1
lines changed

6 files changed

+10
-1
lines changed
 

‎crates/swc_ecma_compat_common/src/regexp.rs

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub struct Config {
2323
pub unicode_property_regex: bool,
2424
/// [RegExp.prototype.unicode](https://tc39.es/ecma262/multipage/text-processing.html#sec-get-regexp.prototype.unicode)
2525
pub unicode_regex: bool,
26+
// [RegExp.prototype.unicodeSets](https://github.com/tc39/proposal-regexp-v-flag)
27+
pub unicode_sets_regex: bool,
2628
}
2729

2830
struct RegExp {
@@ -39,6 +41,7 @@ impl VisitMut for RegExp {
3941
if (self.config.dot_all_regex && regex.flags.contains('s'))
4042
|| (self.config.sticky_regex && regex.flags.contains('y'))
4143
|| (self.config.unicode_regex && regex.flags.contains('u'))
44+
|| (self.config.unicode_sets_regex && regex.flags.contains('v'))
4245
|| (self.config.has_indices && regex.flags.contains('d'))
4346
|| (self.config.named_capturing_groups_regex && regex.exp.contains("(?<"))
4447
|| (self.config.lookbehind_assertion && regex.exp.contains("(?<=")

‎crates/swc_ecma_compat_es2015/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ where
6868
sticky_regex: true,
6969
unicode_property_regex: false,
7070
unicode_regex: true,
71+
unicode_sets_regex: false,
7172
}),
7273
block_scoped_functions(),
7374
template_literal(c.template_literal),

‎crates/swc_ecma_compat_es2018/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn es2018(c: Config) -> impl Fold {
2222
sticky_regex: false,
2323
unicode_property_regex: true,
2424
unicode_regex: false,
25+
unicode_sets_regex: false,
2526
}),
2627
object_rest_spread(c.object_rest_spread)
2728
)

‎crates/swc_ecma_compat_es2022/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn es2022<C: Comments>(cm: Option<C>, config: Config, unresolved_mark: Mark)
2424
sticky_regex: false,
2525
unicode_property_regex: true,
2626
unicode_regex: false,
27+
unicode_sets_regex: false,
2728
}),
2829
static_blocks(config.class_properties.static_blocks_mark),
2930
class_properties(cm, config.class_properties, unresolved_mark),

‎crates/swc_ecma_parser/src/parser/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ impl<I: Tokens> Parser<I> {
340340
AHashMap::<char, usize>::default(),
341341
|mut map, flag| {
342342
let key = match flag {
343-
'g' | 'i' | 'm' | 's' | 'u' | 'y' | 'd' => flag,
343+
// https://tc39.es/ecma262/#sec-isvalidregularexpressionliteral
344+
'd' | 'g' | 'i' | 'm' | 's' | 'u' | 'v' | 'y' => flag,
344345
_ => '\u{0000}', // special marker for unknown flags
345346
};
346347
map.entry(key).and_modify(|count| *count += 1).or_insert(1);

‎crates/swc_ecma_preset_env/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ where
9999
let enable_sticky_regex = should_enable!(StickyRegex, false);
100100
let enable_unicode_property_regex = should_enable!(UnicodePropertyRegex, false);
101101
let enable_unicode_regex = should_enable!(UnicodeRegex, false);
102+
let enable_unicode_sets_regex = should_enable!(UnicodeSetsRegex, false);
102103

103104
let enable = enable_dot_all_regex
104105
|| enable_named_capturing_groups_regex
@@ -119,6 +120,7 @@ where
119120
sticky_regex: enable_sticky_regex,
120121
unicode_property_regex: enable_unicode_property_regex,
121122
unicode_regex: enable_unicode_regex,
123+
unicode_sets_regex: enable_unicode_sets_regex,
122124
}),
123125
enable
124126
)

0 commit comments

Comments
 (0)
Please sign in to comment.