You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
parttimejob/node_modules/@babel/helper-create-regexp-featur.../lib/util.js.map

1 line
5.0 KiB

4 weeks ago
{"version":3,"names":["_features","require","generateRegexpuOptions","pattern","toTransform","feat","name","hasFeature","FEATURES","featDuplicateNamedGroups","regex","seen","Set","match","exec","add","has","unicodeFlag","unicodeSetsFlag","dotAllFlag","unicodePropertyEscapes","namedGroups","onNamedGroup","modifiers","canSkipRegexpu","node","options","flags","includes","test","transformFlags","regexpuOptions","replace"],"sources":["../src/util.ts"],"sourcesContent":["import type { types as t } from \"@babel/core\";\nimport { FEATURES, hasFeature } from \"./features.ts\";\n\nimport type { RegexpuOptions } from \"regexpu-core\";\n\nexport function generateRegexpuOptions(\n pattern: string,\n toTransform: number,\n): RegexpuOptions {\n const feat = (name: keyof typeof FEATURES) => {\n return hasFeature(toTransform, FEATURES[name]) ? \"transform\" : false;\n };\n\n const featDuplicateNamedGroups = (): \"transform\" | false => {\n if (!feat(\"duplicateNamedCaptureGroups\")) return false;\n\n // This can return false positive, for example for /\\(?<a>\\)/.\n // However, it's such a rare occurrence that it's ok to compile\n // the regexp even if we only need to compile regexps with\n // duplicate named capturing groups.\n const regex = /\\(\\?<([^>]+)>/g;\n const seen = new Set();\n for (let match; (match = regex.exec(pattern)); seen.add(match[1])) {\n if (seen.has(match[1])) return \"transform\";\n }\n return false;\n };\n\n return {\n unicodeFlag: feat(\"unicodeFlag\"),\n unicodeSetsFlag: feat(\"unicodeSetsFlag\"),\n dotAllFlag: feat(\"dotAllFlag\"),\n unicodePropertyEscapes: feat(\"unicodePropertyEscape\"),\n namedGroups: feat(\"namedCaptureGroups\") || featDuplicateNamedGroups(),\n onNamedGroup: () => {},\n modifiers: feat(\"modifiers\"),\n };\n}\n\nexport function canSkipRegexpu(\n node: t.RegExpLiteral,\n options: RegexpuOptions,\n): boolean {\n const { flags, pattern } = node;\n\n if (flags.includes(\"v\")) {\n if (options.unicodeSetsFlag === \"transform\") return false;\n }\n\n if (flags.includes(\"u\")) {\n if (options.unicodeFlag === \"transform\") return false;\n if (\n options.unicodePropertyEscapes === \"transform\" &&\n /\\\\p\\{/i.test(pattern)\n ) {\n return false;\n }\n }\n\n if (flags.includes(\"s\")) {\n if (options.dotAllFlag === \"transform\") return false;\n }\n\n if (options.namedGroups === \"transform\" && /\\(\\?<(?![=!])/.test(pattern)) {\n return false;\n }\n\n if (options.modifiers === \"transform\" && /\\(\\?[\\w-]+:/.test(pattern)) {\n return false;\n }\n\n return true;\n}\n\nexport function transformFlags(regexpuOptions: RegexpuOptions, flags: string) {\n if (regexpuOptions.unicodeSetsFlag === \"transform\") {\n flags = flags.replace(\"v\", \"u\");\n }\n if (regexpuOptions.unicodeFlag === \"transform\") {\n flags = flags.replace(\"u\", \"\");\n }\n if (regexpuOptions.dotAllFlag === \"transform\") {\n flags = flags.replace(\"s\", \"\");\n }\n return flags;\n}\n"],"mappings":";;;;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AAIO,SAASC,sBAAsBA,CACpCC,OAAe,EACfC,WAAmB,EACH;EAChB,MAAMC,IAAI,GAAIC,IAA2B,IAAK;IAC5C,OAAO,IAAAC,oBAAU,EAACH,WAAW,EAAEI,kBAAQ,CAACF,IAAI,CAAC,CAAC,GAAG,WAAW,GAAG,KAAK;EACtE,CAAC;EAED,MAAMG,wBAAwB,GAAGA,CAAA,KAA2B;IAC1D,IAAI,CAACJ,IAAI,CAAC,6BAA6B,CAAC,EAAE,OAAO,KAAK;IAMtD,MAAMK,KAAK,GAAG,gBAAgB;IAC9B,MAAMC,IAAI,GAAG,IAAIC,GAAG,CAAC,CAAC;IACtB,KAAK,IAAIC,KAAK,EAAGA,KAAK,GAAGH,KAAK,CAACI,IAAI,CAACX,OAAO,CAAC,EAAGQ,IAAI,CAACI,GAAG,CAACF,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;MACjE,IAAIF,IAAI,CAACK,GAAG,CAACH,KAAK,CAAC,CA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