From 884694457a8fcd514a5db26499cb6a07b2c380db Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Sun, 27 Nov 2022 06:04:03 +0800 Subject: [PATCH 01/10] feat --- lib/regexpu-core.d.ts | 2 + .../package.json | 2 +- .../src/features.ts | 1 + .../src/index.ts | 9 +++- .../src/util.ts | 5 ++ .../.npmignore | 3 ++ .../README.md | 19 +++++++ .../package.json | 50 +++++++++++++++++++ .../src/index.ts | 12 +++++ .../test/fixtures/syntax/basic/exec.js | 11 ++++ .../test/fixtures/syntax/basic/input.js | 2 + .../test/fixtures/syntax/basic/options.json | 3 ++ .../test/fixtures/syntax/basic/output.js | 2 + .../test/fixtures/syntax/with-u-flag/exec.js | 3 ++ .../test/fixtures/syntax/with-u-flag/input.js | 2 + .../fixtures/syntax/with-u-flag/options.json | 3 ++ .../fixtures/syntax/with-u-flag/output.js | 2 + .../test/index.js | 3 ++ .../test/package.json | 1 + packages/babel-standalone/package.json | 1 + .../scripts/pluginConfig.json | 1 + .../babel-standalone/src/generated/plugins.ts | 3 ++ .../babel-standalone/src/preset-stage-3.ts | 8 +-- tsconfig.json | 4 ++ yarn.lock | 15 +++++- 25 files changed, 157 insertions(+), 10 deletions(-) create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/.npmignore create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/README.md create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/package.json create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/src/index.ts create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/exec.js create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/input.js create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/options.json create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/output.js create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/exec.js create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/input.js create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/options.json create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/output.js create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/test/index.js create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/test/package.json diff --git a/lib/regexpu-core.d.ts b/lib/regexpu-core.d.ts index e6cb4eb325f5..832817bd2753 100644 --- a/lib/regexpu-core.d.ts +++ b/lib/regexpu-core.d.ts @@ -6,6 +6,8 @@ declare module "regexpu-core" { unicodePropertyEscapes?: "transform" | false; namedGroups?: "transform" | false; onNamedGroup?: (name: string, index: number) => void; + modifiers?: "transform" | false; + onNewFlags?: (name: string) => void; }; function rewritePattern( pattern: string, diff --git a/packages/babel-helper-create-regexp-features-plugin/package.json b/packages/babel-helper-create-regexp-features-plugin/package.json index 7cced99ab2ac..19e6ebb52dcd 100644 --- a/packages/babel-helper-create-regexp-features-plugin/package.json +++ b/packages/babel-helper-create-regexp-features-plugin/package.json @@ -19,7 +19,7 @@ ], "dependencies": { "@babel/helper-annotate-as-pure": "workspace:^", - "regexpu-core": "^5.2.1" + "regexpu-core": "https://github.com/liuxingbaoyu/regexpu-core#head=modifiers" }, "peerDependencies": { "@babel/core": "^7.0.0" diff --git a/packages/babel-helper-create-regexp-features-plugin/src/features.ts b/packages/babel-helper-create-regexp-features-plugin/src/features.ts index ed9b6f4ed60a..46c94af9d39b 100644 --- a/packages/babel-helper-create-regexp-features-plugin/src/features.ts +++ b/packages/babel-helper-create-regexp-features-plugin/src/features.ts @@ -6,6 +6,7 @@ export const FEATURES = Object.freeze({ unicodeSetsFlag_syntax: 1 << 4, unicodeSetsFlag: 1 << 5, duplicateNamedCaptureGroups: 1 << 6, + modifiers: 1 << 7, }); // We can't use a symbol because this needs to always be the same, even if diff --git a/packages/babel-helper-create-regexp-features-plugin/src/index.ts b/packages/babel-helper-create-regexp-features-plugin/src/index.ts index 52b9e2188d28..eb32f2a07ce3 100644 --- a/packages/babel-helper-create-regexp-features-plugin/src/index.ts +++ b/packages/babel-helper-create-regexp-features-plugin/src/index.ts @@ -116,6 +116,13 @@ export function createRegExpFeaturePlugin({ }; } + let newFlags; + if (regexpuOptions.modifiers === "transform") { + regexpuOptions.onNewFlags = flags => { + newFlags = flags; + }; + } + node.pattern = rewritePattern(node.pattern, node.flags, regexpuOptions); if ( @@ -133,7 +140,7 @@ export function createRegExpFeaturePlugin({ path.replaceWith(call); } - node.flags = transformFlags(regexpuOptions, node.flags); + node.flags = transformFlags(regexpuOptions, newFlags ?? node.flags); }, }, }; diff --git a/packages/babel-helper-create-regexp-features-plugin/src/util.ts b/packages/babel-helper-create-regexp-features-plugin/src/util.ts index d879f0a14e70..05ee3ab3d378 100644 --- a/packages/babel-helper-create-regexp-features-plugin/src/util.ts +++ b/packages/babel-helper-create-regexp-features-plugin/src/util.ts @@ -40,6 +40,7 @@ export function generateRegexpuOptions( unicodePropertyEscapes: feat("unicodePropertyEscape"), namedGroups: feat("namedCaptureGroups") || featDuplicateNamedGroups(), onNamedGroup: () => {}, + modifiers: feat("modifiers"), }; } @@ -71,6 +72,10 @@ export function canSkipRegexpu( return false; } + if (options.modifiers === "transform" && /\(\?.{1,10}:/.test(pattern)) { + return false; + } + return true; } diff --git a/packages/babel-plugin-proposal-regexp-modifiers/.npmignore b/packages/babel-plugin-proposal-regexp-modifiers/.npmignore new file mode 100644 index 000000000000..f9806945836e --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/.npmignore @@ -0,0 +1,3 @@ +src +test +*.log diff --git a/packages/babel-plugin-proposal-regexp-modifiers/README.md b/packages/babel-plugin-proposal-regexp-modifiers/README.md new file mode 100644 index 000000000000..5faf5dafa7b5 --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/README.md @@ -0,0 +1,19 @@ +# @babel/plugin-proposal-regexp-modifiers + +> Compile regular expressions using duplicate named groups to index-based groups. + +See our website [@babel/plugin-proposal-regexp-modifiers](https://babeljs.io/docs/en/babel-plugin-proposal-regexp-modifiers) for more information. + +## Install + +Using npm: + +```sh +npm install --save-dev @babel/plugin-proposal-regexp-modifiers +``` + +or using yarn: + +```sh +yarn add @babel/plugin-proposal-regexp-modifiers --dev +``` diff --git a/packages/babel-plugin-proposal-regexp-modifiers/package.json b/packages/babel-plugin-proposal-regexp-modifiers/package.json new file mode 100644 index 000000000000..5aeecf004efe --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/package.json @@ -0,0 +1,50 @@ +{ + "name": "@babel/plugin-proposal-regexp-modifiers", + "version": "7.19.1", + "description": "TODO", + "homepage": "https://babel.dev/docs/en/next/babel-plugin-proposal-regexp-modifiers", + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "main": "./lib/index.js", + "keywords": [ + "babel-plugin", + "regex", + "regexp", + "regular expressions" + ], + "repository": { + "type": "git", + "url": "https://github.com/babel/babel.git", + "directory": "packages/babel-plugin-proposal-regexp-modifiers" + }, + "bugs": "https://github.com/babel/babel/issues", + "dependencies": { + "@babel/helper-create-regexp-features-plugin": "workspace:^", + "@babel/helper-plugin-utils": "workspace:^" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + }, + "devDependencies": { + "@babel/core": "workspace:^" + }, + "engines": { + "node": ">=6.9.0" + }, + "author": "The Babel Team (https://babel.dev/team)", + "conditions": { + "USE_ESM": [ + { + "type": "module" + }, + null + ] + }, + "exports": { + ".": "./lib/index.js", + "./package.json": "./package.json" + }, + "type": "commonjs" +} diff --git a/packages/babel-plugin-proposal-regexp-modifiers/src/index.ts b/packages/babel-plugin-proposal-regexp-modifiers/src/index.ts new file mode 100644 index 000000000000..790db43479aa --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/src/index.ts @@ -0,0 +1,12 @@ +/* eslint-disable @babel/development/plugin-name */ +import { createRegExpFeaturePlugin } from "@babel/helper-create-regexp-features-plugin"; +import { declare } from "@babel/helper-plugin-utils"; + +export default declare(api => { + api.assertVersion("^7.19.0"); + + return createRegExpFeaturePlugin({ + name: "proposal-regexp-modifiers", + feature: "modifiers", + }); +}); diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/exec.js b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/exec.js new file mode 100644 index 000000000000..abe988c55898 --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/exec.js @@ -0,0 +1,11 @@ +let regex = /(?ims:^[a-z].1$)/ + +expect(regex.test("Ax1")).toBeTruthy(); +expect(regex.test("ax1")).toBeTruthy(); +expect(regex.test("ax2")).toBeFalsy(); +expect(regex.test("1ax1")).toBeFalsy(); + +expect(regex.test("a\r1")).toBeTruthy(); +expect(regex.test("a\r\n1")).toBeFalsy(); + +expect(regex.test("\nax1\n\n\n\n\n\n\n\n\n")).toBeTruthy(); diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/input.js b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/input.js new file mode 100644 index 000000000000..3041280a69a3 --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/input.js @@ -0,0 +1,2 @@ +/(?ims:^[a-z]1$)/; +/(?-ims:^[a-z].1$)(^[a-z].)/ims; diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/options.json b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/options.json new file mode 100644 index 000000000000..da996fb6c95b --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-regexp-modifiers"] +} diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/output.js b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/output.js new file mode 100644 index 000000000000..8f2e4896210c --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/output.js @@ -0,0 +1,2 @@ +/((?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z]1(?:$|(?=[\n\r\u2028\u2029])))/; +/(^[a-z].1$)((?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z][\s\S])/; diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/exec.js b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/exec.js new file mode 100644 index 000000000000..58229379f405 --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/exec.js @@ -0,0 +1,3 @@ +let regex = /(?ims:^[a-z])/u; + +expect(regex.test("\u017F")).toBeTruthy(); diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/input.js b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/input.js new file mode 100644 index 000000000000..c210b35d3fdc --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/input.js @@ -0,0 +1,2 @@ +/(?ims:^[a-z])/u; +/(?-ims:^[a-z].)(^[a-z].)/uims; diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/options.json b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/options.json new file mode 100644 index 000000000000..39d545141c49 --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-regexp-modifiers", "transform-unicode-regex"] +} diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/output.js b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/output.js new file mode 100644 index 000000000000..2aec15cd857c --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/output.js @@ -0,0 +1,2 @@ +/((?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z\u017F\u212A])/; +/(^[a-z](?:[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))((?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z\u017F\u212A](?:[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/; diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/index.js b/packages/babel-plugin-proposal-regexp-modifiers/test/index.js new file mode 100644 index 000000000000..21a55ce6b5e7 --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/index.js @@ -0,0 +1,3 @@ +import runner from "@babel/helper-plugin-test-runner"; + +runner(import.meta.url); diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/package.json b/packages/babel-plugin-proposal-regexp-modifiers/test/package.json new file mode 100644 index 000000000000..5ffd9800b97c --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/package.json @@ -0,0 +1 @@ +{ "type": "module" } diff --git a/packages/babel-standalone/package.json b/packages/babel-standalone/package.json index 51c2f37a144b..650350ca770e 100644 --- a/packages/babel-standalone/package.json +++ b/packages/babel-standalone/package.json @@ -35,6 +35,7 @@ "@babel/plugin-proposal-private-methods": "workspace:^", "@babel/plugin-proposal-private-property-in-object": "workspace:^", "@babel/plugin-proposal-record-and-tuple": "workspace:^", + "@babel/plugin-proposal-regexp-modifiers": "workspace:^", "@babel/plugin-proposal-throw-expressions": "workspace:^", "@babel/plugin-proposal-unicode-property-regex": "workspace:^", "@babel/plugin-proposal-unicode-sets-regex": "workspace:^", diff --git a/packages/babel-standalone/scripts/pluginConfig.json b/packages/babel-standalone/scripts/pluginConfig.json index 1d03b194f388..815d03edd31c 100644 --- a/packages/babel-standalone/scripts/pluginConfig.json +++ b/packages/babel-standalone/scripts/pluginConfig.json @@ -59,6 +59,7 @@ "proposal-private-methods", "proposal-private-property-in-object", "proposal-record-and-tuple", + "proposal-regexp-modifiers", "proposal-throw-expressions", "proposal-unicode-property-regex", "proposal-unicode-sets-regex", diff --git a/packages/babel-standalone/src/generated/plugins.ts b/packages/babel-standalone/src/generated/plugins.ts index 925ecaae8d69..285f8946c40c 100644 --- a/packages/babel-standalone/src/generated/plugins.ts +++ b/packages/babel-standalone/src/generated/plugins.ts @@ -43,6 +43,7 @@ import proposalPipelineOperator from "@babel/plugin-proposal-pipeline-operator"; import proposalPrivateMethods from "@babel/plugin-proposal-private-methods"; import proposalPrivatePropertyInObject from "@babel/plugin-proposal-private-property-in-object"; import proposalRecordAndTuple from "@babel/plugin-proposal-record-and-tuple"; +import proposalRegexpModifiers from "@babel/plugin-proposal-regexp-modifiers"; import proposalThrowExpressions from "@babel/plugin-proposal-throw-expressions"; import proposalUnicodePropertyRegex from "@babel/plugin-proposal-unicode-property-regex"; import proposalUnicodeSetsRegex from "@babel/plugin-proposal-unicode-sets-regex"; @@ -145,6 +146,7 @@ export { proposalPrivateMethods, proposalPrivatePropertyInObject, proposalRecordAndTuple, + proposalRegexpModifiers, proposalThrowExpressions, proposalUnicodePropertyRegex, proposalUnicodeSetsRegex, @@ -249,6 +251,7 @@ export const all: { [k: string]: any } = { "proposal-private-methods": proposalPrivateMethods, "proposal-private-property-in-object": proposalPrivatePropertyInObject, "proposal-record-and-tuple": proposalRecordAndTuple, + "proposal-regexp-modifiers": proposalRegexpModifiers, "proposal-throw-expressions": proposalThrowExpressions, "proposal-unicode-property-regex": proposalUnicodePropertyRegex, "proposal-unicode-sets-regex": proposalUnicodeSetsRegex, diff --git a/packages/babel-standalone/src/preset-stage-3.ts b/packages/babel-standalone/src/preset-stage-3.ts index 56749b82e9e1..8266bd2ec3b0 100644 --- a/packages/babel-standalone/src/preset-stage-3.ts +++ b/packages/babel-standalone/src/preset-stage-3.ts @@ -13,13 +13,7 @@ export default (_: any, opts: any = {}) => { babelPlugins.syntaxImportAssertions, babelPlugins.proposalUnicodeSetsRegex, babelPlugins.proposalDuplicateNamedCapturingGroupsRegex, - [ - babelPlugins.proposalDecorators, - { - version: decoratorsLegacy ? "legacy" : decoratorsVersion, - decoratorsBeforeExport, - }, - ], + babelPlugins.proposalRegexpModifiers, ]; if (!process.env.BABEL_8_BREAKING) { diff --git a/tsconfig.json b/tsconfig.json index f0b50ceeaf81..59a3478a1cb5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -67,6 +67,7 @@ "./packages/babel-plugin-proposal-private-methods/src/**/*.ts", "./packages/babel-plugin-proposal-private-property-in-object/src/**/*.ts", "./packages/babel-plugin-proposal-record-and-tuple/src/**/*.ts", + "./packages/babel-plugin-proposal-regexp-modifiers/src/**/*.ts", "./packages/babel-plugin-proposal-throw-expressions/src/**/*.ts", "./packages/babel-plugin-proposal-unicode-property-regex/src/**/*.ts", "./packages/babel-plugin-proposal-unicode-sets-regex/src/**/*.ts", @@ -367,6 +368,9 @@ "@babel/plugin-proposal-record-and-tuple": [ "./packages/babel-plugin-proposal-record-and-tuple/src" ], + "@babel/plugin-proposal-regexp-modifiers": [ + "./packages/babel-plugin-proposal-regexp-modifiers/src" + ], "@babel/plugin-proposal-throw-expressions": [ "./packages/babel-plugin-proposal-throw-expressions/src" ], diff --git a/yarn.lock b/yarn.lock index cc7549473d09..33e37d715e54 100644 --- a/yarn.lock +++ b/yarn.lock @@ -636,7 +636,7 @@ __metadata: "@babel/core": "workspace:^" "@babel/helper-annotate-as-pure": "workspace:^" "@babel/helper-plugin-test-runner": "workspace:^" - regexpu-core: ^5.2.1 + regexpu-core: "https://github.com/liuxingbaoyu/regexpu-core#head=modifiers" peerDependencies: "@babel/core": ^7.0.0 languageName: unknown @@ -1764,6 +1764,18 @@ __metadata: languageName: unknown linkType: soft +"@babel/plugin-proposal-regexp-modifiers@workspace:^, @babel/plugin-proposal-regexp-modifiers@workspace:packages/babel-plugin-proposal-regexp-modifiers": + version: 0.0.0-use.local + resolution: "@babel/plugin-proposal-regexp-modifiers@workspace:packages/babel-plugin-proposal-regexp-modifiers" + dependencies: + "@babel/core": "workspace:^" + "@babel/helper-create-regexp-features-plugin": "workspace:^" + "@babel/helper-plugin-utils": "workspace:^" + peerDependencies: + "@babel/core": ^7.0.0 + languageName: unknown + linkType: soft + "@babel/plugin-proposal-throw-expressions@workspace:^, @babel/plugin-proposal-throw-expressions@workspace:packages/babel-plugin-proposal-throw-expressions": version: 0.0.0-use.local resolution: "@babel/plugin-proposal-throw-expressions@workspace:packages/babel-plugin-proposal-throw-expressions" @@ -3683,6 +3695,7 @@ __metadata: "@babel/plugin-proposal-private-methods": "workspace:^" "@babel/plugin-proposal-private-property-in-object": "workspace:^" "@babel/plugin-proposal-record-and-tuple": "workspace:^" + "@babel/plugin-proposal-regexp-modifiers": "workspace:^" "@babel/plugin-proposal-throw-expressions": "workspace:^" "@babel/plugin-proposal-unicode-property-regex": "workspace:^" "@babel/plugin-proposal-unicode-sets-regex": "workspace:^" From e496c1a1116da6bbe210b26fe8a6d89f980df95e Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Thu, 9 Feb 2023 18:20:47 +0800 Subject: [PATCH 02/10] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolò Ribaudo --- .../babel-helper-create-regexp-features-plugin/package.json | 2 +- packages/babel-helper-create-regexp-features-plugin/src/util.ts | 2 +- packages/babel-plugin-proposal-regexp-modifiers/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/babel-helper-create-regexp-features-plugin/package.json b/packages/babel-helper-create-regexp-features-plugin/package.json index 19e6ebb52dcd..3afc5326a3a9 100644 --- a/packages/babel-helper-create-regexp-features-plugin/package.json +++ b/packages/babel-helper-create-regexp-features-plugin/package.json @@ -19,7 +19,7 @@ ], "dependencies": { "@babel/helper-annotate-as-pure": "workspace:^", - "regexpu-core": "https://github.com/liuxingbaoyu/regexpu-core#head=modifiers" + "regexpu-core": "^5.3.0" }, "peerDependencies": { "@babel/core": "^7.0.0" diff --git a/packages/babel-helper-create-regexp-features-plugin/src/util.ts b/packages/babel-helper-create-regexp-features-plugin/src/util.ts index 05ee3ab3d378..7396baf3219a 100644 --- a/packages/babel-helper-create-regexp-features-plugin/src/util.ts +++ b/packages/babel-helper-create-regexp-features-plugin/src/util.ts @@ -72,7 +72,7 @@ export function canSkipRegexpu( return false; } - if (options.modifiers === "transform" && /\(\?.{1,10}:/.test(pattern)) { + if (options.modifiers === "transform" && /\(\?[\w-]+:/.test(pattern)) { return false; } diff --git a/packages/babel-plugin-proposal-regexp-modifiers/package.json b/packages/babel-plugin-proposal-regexp-modifiers/package.json index 5aeecf004efe..dc2c1f444141 100644 --- a/packages/babel-plugin-proposal-regexp-modifiers/package.json +++ b/packages/babel-plugin-proposal-regexp-modifiers/package.json @@ -1,7 +1,7 @@ { "name": "@babel/plugin-proposal-regexp-modifiers", "version": "7.19.1", - "description": "TODO", + "description": "Compile inline regular expression modifiers", "homepage": "https://babel.dev/docs/en/next/babel-plugin-proposal-regexp-modifiers", "license": "MIT", "publishConfig": { From 85f60e8c4e709fe71df0b40bf9ffee089c07ff23 Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Sat, 11 Feb 2023 18:57:21 +0800 Subject: [PATCH 03/10] rebase --- yarn.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn.lock b/yarn.lock index 33e37d715e54..904ad4add2c7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -636,7 +636,7 @@ __metadata: "@babel/core": "workspace:^" "@babel/helper-annotate-as-pure": "workspace:^" "@babel/helper-plugin-test-runner": "workspace:^" - regexpu-core: "https://github.com/liuxingbaoyu/regexpu-core#head=modifiers" + regexpu-core: ^5.3.0 peerDependencies: "@babel/core": ^7.0.0 languageName: unknown @@ -13134,7 +13134,7 @@ fsevents@^1.2.7: languageName: node linkType: hard -"regexpu-core@npm:^5.2.1": +"regexpu-core@npm:^5.2.1, regexpu-core@npm:^5.3.0": version: 5.3.0 resolution: "regexpu-core@npm:5.3.0" dependencies: From d54234ac58444260cd98e01e8a86524f5be09d53 Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Tue, 14 Feb 2023 23:37:54 +0800 Subject: [PATCH 04/10] fix tests --- .../test/fixtures/syntax/basic/output.js | 4 ++-- .../test/fixtures/syntax/with-u-flag/output.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/output.js b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/output.js index 8f2e4896210c..8b31dd64bfe1 100644 --- a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/output.js +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/output.js @@ -1,2 +1,2 @@ -/((?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z]1(?:$|(?=[\n\r\u2028\u2029])))/; -/(^[a-z].1$)((?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z][\s\S])/; +/(?:(?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z]1(?:$|(?=[\n\r\u2028\u2029])))/; +/(?:^[a-z].1$)((?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z][\s\S])/; diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/output.js b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/output.js index 2aec15cd857c..3eab42554df0 100644 --- a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/output.js +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/output.js @@ -1,2 +1,2 @@ -/((?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z\u017F\u212A])/; -/(^[a-z](?:[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))((?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z\u017F\u212A](?:[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/; +/(?:(?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z\u017F\u212A])/; +/(?:^[a-z](?:[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))((?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z\u017F\u212A](?:[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/; From 3b0a584d4b304af3bc73d281c7e4dc7b569815b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 16 Feb 2023 16:36:19 +0100 Subject: [PATCH 05/10] Update regexpu-core --- .../package.json | 2 +- yarn.lock | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/babel-helper-create-regexp-features-plugin/package.json b/packages/babel-helper-create-regexp-features-plugin/package.json index 3afc5326a3a9..bc688e22d15c 100644 --- a/packages/babel-helper-create-regexp-features-plugin/package.json +++ b/packages/babel-helper-create-regexp-features-plugin/package.json @@ -19,7 +19,7 @@ ], "dependencies": { "@babel/helper-annotate-as-pure": "workspace:^", - "regexpu-core": "^5.3.0" + "regexpu-core": "^5.3.1" }, "peerDependencies": { "@babel/core": "^7.0.0" diff --git a/yarn.lock b/yarn.lock index 904ad4add2c7..0f6ae63e8433 100644 --- a/yarn.lock +++ b/yarn.lock @@ -636,7 +636,7 @@ __metadata: "@babel/core": "workspace:^" "@babel/helper-annotate-as-pure": "workspace:^" "@babel/helper-plugin-test-runner": "workspace:^" - regexpu-core: ^5.3.0 + regexpu-core: ^5.3.1 peerDependencies: "@babel/core": ^7.0.0 languageName: unknown @@ -13134,7 +13134,7 @@ fsevents@^1.2.7: languageName: node linkType: hard -"regexpu-core@npm:^5.2.1, regexpu-core@npm:^5.3.0": +"regexpu-core@npm:^5.2.1": version: 5.3.0 resolution: "regexpu-core@npm:5.3.0" dependencies: @@ -13148,6 +13148,20 @@ fsevents@^1.2.7: languageName: node linkType: hard +"regexpu-core@npm:^5.3.1": + version: 5.3.1 + resolution: "regexpu-core@npm:5.3.1" + dependencies: + "@babel/regjsgen": ^0.8.0 + regenerate: ^1.4.2 + regenerate-unicode-properties: ^10.1.0 + regjsparser: ^0.9.1 + unicode-match-property-ecmascript: ^2.0.0 + unicode-match-property-value-ecmascript: ^2.1.0 + checksum: 446fbbb79059afcd64d11ea573276e2df97ee7ad45aa452834d3b2aef7edf7bfe206c310f57f9345d8c95bfedbf9c16a9529f9219a05ae6a6b0d6f0dbe523b33 + languageName: node + linkType: hard + "regjsparser@npm:^0.9.1": version: 0.9.1 resolution: "regjsparser@npm:0.9.1" From 15b602298bb0275d4b80171a45dff2c751b514f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 16 Feb 2023 16:41:59 +0100 Subject: [PATCH 06/10] `yarn dedupe` --- yarn.lock | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/yarn.lock b/yarn.lock index 0f6ae63e8433..bfab5e433f31 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13134,21 +13134,7 @@ fsevents@^1.2.7: languageName: node linkType: hard -"regexpu-core@npm:^5.2.1": - version: 5.3.0 - resolution: "regexpu-core@npm:5.3.0" - dependencies: - "@babel/regjsgen": ^0.8.0 - regenerate: ^1.4.2 - regenerate-unicode-properties: ^10.1.0 - regjsparser: ^0.9.1 - unicode-match-property-ecmascript: ^2.0.0 - unicode-match-property-value-ecmascript: ^2.1.0 - checksum: f3c7921543ebda919c53fdbbf3a9cebbecbf8ad65b30e423d7eaef35484e08cbc919f9e8334f4693a72206f583d4f2b48d4415483f6e6e8c81f0046e3a23c66f - languageName: node - linkType: hard - -"regexpu-core@npm:^5.3.1": +"regexpu-core@npm:^5.2.1, regexpu-core@npm:^5.3.1": version: 5.3.1 resolution: "regexpu-core@npm:5.3.1" dependencies: From 6cabb8b2c9f33b79180732b5d7698c2e870410b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 16 Feb 2023 16:59:32 +0100 Subject: [PATCH 07/10] Disable tests on Node.js 6 --- .../test/fixtures/syntax/basic/options.json | 3 ++- .../test/fixtures/syntax/with-u-flag/options.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/options.json b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/options.json index da996fb6c95b..d2a834e3d767 100644 --- a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/options.json +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/options.json @@ -1,3 +1,4 @@ { - "plugins": ["proposal-regexp-modifiers"] + "plugins": ["proposal-regexp-modifiers"], + "minNodeVersion": "8.0.0" } diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/options.json b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/options.json index 39d545141c49..24af1c1a4663 100644 --- a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/options.json +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/options.json @@ -1,3 +1,4 @@ { - "plugins": ["proposal-regexp-modifiers", "transform-unicode-regex"] + "plugins": ["proposal-regexp-modifiers", "transform-unicode-regex"], + "minNodeVersion": "8.0.0" } From 44aa17728f3d66929689d10d8faed38f9d7d27ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sat, 18 Feb 2023 17:15:16 +0100 Subject: [PATCH 08/10] Reorganize tests to have at least one running on Node.js 6 --- .../fixtures/syntax/{basic => without-u-flag-exec}/exec.js | 0 .../syntax/{basic => without-u-flag-exec}/options.json | 0 .../test/fixtures/syntax/{basic => without-u-flag}/input.js | 0 .../test/fixtures/syntax/without-u-flag/options.json | 3 +++ .../test/fixtures/syntax/{basic => without-u-flag}/output.js | 0 5 files changed, 3 insertions(+) rename packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/{basic => without-u-flag-exec}/exec.js (100%) rename packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/{basic => without-u-flag-exec}/options.json (100%) rename packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/{basic => without-u-flag}/input.js (100%) create mode 100644 packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag/options.json rename packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/{basic => without-u-flag}/output.js (100%) diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/exec.js b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag-exec/exec.js similarity index 100% rename from packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/exec.js rename to packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag-exec/exec.js diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/options.json b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag-exec/options.json similarity index 100% rename from packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/options.json rename to packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag-exec/options.json diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/input.js b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag/input.js similarity index 100% rename from packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/input.js rename to packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag/input.js diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag/options.json b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag/options.json new file mode 100644 index 000000000000..da996fb6c95b --- /dev/null +++ b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-regexp-modifiers"] +} diff --git a/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/output.js b/packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag/output.js similarity index 100% rename from packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/basic/output.js rename to packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag/output.js From 2a8d36102b70506912430ab8443b42fefd948f2d Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Mon, 20 Feb 2023 02:15:23 +0800 Subject: [PATCH 09/10] fix rebase --- packages/babel-standalone/src/preset-stage-3.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/babel-standalone/src/preset-stage-3.ts b/packages/babel-standalone/src/preset-stage-3.ts index 8266bd2ec3b0..4fa050fea9c4 100644 --- a/packages/babel-standalone/src/preset-stage-3.ts +++ b/packages/babel-standalone/src/preset-stage-3.ts @@ -13,6 +13,13 @@ export default (_: any, opts: any = {}) => { babelPlugins.syntaxImportAssertions, babelPlugins.proposalUnicodeSetsRegex, babelPlugins.proposalDuplicateNamedCapturingGroupsRegex, + [ + babelPlugins.proposalDecorators, + { + version: decoratorsLegacy ? "legacy" : decoratorsVersion, + decoratorsBeforeExport, + }, + ], babelPlugins.proposalRegexpModifiers, ]; From b9bfc5de4b08a3a1a9ce0383e011515d71210e4f Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Mon, 20 Feb 2023 02:41:12 +0800 Subject: [PATCH 10/10] improve type --- .../babel-standalone/src/preset-stage-3.ts | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/packages/babel-standalone/src/preset-stage-3.ts b/packages/babel-standalone/src/preset-stage-3.ts index 4fa050fea9c4..69b45b30efd9 100644 --- a/packages/babel-standalone/src/preset-stage-3.ts +++ b/packages/babel-standalone/src/preset-stage-3.ts @@ -8,8 +8,7 @@ export default (_: any, opts: any = {}) => { decoratorsBeforeExport, } = opts; - // todo(flow->ts) improve types - const plugins: any[] = [ + const plugins = [ babelPlugins.syntaxImportAssertions, babelPlugins.proposalUnicodeSetsRegex, babelPlugins.proposalDuplicateNamedCapturingGroupsRegex, @@ -21,23 +20,22 @@ export default (_: any, opts: any = {}) => { }, ], babelPlugins.proposalRegexpModifiers, - ]; - - if (!process.env.BABEL_8_BREAKING) { // These are Stage 4 - plugins.push( - babelPlugins.proposalExportNamespaceFrom, - babelPlugins.proposalLogicalAssignmentOperators, - [babelPlugins.proposalOptionalChaining, { loose }], - [babelPlugins.proposalNullishCoalescingOperator, { loose }], - [babelPlugins.proposalClassProperties, { loose }], - babelPlugins.proposalJsonStrings, - babelPlugins.proposalNumericSeparator, - [babelPlugins.proposalPrivateMethods, { loose }], - babelPlugins.proposalPrivatePropertyInObject, - babelPlugins.proposalClassStaticBlock, - ); - } + ...(process.env.BABEL_8_BREAKING + ? [] + : [ + babelPlugins.proposalExportNamespaceFrom, + babelPlugins.proposalLogicalAssignmentOperators, + [babelPlugins.proposalOptionalChaining, { loose }], + [babelPlugins.proposalNullishCoalescingOperator, { loose }], + [babelPlugins.proposalClassProperties, { loose }], + babelPlugins.proposalJsonStrings, + babelPlugins.proposalNumericSeparator, + [babelPlugins.proposalPrivateMethods, { loose }], + babelPlugins.proposalPrivatePropertyInObject, + babelPlugins.proposalClassStaticBlock, + ]), + ]; return { plugins }; };