1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.canSkipRegexpu = canSkipRegexpu;
|
---|
7 | exports.generateRegexpuOptions = generateRegexpuOptions;
|
---|
8 | exports.transformFlags = transformFlags;
|
---|
9 | var _features = require("./features.js");
|
---|
10 | function generateRegexpuOptions(pattern, toTransform) {
|
---|
11 | const feat = name => {
|
---|
12 | return (0, _features.hasFeature)(toTransform, _features.FEATURES[name]) ? "transform" : false;
|
---|
13 | };
|
---|
14 | const featDuplicateNamedGroups = () => {
|
---|
15 | if (!feat("duplicateNamedCaptureGroups")) return false;
|
---|
16 | const regex = /\(\?<([^>]+)>/g;
|
---|
17 | const seen = new Set();
|
---|
18 | for (let match; match = regex.exec(pattern); seen.add(match[1])) {
|
---|
19 | if (seen.has(match[1])) return "transform";
|
---|
20 | }
|
---|
21 | return false;
|
---|
22 | };
|
---|
23 | return {
|
---|
24 | unicodeFlag: feat("unicodeFlag"),
|
---|
25 | unicodeSetsFlag: feat("unicodeSetsFlag"),
|
---|
26 | dotAllFlag: feat("dotAllFlag"),
|
---|
27 | unicodePropertyEscapes: feat("unicodePropertyEscape"),
|
---|
28 | namedGroups: feat("namedCaptureGroups") || featDuplicateNamedGroups(),
|
---|
29 | onNamedGroup: () => {},
|
---|
30 | modifiers: feat("modifiers")
|
---|
31 | };
|
---|
32 | }
|
---|
33 | function canSkipRegexpu(node, options) {
|
---|
34 | const {
|
---|
35 | flags,
|
---|
36 | pattern
|
---|
37 | } = node;
|
---|
38 | if (flags.includes("v")) {
|
---|
39 | if (options.unicodeSetsFlag === "transform") return false;
|
---|
40 | }
|
---|
41 | if (flags.includes("u")) {
|
---|
42 | if (options.unicodeFlag === "transform") return false;
|
---|
43 | if (options.unicodePropertyEscapes === "transform" && /\\p\{/i.test(pattern)) {
|
---|
44 | return false;
|
---|
45 | }
|
---|
46 | }
|
---|
47 | if (flags.includes("s")) {
|
---|
48 | if (options.dotAllFlag === "transform") return false;
|
---|
49 | }
|
---|
50 | if (options.namedGroups === "transform" && /\(\?<(?![=!])/.test(pattern)) {
|
---|
51 | return false;
|
---|
52 | }
|
---|
53 | if (options.modifiers === "transform" && /\(\?[\w-]+:/.test(pattern)) {
|
---|
54 | return false;
|
---|
55 | }
|
---|
56 | return true;
|
---|
57 | }
|
---|
58 | function transformFlags(regexpuOptions, flags) {
|
---|
59 | if (regexpuOptions.unicodeSetsFlag === "transform") {
|
---|
60 | flags = flags.replace("v", "u");
|
---|
61 | }
|
---|
62 | if (regexpuOptions.unicodeFlag === "transform") {
|
---|
63 | flags = flags.replace("u", "");
|
---|
64 | }
|
---|
65 | if (regexpuOptions.dotAllFlag === "transform") {
|
---|
66 | flags = flags.replace("s", "");
|
---|
67 | }
|
---|
68 | return flags;
|
---|
69 | }
|
---|
70 |
|
---|
71 | //# sourceMappingURL=util.js.map
|
---|