Merge multiple regex transform plugin (#10447)

* feat: implement create-regexp-features-plugin

* fix: test input is not effective

* refactor: leverage create-regexp-features-plugin

* test: add more test cases

* test: update test fixture

* chore: add type annotation to features

* test: add regression test for issue 9892

* add regression test for issue 9199

* address review comments from Nicolò

* address review comments from Brian

* small tweaks

* Enable dotAllFlag when flags includes u
This commit is contained in:
Huáng Jùnliàng
2019-10-29 17:58:04 -04:00
committed by Nicolò Ribaudo
parent ec3345bb57
commit 8ffca0475a
38 changed files with 333 additions and 113 deletions

View File

@@ -1,19 +1,12 @@
/* eslint-disable @babel/development/plugin-name */
import { createRegExpFeaturePlugin } from "@babel/helper-create-regexp-features-plugin";
import { declare } from "@babel/helper-plugin-utils";
import rewritePattern from "regexpu-core";
import * as regex from "@babel/helper-regex";
export default declare(api => {
api.assertVersion(7);
return {
return createRegExpFeaturePlugin({
name: "transform-unicode-regex",
visitor: {
RegExpLiteral({ node }) {
if (!regex.is(node, "u")) return;
node.pattern = rewritePattern(node.pattern, node.flags);
regex.pullFlag(node, "u");
},
},
};
feature: "unicodeFlag",
});
});