| 1 | import type { types as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/ } from "@babel/core"scip-typescript npm @babel/core 7.20.12 src/`index.ts`/; |
| 2 | import { FEATURESscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/FEATURES., hasFeaturescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/hasFeature(). } from "./features"scip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/; |
| 3 | |
| 4 | import type { RegexpuOptionsscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions# } from "regexpu-core"scip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/; |
| 5 | |
| 6 | export function generateRegexpuOptionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/generateRegexpuOptions().( |
| 7 | patternscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/generateRegexpuOptions().(pattern): string, |
| 8 | toTransformscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/generateRegexpuOptions().(toTransform): number, |
| 9 | ): RegexpuOptionsscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions# { |
| 10 | type Experimental = 1; |
| 11 | |
| 12 | const feat = <Stability extends 0 | 1 = 0>( |
| 13 | name: keyof typeof FEATURESscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/FEATURES., |
| 14 | ok: "transform" | (Stability extends 0 ? never : "parse") = "transform", |
| 15 | ) => { |
| 16 | return hasFeaturescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/hasFeature().(toTransformscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/generateRegexpuOptions().(toTransform), FEATURESscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/FEATURES.[name]) ? ok : false; |
| 17 | }; |
| 18 | |
| 19 | const featDuplicateNamedGroups = (): "transform" | false => { |
| 20 | if (!feat("duplicateNamedCaptureGroups")) return false; |
| 21 | |
| 22 | // This can return false positive, for example for /\(?<a>\)/. |
| 23 | // However, it's such a rare occurrence that it's ok to compile |
| 24 | // the regexp even if we only need to compile regexps with |
| 25 | // duplicate named capturing groups. |
| 26 | const regex = /\(\?<([^>]+)>/g; |
| 27 | const seen = new Setscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#(); |
| 28 | for (let match; (match = regex.execscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/RegExp#exec().(patternscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/generateRegexpuOptions().(pattern))); seen.addscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#add().(match[1])) { |
| 29 | if (seen.hasscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#has().(match[1])) return "transform"; |
| 30 | } |
| 31 | return false; |
| 32 | }; |
| 33 | |
| 34 | return { |
| 35 | unicodeFlagscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:unicodeFlag.: feat("unicodeFlag"), |
| 36 | unicodeSetsFlagscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:unicodeSetsFlag.: |
| 37 | feat<Experimental>("unicodeSetsFlag") || |
| 38 | feat<Experimental>("unicodeSetsFlag_syntax", "parse"), |
| 39 | dotAllFlagscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:dotAllFlag.: feat("dotAllFlag"), |
| 40 | unicodePropertyEscapesscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:unicodePropertyEscapes.: feat("unicodePropertyEscape"), |
| 41 | namedGroupsscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:namedGroups.: feat("namedCaptureGroups") || featDuplicateNamedGroups(), |
| 42 | onNamedGroupscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:onNamedGroup.: () => {}, |
| 43 | }; |
| 44 | } |
| 45 | |
| 46 | export function canSkipRegexpuscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/canSkipRegexpu().( |
| 47 | nodescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/canSkipRegexpu().(node): tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.RegExpLiteralscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/RegExpLiteral#, |
| 48 | optionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/canSkipRegexpu().(options): RegexpuOptionsscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#, |
| 49 | ): boolean { |
| 50 | const { flagsscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/RegExpLiteral#flags., patternscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/RegExpLiteral#pattern. } = nodescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/canSkipRegexpu().(node); |
| 51 | |
| 52 | if (flags.includesscip-typescript npm typescript 5.9.3 lib/`lib.es2015.core.d.ts`/String#includes().("v")) { |
| 53 | if (optionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/canSkipRegexpu().(options).unicodeSetsFlagscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:unicodeSetsFlag. === "transform") return false; |
| 54 | } |
| 55 | |
| 56 | if (flags.includesscip-typescript npm typescript 5.9.3 lib/`lib.es2015.core.d.ts`/String#includes().("u")) { |
| 57 | if (optionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/canSkipRegexpu().(options).unicodeFlagscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:unicodeFlag. === "transform") return false; |
| 58 | if ( |
| 59 | optionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/canSkipRegexpu().(options).unicodePropertyEscapesscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:unicodePropertyEscapes. === "transform" && |
| 60 | /\\[pP]{/.testscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/RegExp#test().(pattern) |
| 61 | ) { |
| 62 | return false; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if (flags.includesscip-typescript npm typescript 5.9.3 lib/`lib.es2015.core.d.ts`/String#includes().("s")) { |
| 67 | if (optionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/canSkipRegexpu().(options).dotAllFlagscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:dotAllFlag. === "transform") return false; |
| 68 | } |
| 69 | |
| 70 | if (optionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/canSkipRegexpu().(options).namedGroupsscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:namedGroups. === "transform" && /\(\?<(?![=!])/.testscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/RegExp#test().(pattern)) { |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | export function transformFlagsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(regexpuOptionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(regexpuOptions): RegexpuOptionsscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#, flagsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(flags): string) { |
| 78 | if (regexpuOptionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(regexpuOptions).unicodeSetsFlagscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:unicodeSetsFlag. === "transform") { |
| 79 | flagsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(flags) = flagsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(flags).replacescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#replace().("v", "u"); |
| 80 | } |
| 81 | if (regexpuOptionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(regexpuOptions).unicodeFlagscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:unicodeFlag. === "transform") { |
| 82 | flagsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(flags) = flagsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(flags).replacescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#replace().("u", ""); |
| 83 | } |
| 84 | if (regexpuOptionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(regexpuOptions).dotAllFlagscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:dotAllFlag. === "transform") { |
| 85 | flagsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(flags) = flagsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(flags).replacescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#replace().("s", ""); |
| 86 | } |
| 87 | return flagsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(flags); |
| 88 | } |