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:
committed by
Nicolò Ribaudo
parent
ec3345bb57
commit
8ffca0475a
@@ -12,9 +12,8 @@
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "^7.0.0",
|
||||
"@babel/helper-regex": "^7.4.4",
|
||||
"regexpu-core": "^4.6.0"
|
||||
"@babel/helper-create-regexp-features-plugin": "^7.6.0",
|
||||
"@babel/helper-plugin-utils": "^7.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0-0"
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user