feat(transformer): add features ES2018NamedCapturingGroupsRegex and ES2018LookbehindRegex (#7182)

This commit is contained in:
Boshen 2024-11-07 07:39:33 +00:00
parent ad3a2f518e
commit a579011e37
8 changed files with 120 additions and 12 deletions

View file

@ -190,10 +190,8 @@ impl TryFrom<BabelEnvOptions> for EnvOptions {
unicode_property_escapes: o.can_enable(ES2018UnicodePropertyRegex),
dot_all_flag: o.can_enable(ES2018DotallRegex),
named_capture_groups: o.can_enable(ES2018NamedCapturingGroupsRegex),
// FIXME
look_behind_assertions: false, // o.can_enable("esbuild-regexp-lookbehind-assertions"),
// FIXME
match_indices: false, // o.can_enable("esbuild-regexp-match-indices"),
look_behind_assertions: o.can_enable(ES2018LookbehindRegex),
match_indices: o.can_enable(ES2022MatchIndicesRegex),
set_notation: o.can_enable(ES2024UnicodeSetsRegex),
},
es2015: ES2015Options {

View file

@ -35,6 +35,7 @@ pub enum ESFeature {
ES2018NamedCapturingGroupsRegex,
ES2018UnicodePropertyRegex,
ES2018DotallRegex,
ES2018LookbehindRegex,
ES2018ObjectRestSpread,
ES2018AsyncGeneratorFunctions,
ES2018OptionalCatchBinding,
@ -47,6 +48,7 @@ pub enum ESFeature {
ES2022ClassProperties,
ES2022PrivatePropertyInObject,
ES2022ClassStaticBlock,
ES2022MatchIndicesRegex,
ES2024UnicodeSetsRegex,
ES2025RegexpModifiers,
ES2025DuplicateNamedCapturingGroupsRegex,
@ -539,6 +541,22 @@ pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
(Edge, Version(79u32, 0u32, 0u32)),
])),
),
(
ES2018LookbehindRegex,
EngineTargets::new(FxHashMap::from_iter([
(Chrome, Version(62u32, 0u32, 0u32)),
(Safari, Version(16u32, 4u32, 0u32)),
(OperaMobile, Version(46u32, 0u32, 0u32)),
(Samsung, Version(8u32, 0u32, 0u32)),
(Node, Version(8u32, 10u32, 0u32)),
(Firefox, Version(78u32, 0u32, 0u32)),
(Deno, Version(1u32, 0u32, 0u32)),
(Electron, Version(3u32, 0u32, 0u32)),
(Opera, Version(49u32, 0u32, 0u32)),
(Ios, Version(16u32, 4u32, 0u32)),
(Edge, Version(79u32, 0u32, 0u32)),
])),
),
(
ES2018ObjectRestSpread,
EngineTargets::new(FxHashMap::from_iter([
@ -733,6 +751,22 @@ pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
(Edge, Version(94u32, 0u32, 0u32)),
])),
),
(
ES2022MatchIndicesRegex,
EngineTargets::new(FxHashMap::from_iter([
(Chrome, Version(90u32, 0u32, 0u32)),
(Safari, Version(15u32, 0u32, 0u32)),
(OperaMobile, Version(64u32, 0u32, 0u32)),
(Samsung, Version(15u32, 0u32, 0u32)),
(Node, Version(16u32, 0u32, 0u32)),
(Firefox, Version(91u32, 0u32, 0u32)),
(Deno, Version(1u32, 8u32, 0u32)),
(Electron, Version(13u32, 0u32, 0u32)),
(Opera, Version(76u32, 0u32, 0u32)),
(Ios, Version(15u32, 0u32, 0u32)),
(Edge, Version(90u32, 0u32, 0u32)),
])),
),
(
ES2024UnicodeSetsRegex,
EngineTargets::new(FxHashMap::from_iter([

View file

@ -1 +1,12 @@
# Compat Data
Get engine compatibility Data from https://github.com/compat-table/compat-table/
Code extracted from https://github.com/babel/babel/tree/main/packages/babel-compat-data
## Adding a new feature
- Find the feature from https://github.com/compat-table/compat-table/blob/gh-pages/data-es2016plus.js
- Add the feature in `./es-features.js`
- `pnpm install`
- `cargo run -p oxc_compat_data`

View file

@ -59,7 +59,6 @@ const getLowestImplementedVersion = (
ok &&= !exclude(test.name);
return ok;
});
const envTests = tests.map(({ res }) => {
const versions = envsVersions[env];
let i = versions.length - 1;
@ -110,7 +109,6 @@ const generateData = (environments, items) => {
item.targets = targets;
}
console.log(items);
return items;
};

View file

@ -652,6 +652,27 @@
"electron": "3.0"
}
},
{
"name": "LookbehindRegex",
"babel": null,
"features": [
"RegExp Lookbehind Assertions"
],
"es": "ES2018",
"targets": {
"chrome": "62",
"opera": "49",
"edge": "79",
"firefox": "78",
"safari": "16.4",
"node": "8.10",
"deno": "1",
"ios": "16.4",
"samsung": "8",
"opera_mobile": "46",
"electron": "3.0"
}
},
{
"name": "ObjectRestSpread",
"babel": "transform-object-rest-spread",
@ -910,6 +931,27 @@
"electron": "15.0"
}
},
{
"name": "MatchIndicesRegex",
"babel": null,
"features": [
"RegExp Match Indices (`hasIndices` / `d` flag) / constructor supports it"
],
"es": "ES2022",
"targets": {
"chrome": "90",
"opera": "76",
"edge": "90",
"firefox": "91",
"safari": "15",
"node": "16",
"deno": "1.8",
"ios": "15",
"samsung": "15",
"opera_mobile": "64",
"electron": "13.0"
}
},
{
"name": "UnicodeSetsRegex",
"babel": "transform-unicode-sets-regex",

View file

@ -201,6 +201,11 @@ const es2018 = [
babel: 'transform-dotall-regex',
features: ['s (dotAll) flag for regular expressions'],
},
{
name: 'LookbehindRegex',
babel: null,
features: ['RegExp Lookbehind Assertions'],
},
{
name: 'ObjectRestSpread',
babel: 'transform-object-rest-spread',
@ -279,6 +284,14 @@ const es2022 = [
babel: 'transform-class-static-block',
features: ['Class static initialization blocks'],
},
{
name: 'MatchIndicesRegex',
babel: null,
features: [
'RegExp Match Indices (`hasIndices` / `d` flag) / constructor supports it',
// ignore "shows up in flags"
],
},
].map(f('ES2022'));
const es2024 = [

View file

@ -1,5 +1,21 @@
#![allow(clippy::print_stdout)]
use std::process::Command;
use oxc_compat_data::generate;
use oxc_tasks_common::project_root;
fn main() {
let cwd = project_root().join("tasks/compat_data");
if !cwd.join("compat-table").exists() {
println!("Cloning compat-table ...");
Command::new("pnpm").current_dir(&cwd).args(["run", "init"]).output().unwrap();
}
let output = Command::new("pnpm").current_dir(cwd).args(["run", "build"]).output().unwrap();
if !output.status.success() {
println!("{}", String::from_utf8(output.stderr).unwrap());
}
generate();
}

View file

@ -1,6 +1,6 @@
commit: d20b314c
Passed: 77/87
Passed: 78/87
# All Passed:
* babel-plugin-transform-class-static-block
@ -12,6 +12,7 @@ Passed: 77/87
* babel-plugin-transform-arrow-functions
* babel-preset-typescript
* babel-plugin-transform-react-jsx-source
* regexp
# babel-plugin-transform-typescript (2/9)
@ -175,8 +176,3 @@ x Output mismatch
x Output mismatch
# regexp (7/8)
* all-regex-plugins-enabled-by-targets/input.js
x Output mismatch