Debian Codegraph @

packages/babel-helper-create-regexp-features-plugin/src/index.ts

raw symbols SCIP
1 import rewritePatternscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/rewritePattern(). from "regexpu-core"scip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/;
2 import {
3 featuresKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/featuresKey.,
4 FEATURESscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/FEATURES.,
5 enableFeaturescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/enableFeature().,
6 runtimeKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/runtimeKey.,
7 hasFeaturescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/hasFeature().,
8 } from "./features"scip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/;
9 import { generateRegexpuOptionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/generateRegexpuOptions()., canSkipRegexpuscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/canSkipRegexpu()., transformFlagsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags(). } from "./util"scip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/;
10 import type { NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath# } from "@babel/traverse"scip-typescript npm @babel/traverse 7.20.13 src/`index.ts`/;
11
12 import { 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`/;
13 import type { PluginObjectscip-typescript npm @babel/core 7.20.12 src/config/validation/`plugins.ts`/PluginObject# } from "@babel/core"scip-typescript npm @babel/core 7.20.12 src/`index.ts`/;
14 import annotateAsPurescip-typescript npm @babel/helper-annotate-as-pure 7.18.6 src/`index.ts`/annotateAsPure(). from "@babel/helper-annotate-as-pure"scip-typescript npm @babel/helper-annotate-as-pure 7.18.6 src/`index.ts`/;
15
16 declare const PACKAGE_JSONscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/PACKAGE_JSON.: { namescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/PACKAGE_JSON.typeLiteral2:name.: string; versionscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/PACKAGE_JSON.typeLiteral2:version.: string };
17
18 // Note: Versions are represented as an integer. e.g. 7.1.5 is represented
19 // as 70000100005. This method is easier than using a semver-parsing
20 // package, but it breaks if we release x.y.z where x, y or z are
21 // greater than 99_999.
22 const versionscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/version. = PACKAGE_JSONscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/PACKAGE_JSON..versionscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/PACKAGE_JSON.typeLiteral2:version.
23 .splitscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#split().(".")
24 .reducescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#reduce().((v, x) => v * 1e5 + +x, 0);
25 const versionKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/versionKey. = "@babel/plugin-regexp-features/version";
26
27 export interface Optionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options# {
28 namescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#name.: string;
29 featurescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#feature.: keyof typeof FEATURESscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/FEATURES.;
30 optionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#options.?: {
31 useUnicodeFlagscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#options.typeLiteral7:useUnicodeFlag.?: boolean;
32 runtimescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#options.typeLiteral7:runtime.?: boolean;
33 };
34 manipulateOptionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#manipulateOptions.?: PluginObjectscip-typescript npm @babel/core 7.20.12 src/config/validation/`plugins.ts`/PluginObject#["manipulateOptions"scip-typescript npm @babel/core 7.20.12 src/config/validation/`plugins.ts`/PluginObject#typeLiteral0:manipulateOptions.];
35 }
36
37 export function createRegExpFeaturePluginscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/createRegExpFeaturePlugin().({
38 namescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#name.,
39 featurescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#feature.,
40 optionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#options. = {},
41 manipulateOptionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#manipulateOptions. = () => {},
42 }: Optionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#): PluginObjectscip-typescript npm @babel/core 7.20.12 src/config/validation/`plugins.ts`/PluginObject# {
43 return {
44 namescip-typescript npm @babel/core 7.20.12 src/config/validation/`plugins.ts`/PluginObject#typeLiteral0:name.,
45
46 manipulateOptionsscip-typescript npm @babel/core 7.20.12 src/config/validation/`plugins.ts`/PluginObject#typeLiteral0:manipulateOptions.,
47
48 prescip-typescript npm @babel/core 7.20.12 src/config/validation/`plugins.ts`/PluginObject#typeLiteral0:pre.() {
49 const { filescip-typescript npm @babel/core 7.20.12 src/transformation/`plugin-pass.ts`/PluginPass#file. } = this;
50 const features = file.getscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#get().(featuresKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/featuresKey.) ?? 0;
51 let newFeatures = enableFeaturescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/enableFeature().(features, FEATURESscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/FEATURES.[feature]);
52
53 const { useUnicodeFlagscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#options.typeLiteral7:useUnicodeFlag., runtimescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/Options#options.typeLiteral7:runtime. } = options;
54 if (useUnicodeFlag === false) {
55 newFeatures = enableFeaturescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/enableFeature().(newFeatures, FEATURESscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/FEATURES..unicodeFlagscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/unicodeFlag0:);
56 }
57 if (newFeatures !== features) {
58 file.setscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#set().(featuresKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/featuresKey., newFeatures);
59 }
60
61 if (runtime !== undefined) {
62 if (
63 file.hasscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#has().(runtimeKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/runtimeKey.) &&
64 file.getscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#get().(runtimeKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/runtimeKey.) !== runtime &&
65 // TODO(Babel 8): Remove this check. It's necessary because in Babel 7
66 // we allow multiple copies of transform-named-capturing-groups-regex
67 // with conflicting 'runtime' options.
68 hasFeaturescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/hasFeature().(newFeatures, FEATURESscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/FEATURES..duplicateNamedCaptureGroupsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/duplicateNamedCaptureGroups0:)
69 ) {
70 throw new Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#(
71 `The 'runtime' option must be the same for ` +
72 `'@babel/plugin-transform-named-capturing-groups-regex' and ` +
73 `'@babel/plugin-proposal-duplicate-named-capturing-groups-regex'.`,
74 );
75 }
76 // TODO(Babel 8): Remove this check and always set it.
77 // It's necessary because in Babel 7 we allow multiple copies of
78 // transform-named-capturing-groups-regex with conflicting 'runtime' options.
79 if (feature === "namedCaptureGroups") {
80 if (!runtime || !file.hasscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#has().(runtimeKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/runtimeKey.)) file.setscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#set().(runtimeKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/runtimeKey., runtime);
81 } else {
82 file.setscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#set().(runtimeKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/runtimeKey., runtime);
83 }
84 }
85
86 if (!file.hasscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#has().(versionKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/versionKey.) || file.getscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#get().(versionKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/versionKey.) < versionscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/version.) {
87 file.setscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#set().(versionKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/versionKey., versionscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/version.);
88 }
89 },
90
91 visitorscip-typescript npm @babel/core 7.20.12 src/config/validation/`plugins.ts`/PluginObject#typeLiteral0:visitor.: {
92 RegExpLiteral(path) {
93 const { nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. } = path;
94 const { filescip-typescript npm @babel/core 7.20.12 src/transformation/`plugin-pass.ts`/PluginPass#file. } = this;
95 const features = file.getscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#get().(featuresKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/featuresKey.);
96 const runtime = file.getscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#get().(runtimeKeyscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`features.ts`/runtimeKey.) ?? true;
97
98 const regexpuOptions = generateRegexpuOptionsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/generateRegexpuOptions().(node.patternscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/RegExpLiteral#pattern., features);
99 if (canSkipRegexpuscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/canSkipRegexpu().(node, regexpuOptions)) {
100 return;
101 }
102
103 const namedCaptureGroups: Recordscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Record#<string, number | number[]> = {
104 __proto__scip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/__proto__0:: null,
105 };
106 if (regexpuOptions.namedGroupsscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:namedGroups. === "transform") {
107 regexpuOptions.onNamedGroupscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:onNamedGroup. = (name, index) => {
108 const prev = namedCaptureGroups[name];
109 if (typeof prev === "number") {
110 namedCaptureGroups[name] = [prev, index];
111 } else if (Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#.isArrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ArrayConstructor#isArray().(prev)) {
112 prev.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(index);
113 } else {
114 namedCaptureGroups[name] = index;
115 }
116 };
117 }
118
119 node.patternscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/RegExpLiteral#pattern. = rewritePatternscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/rewritePattern().(node.patternscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/RegExpLiteral#pattern., node.flagsscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/RegExpLiteral#flags., regexpuOptions);
120
121 if (
122 regexpuOptions.namedGroupsscip-typescript npm babel 7.20.15 lib/`regexpu-core.d.ts`/`"regexpu-core"`/RegexpuOptions#typeLiteral22:namedGroups. === "transform" &&
123 Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.keysscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ObjectConstructor#keys().(namedCaptureGroups).lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. > 0 &&
124 runtime &&
125 !isRegExpTestscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/isRegExpTest().(path)
126 ) {
127 const call = tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.callExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/callExpression().(this.addHelperscip-typescript npm @babel/core 7.20.12 src/transformation/`plugin-pass.ts`/PluginPass#addHelper().("wrapRegExp"), [
128 node,
129 tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.valueToNode(namedCaptureGroups),
130 ]);
131 annotateAsPurescip-typescript npm @babel/helper-annotate-as-pure 7.18.6 src/`index.ts`/annotateAsPure().(call);
132
133 path.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(call);
134 }
135
136 node.flagsscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/RegExpLiteral#flags. = transformFlagsscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`util.ts`/transformFlags().(regexpuOptions, node.flagsscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/RegExpLiteral#flags.);
137 },
138 },
139 };
140 }
141
142 function isRegExpTestscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/isRegExpTest().(pathscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/isRegExpTest().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<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#>) {
143 return (
144 pathscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/isRegExpTest().(path).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isMemberExpression().({
145 objectscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/object0:: pathscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/isRegExpTest().(path).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.,
146 computedscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/computed0:: false,
147 }) && pathscip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/isRegExpTest().(path).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..get("property").isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().({ namescip-typescript npm @babel/helper-create-regexp-features-plugin 7.20.5 src/`index.ts`/name0:: "test" })
148 );
149 }