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
@@ -8,9 +8,6 @@
|
||||
"access": "public"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"keywords": [
|
||||
"babel-plugin",
|
||||
"regex",
|
||||
@@ -21,9 +18,8 @@
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-dotall-regex",
|
||||
"bugs": "https://github.com/babel/babel/issues",
|
||||
"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,25 +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-dotall-regex",
|
||||
|
||||
visitor: {
|
||||
RegExpLiteral(path) {
|
||||
const node = path.node;
|
||||
if (!regex.is(node, "s")) {
|
||||
return;
|
||||
}
|
||||
node.pattern = rewritePattern(node.pattern, node.flags, {
|
||||
dotAllFlag: true,
|
||||
useUnicodeFlag: regex.is(node, "u"),
|
||||
});
|
||||
regex.pullFlag(node, "s");
|
||||
},
|
||||
},
|
||||
};
|
||||
feature: "dotAllFlag",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = /\p{Unified_Ideograph}./u;
|
||||
var b = /\p{Unified_Ideograph}./su;
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["transform-dotall-regex", "proposal-unicode-property-regex"]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = /[\u3400-\u4DB5\u4E00-\u9FEF\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29\u{20000}-\u{2A6D6}\u{2A700}-\u{2B734}\u{2B740}-\u{2B81D}\u{2B820}-\u{2CEA1}\u{2CEB0}-\u{2EBE0}][\0-\t\x0B\f\x0E-\u2027\u202A-\u{10FFFF}]/u;
|
||||
var b = /[\u3400-\u4DB5\u4E00-\u9FEF\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29\u{20000}-\u{2A6D6}\u{2A700}-\u{2B734}\u{2B740}-\u{2B81D}\u{2B820}-\u{2CEA1}\u{2CEB0}-\u{2EBE0}][\0-\u{10FFFF}]/u;
|
||||
Reference in New Issue
Block a user