react-code-locator 0.1.16 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +54 -279
  2. package/dist/esbuild.cjs +7025 -295
  3. package/dist/esbuild.cjs.map +1 -1
  4. package/dist/esbuild.d.cts +38 -6
  5. package/dist/esbuild.d.ts +38 -6
  6. package/dist/esbuild.js +7025 -295
  7. package/dist/esbuild.js.map +1 -1
  8. package/dist/index.cjs +7132 -16
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +7 -0
  11. package/dist/index.d.ts +7 -0
  12. package/dist/index.js +7126 -15
  13. package/dist/index.js.map +1 -1
  14. package/dist/swc.cjs +7020 -293
  15. package/dist/swc.cjs.map +1 -1
  16. package/dist/swc.d.cts +43 -19
  17. package/dist/swc.d.ts +43 -19
  18. package/dist/swc.js +7020 -293
  19. package/dist/swc.js.map +1 -1
  20. package/dist/transform-CXh-m5Ez.d.cts +12 -0
  21. package/dist/transform-CXh-m5Ez.d.ts +12 -0
  22. package/dist/unplugin.cjs +6850 -8
  23. package/dist/unplugin.cjs.map +1 -1
  24. package/dist/unplugin.d.cts +4 -13
  25. package/dist/unplugin.d.ts +4 -13
  26. package/dist/unplugin.js +6848 -6
  27. package/dist/unplugin.js.map +1 -1
  28. package/dist/vite.cjs +7029 -304
  29. package/dist/vite.cjs.map +1 -1
  30. package/dist/vite.d.cts +39 -14
  31. package/dist/vite.d.ts +39 -14
  32. package/dist/vite.js +7029 -303
  33. package/dist/vite.js.map +1 -1
  34. package/package.json +5 -51
  35. package/dist/babel.cjs +0 -370
  36. package/dist/babel.cjs.map +0 -1
  37. package/dist/babel.d.cts +0 -13
  38. package/dist/babel.d.ts +0 -13
  39. package/dist/babel.js +0 -341
  40. package/dist/babel.js.map +0 -1
  41. package/dist/babelInjectComponentSource.cjs +0 -342
  42. package/dist/babelInjectComponentSource.cjs.map +0 -1
  43. package/dist/babelInjectComponentSource.d.cts +0 -15
  44. package/dist/babelInjectComponentSource.d.ts +0 -15
  45. package/dist/babelInjectComponentSource.js +0 -317
  46. package/dist/babelInjectComponentSource.js.map +0 -1
  47. package/dist/sourceAdapter-dPr5CgLi.d.cts +0 -14
  48. package/dist/sourceAdapter-dPr5CgLi.d.ts +0 -14
  49. package/dist/webpack.cjs +0 -68
  50. package/dist/webpack.cjs.map +0 -1
  51. package/dist/webpack.d.cts +0 -2
  52. package/dist/webpack.d.ts +0 -2
  53. package/dist/webpack.js +0 -82
  54. package/dist/webpack.js.map +0 -1
  55. package/dist/webpackRuntimeEntry.cjs +0 -375
  56. package/dist/webpackRuntimeEntry.cjs.map +0 -1
  57. package/dist/webpackRuntimeEntry.d.cts +0 -2
  58. package/dist/webpackRuntimeEntry.d.ts +0 -2
  59. package/dist/webpackRuntimeEntry.js +0 -373
  60. package/dist/webpackRuntimeEntry.js.map +0 -1
@@ -1,317 +0,0 @@
1
- // src/babelInjectComponentSource.ts
2
- import { types as t } from "@babel/core";
3
-
4
- // src/constants.ts
5
- var SOURCE_PROP = "__componentSourceLoc";
6
- var JSX_SOURCE_REGISTRY_SYMBOL = "react-code-locator.jsxSourceRegistry";
7
-
8
- // src/sourceMetadata.ts
9
- function normalizeSlashes(value) {
10
- return value.replace(/\\/g, "/");
11
- }
12
- function trimTrailingSlash(value) {
13
- return value.replace(/\/+$/, "");
14
- }
15
- function splitPathSegments(value) {
16
- return normalizeSlashes(value).split("/").filter(Boolean);
17
- }
18
- function computeRelativePath(fromPath, toPath) {
19
- const fromSegments = splitPathSegments(fromPath);
20
- const toSegments = splitPathSegments(toPath);
21
- let sharedIndex = 0;
22
- while (sharedIndex < fromSegments.length && sharedIndex < toSegments.length && fromSegments[sharedIndex] === toSegments[sharedIndex]) {
23
- sharedIndex += 1;
24
- }
25
- const upSegments = new Array(Math.max(0, fromSegments.length - sharedIndex)).fill("..");
26
- const downSegments = toSegments.slice(sharedIndex);
27
- const relativeSegments = [...upSegments, ...downSegments];
28
- return relativeSegments.length > 0 ? relativeSegments.join("/") : ".";
29
- }
30
- function normalizeProjectRoot(projectRoot) {
31
- if (projectRoot) {
32
- return trimTrailingSlash(normalizeSlashes(projectRoot));
33
- }
34
- return "";
35
- }
36
- function toRelativeSource(filename, loc, projectRoot) {
37
- if (!filename || !loc) {
38
- return null;
39
- }
40
- const root = normalizeProjectRoot(projectRoot);
41
- const normalizedFilename = normalizeSlashes(filename);
42
- const relPath = root && normalizedFilename.startsWith(`${root}/`) ? normalizedFilename.slice(root.length + 1) : root ? computeRelativePath(root, normalizedFilename) : normalizedFilename;
43
- return `${relPath}:${loc.line}:${loc.column + 1}`;
44
- }
45
-
46
- // src/babelInjectComponentSource.ts
47
- function isComponentName(name) {
48
- return /^[A-Z]/.test(name);
49
- }
50
- function isElementFactoryIdentifier(name) {
51
- return name === "jsx" || name === "jsxs" || name === "jsxDEV" || name === "_jsx" || name === "_jsxs" || name === "_jsxDEV" || name === "createElement";
52
- }
53
- function isReactElementFactoryCall(pathNode) {
54
- const callee = pathNode.node.callee;
55
- if (t.isIdentifier(callee)) {
56
- return isElementFactoryIdentifier(callee.name);
57
- }
58
- return t.isMemberExpression(callee) && t.isIdentifier(callee.object, { name: "React" }) && t.isIdentifier(callee.property, { name: "createElement" });
59
- }
60
- function isSupportedComponentInit(node) {
61
- if (!node) {
62
- return false;
63
- }
64
- if (t.isArrowFunctionExpression(node) || t.isFunctionExpression(node)) {
65
- return true;
66
- }
67
- if (!t.isCallExpression(node)) {
68
- return false;
69
- }
70
- if (t.isIdentifier(node.callee) && (node.callee.name === "memo" || node.callee.name === "forwardRef")) {
71
- return true;
72
- }
73
- return t.isMemberExpression(node.callee) && t.isIdentifier(node.callee.object, { name: "React" }) && t.isIdentifier(node.callee.property) && (node.callee.property.name === "memo" || node.callee.property.name === "forwardRef");
74
- }
75
- function getSourceValue(state, loc, projectRoot) {
76
- const filename = state.file?.opts?.filename;
77
- if (!filename || !loc) {
78
- return null;
79
- }
80
- return toRelativeSource(filename, loc, projectRoot);
81
- }
82
- function buildAssignment(name, sourceValue) {
83
- return t.expressionStatement(
84
- t.assignmentExpression(
85
- "=",
86
- t.memberExpression(t.identifier(name), t.identifier(SOURCE_PROP)),
87
- t.stringLiteral(sourceValue)
88
- )
89
- );
90
- }
91
- function buildElementSourceHelper() {
92
- return t.functionDeclaration(
93
- t.identifier("_markReactElementSource"),
94
- [t.identifier("element"), t.identifier("source")],
95
- t.blockStatement([
96
- t.variableDeclaration("const", [
97
- t.variableDeclarator(
98
- t.identifier("registryKey"),
99
- t.callExpression(
100
- t.memberExpression(t.identifier("Symbol"), t.identifier("for")),
101
- [t.stringLiteral(JSX_SOURCE_REGISTRY_SYMBOL)]
102
- )
103
- )
104
- ]),
105
- t.variableDeclaration("let", [
106
- t.variableDeclarator(
107
- t.identifier("registry"),
108
- t.memberExpression(t.identifier("globalThis"), t.identifier("registryKey"), true)
109
- )
110
- ]),
111
- t.ifStatement(
112
- t.unaryExpression(
113
- "!",
114
- t.binaryExpression("instanceof", t.identifier("registry"), t.identifier("WeakMap"))
115
- ),
116
- t.blockStatement([
117
- t.expressionStatement(
118
- t.assignmentExpression(
119
- "=",
120
- t.identifier("registry"),
121
- t.assignmentExpression(
122
- "=",
123
- t.memberExpression(t.identifier("globalThis"), t.identifier("registryKey"), true),
124
- t.newExpression(t.identifier("WeakMap"), [])
125
- )
126
- )
127
- )
128
- ])
129
- ),
130
- t.ifStatement(
131
- t.logicalExpression(
132
- "&&",
133
- t.identifier("element"),
134
- t.logicalExpression(
135
- "&&",
136
- t.binaryExpression("===", t.unaryExpression("typeof", t.identifier("element")), t.stringLiteral("object")),
137
- t.binaryExpression(
138
- "===",
139
- t.unaryExpression("typeof", t.memberExpression(t.identifier("element"), t.identifier("props"))),
140
- t.stringLiteral("object")
141
- )
142
- )
143
- ),
144
- t.blockStatement([
145
- t.expressionStatement(
146
- t.callExpression(
147
- t.memberExpression(t.identifier("registry"), t.identifier("set")),
148
- [t.memberExpression(t.identifier("element"), t.identifier("props")), t.identifier("source")]
149
- )
150
- )
151
- ])
152
- ),
153
- t.returnStatement(t.identifier("element"))
154
- ])
155
- );
156
- }
157
- function ensureElementSourceHelper(programPath, state) {
158
- if (state.injectedIntrinsicHelper) {
159
- return;
160
- }
161
- const alreadyExists = programPath.node.body.some(
162
- (node) => t.isFunctionDeclaration(node) && t.isIdentifier(node.id, { name: "_markReactElementSource" })
163
- );
164
- if (!alreadyExists) {
165
- programPath.unshiftContainer("body", buildElementSourceHelper());
166
- }
167
- state.injectedIntrinsicHelper = true;
168
- }
169
- function visitDeclaration(declarationPath, insertAfterPath, state, seen, projectRoot) {
170
- if (declarationPath.isFunctionDeclaration() || declarationPath.isClassDeclaration()) {
171
- const name = declarationPath.node.id?.name;
172
- if (!name || !isComponentName(name) || seen.has(name)) {
173
- return;
174
- }
175
- const sourceValue = getSourceValue(
176
- state,
177
- declarationPath.node.loc?.start,
178
- projectRoot
179
- );
180
- if (!sourceValue) {
181
- return;
182
- }
183
- seen.add(name);
184
- insertAfterPath.insertAfter(buildAssignment(name, sourceValue));
185
- return;
186
- }
187
- if (!declarationPath.isVariableDeclaration()) {
188
- return;
189
- }
190
- const assignments = declarationPath.node.declarations.flatMap(
191
- (declarator) => {
192
- if (!t.isIdentifier(declarator.id) || !isComponentName(declarator.id.name) || seen.has(declarator.id.name)) {
193
- return [];
194
- }
195
- if (!declarator.init) {
196
- return [];
197
- }
198
- if (!isSupportedComponentInit(declarator.init)) {
199
- return [];
200
- }
201
- const sourceValue = getSourceValue(
202
- state,
203
- declarator.loc?.start ?? declarator.init.loc?.start,
204
- projectRoot
205
- );
206
- if (!sourceValue) {
207
- return [];
208
- }
209
- seen.add(declarator.id.name);
210
- return [buildAssignment(declarator.id.name, sourceValue)];
211
- }
212
- );
213
- if (assignments.length > 0) {
214
- insertAfterPath.insertAfter(assignments);
215
- }
216
- }
217
- function babelInjectComponentSource(options = {}) {
218
- const {
219
- injectJsxSource = true,
220
- injectComponentSource = true,
221
- projectRoot
222
- } = options;
223
- return {
224
- name: "babel-inject-component-source",
225
- visitor: {
226
- CallExpression(pathNode, state) {
227
- if (!injectJsxSource) {
228
- return;
229
- }
230
- if (!isReactElementFactoryCall(pathNode)) {
231
- return;
232
- }
233
- if (pathNode.parentPath.isCallExpression() && t.isIdentifier(pathNode.parentPath.node.callee, {
234
- name: "_markReactElementSource"
235
- })) {
236
- return;
237
- }
238
- const sourceValue = getSourceValue(
239
- state,
240
- pathNode.node.loc?.start,
241
- projectRoot
242
- );
243
- if (!sourceValue) {
244
- return;
245
- }
246
- const programPath = pathNode.findParent((parent) => parent.isProgram());
247
- if (!programPath || !programPath.isProgram()) {
248
- return;
249
- }
250
- ensureElementSourceHelper(programPath, state);
251
- pathNode.replaceWith(
252
- t.callExpression(t.identifier("_markReactElementSource"), [
253
- pathNode.node,
254
- t.stringLiteral(sourceValue)
255
- ])
256
- );
257
- pathNode.skip();
258
- },
259
- JSXElement: {
260
- exit(pathNode, state) {
261
- if (!injectJsxSource) {
262
- return;
263
- }
264
- if (pathNode.parentPath.isCallExpression() && t.isIdentifier(pathNode.parentPath.node.callee, { name: "_markReactElementSource" })) {
265
- return;
266
- }
267
- const sourceValue = getSourceValue(
268
- state,
269
- pathNode.node.openingElement.loc?.start,
270
- projectRoot
271
- );
272
- if (!sourceValue) {
273
- return;
274
- }
275
- const programPath = pathNode.findParent((parent) => parent.isProgram());
276
- if (!programPath || !programPath.isProgram()) {
277
- return;
278
- }
279
- ensureElementSourceHelper(programPath, state);
280
- const wrappedNode = t.callExpression(t.identifier("_markReactElementSource"), [
281
- pathNode.node,
282
- t.stringLiteral(sourceValue)
283
- ]);
284
- if (pathNode.parentPath.isJSXElement() || pathNode.parentPath.isJSXFragment()) {
285
- pathNode.replaceWith(t.jsxExpressionContainer(wrappedNode));
286
- return;
287
- }
288
- if (pathNode.parentPath.isJSXExpressionContainer()) {
289
- pathNode.parentPath.replaceWith(t.jsxExpressionContainer(wrappedNode));
290
- return;
291
- }
292
- pathNode.replaceWith(wrappedNode);
293
- }
294
- },
295
- Program(programPath, state) {
296
- if (!injectComponentSource) {
297
- return;
298
- }
299
- const seen = /* @__PURE__ */ new Set();
300
- for (const childPath of programPath.get("body")) {
301
- if (childPath.isExportNamedDeclaration() || childPath.isExportDefaultDeclaration()) {
302
- const declarationPath = childPath.get("declaration");
303
- if (!Array.isArray(declarationPath) && declarationPath.node) {
304
- visitDeclaration(declarationPath, childPath, state, seen, projectRoot);
305
- }
306
- continue;
307
- }
308
- visitDeclaration(childPath, childPath, state, seen, projectRoot);
309
- }
310
- }
311
- }
312
- };
313
- }
314
- export {
315
- babelInjectComponentSource
316
- };
317
- //# sourceMappingURL=babelInjectComponentSource.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/babelInjectComponentSource.ts","../src/constants.ts","../src/sourceMetadata.ts"],"sourcesContent":["import { types as t, type NodePath, type PluginObj } from \"@babel/core\";\nimport { JSX_SOURCE_REGISTRY_SYMBOL, SOURCE_PROP } from \"./constants\";\nimport type { SourceInjectionOptions } from \"./sourceAdapter\";\nimport { toRelativeSource } from \"./sourceMetadata\";\n\nexport type BabelInjectComponentSourceOptions = SourceInjectionOptions;\n\ntype BabelState = {\n file?: {\n opts?: {\n filename?: string;\n };\n };\n injectedIntrinsicHelper?: boolean;\n};\n\nfunction isComponentName(name: string) {\n return /^[A-Z]/.test(name);\n}\n\nfunction isElementFactoryIdentifier(name: string) {\n return (\n name === \"jsx\" ||\n name === \"jsxs\" ||\n name === \"jsxDEV\" ||\n name === \"_jsx\" ||\n name === \"_jsxs\" ||\n name === \"_jsxDEV\" ||\n name === \"createElement\"\n );\n}\n\nfunction isReactElementFactoryCall(pathNode: NodePath<t.CallExpression>) {\n const callee = pathNode.node.callee;\n\n if (t.isIdentifier(callee)) {\n return isElementFactoryIdentifier(callee.name);\n }\n\n return (\n t.isMemberExpression(callee) &&\n t.isIdentifier(callee.object, { name: \"React\" }) &&\n t.isIdentifier(callee.property, { name: \"createElement\" })\n );\n}\n\nfunction isSupportedComponentInit(\n node: t.Expression | null | undefined,\n): boolean {\n if (!node) {\n return false;\n }\n\n if (t.isArrowFunctionExpression(node) || t.isFunctionExpression(node)) {\n return true;\n }\n\n if (!t.isCallExpression(node)) {\n return false;\n }\n\n if (\n t.isIdentifier(node.callee) &&\n (node.callee.name === \"memo\" || node.callee.name === \"forwardRef\")\n ) {\n return true;\n }\n\n return (\n t.isMemberExpression(node.callee) &&\n t.isIdentifier(node.callee.object, { name: \"React\" }) &&\n t.isIdentifier(node.callee.property) &&\n (node.callee.property.name === \"memo\" ||\n node.callee.property.name === \"forwardRef\")\n );\n}\n\nfunction getSourceValue(\n state: BabelState,\n loc: { line: number; column: number } | null | undefined,\n projectRoot?: string,\n) {\n const filename = state.file?.opts?.filename;\n if (!filename || !loc) {\n return null;\n }\n\n return toRelativeSource(filename, loc, projectRoot);\n}\n\nfunction buildAssignment(name: string, sourceValue: string) {\n return t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.memberExpression(t.identifier(name), t.identifier(SOURCE_PROP)),\n t.stringLiteral(sourceValue),\n ),\n );\n}\n\nfunction buildElementSourceHelper() {\n return t.functionDeclaration(\n t.identifier(\"_markReactElementSource\"),\n [t.identifier(\"element\"), t.identifier(\"source\")],\n t.blockStatement([\n t.variableDeclaration(\"const\", [\n t.variableDeclarator(\n t.identifier(\"registryKey\"),\n t.callExpression(\n t.memberExpression(t.identifier(\"Symbol\"), t.identifier(\"for\")),\n [t.stringLiteral(JSX_SOURCE_REGISTRY_SYMBOL)],\n ),\n ),\n ]),\n t.variableDeclaration(\"let\", [\n t.variableDeclarator(\n t.identifier(\"registry\"),\n t.memberExpression(t.identifier(\"globalThis\"), t.identifier(\"registryKey\"), true),\n ),\n ]),\n t.ifStatement(\n t.unaryExpression(\n \"!\",\n t.binaryExpression(\"instanceof\", t.identifier(\"registry\"), t.identifier(\"WeakMap\")),\n ),\n t.blockStatement([\n t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.identifier(\"registry\"),\n t.assignmentExpression(\n \"=\",\n t.memberExpression(t.identifier(\"globalThis\"), t.identifier(\"registryKey\"), true),\n t.newExpression(t.identifier(\"WeakMap\"), []),\n ),\n ),\n ),\n ]),\n ),\n t.ifStatement(\n t.logicalExpression(\n \"&&\",\n t.identifier(\"element\"),\n t.logicalExpression(\n \"&&\",\n t.binaryExpression(\"===\", t.unaryExpression(\"typeof\", t.identifier(\"element\")), t.stringLiteral(\"object\")),\n t.binaryExpression(\n \"===\",\n t.unaryExpression(\"typeof\", t.memberExpression(t.identifier(\"element\"), t.identifier(\"props\"))),\n t.stringLiteral(\"object\"),\n ),\n ),\n ),\n t.blockStatement([\n t.expressionStatement(\n t.callExpression(\n t.memberExpression(t.identifier(\"registry\"), t.identifier(\"set\")),\n [t.memberExpression(t.identifier(\"element\"), t.identifier(\"props\")), t.identifier(\"source\")],\n ),\n ),\n ]),\n ),\n t.returnStatement(t.identifier(\"element\")),\n ]),\n );\n}\n\nfunction ensureElementSourceHelper(programPath: NodePath<t.Program>, state: BabelState) {\n if (state.injectedIntrinsicHelper) {\n return;\n }\n\n const alreadyExists = programPath.node.body.some(\n (node: t.Statement) =>\n t.isFunctionDeclaration(node) && t.isIdentifier(node.id, { name: \"_markReactElementSource\" }),\n );\n if (!alreadyExists) {\n programPath.unshiftContainer(\"body\", buildElementSourceHelper());\n }\n\n state.injectedIntrinsicHelper = true;\n}\n\nfunction visitDeclaration(\n declarationPath: NodePath,\n insertAfterPath: NodePath,\n state: BabelState,\n seen: Set<string>,\n projectRoot?: string,\n) {\n if (\n declarationPath.isFunctionDeclaration() ||\n declarationPath.isClassDeclaration()\n ) {\n const name = declarationPath.node.id?.name;\n if (!name || !isComponentName(name) || seen.has(name)) {\n return;\n }\n\n const sourceValue = getSourceValue(\n state,\n declarationPath.node.loc?.start,\n projectRoot,\n );\n if (!sourceValue) {\n return;\n }\n\n seen.add(name);\n insertAfterPath.insertAfter(buildAssignment(name, sourceValue));\n return;\n }\n\n if (!declarationPath.isVariableDeclaration()) {\n return;\n }\n\n const assignments = declarationPath.node.declarations.flatMap(\n (declarator: t.VariableDeclarator) => {\n if (\n !t.isIdentifier(declarator.id) ||\n !isComponentName(declarator.id.name) ||\n seen.has(declarator.id.name)\n ) {\n return [];\n }\n\n if (!declarator.init) {\n return [];\n }\n\n if (!isSupportedComponentInit(declarator.init)) {\n return [];\n }\n\n const sourceValue = getSourceValue(\n state,\n declarator.loc?.start ?? declarator.init.loc?.start,\n projectRoot,\n );\n if (!sourceValue) {\n return [];\n }\n\n seen.add(declarator.id.name);\n return [buildAssignment(declarator.id.name, sourceValue)];\n },\n );\n\n if (assignments.length > 0) {\n insertAfterPath.insertAfter(assignments);\n }\n}\n\nexport function babelInjectComponentSource(\n options: BabelInjectComponentSourceOptions = {},\n): PluginObj<BabelState> {\n const {\n injectJsxSource = true,\n injectComponentSource = true,\n projectRoot,\n } = options;\n\n return {\n name: \"babel-inject-component-source\",\n visitor: {\n CallExpression(pathNode: NodePath<t.CallExpression>, state: BabelState) {\n if (!injectJsxSource) {\n return;\n }\n\n if (!isReactElementFactoryCall(pathNode)) {\n return;\n }\n\n if (\n pathNode.parentPath.isCallExpression() &&\n t.isIdentifier(pathNode.parentPath.node.callee, {\n name: \"_markReactElementSource\",\n })\n ) {\n return;\n }\n\n const sourceValue = getSourceValue(\n state,\n pathNode.node.loc?.start,\n projectRoot,\n );\n if (!sourceValue) {\n return;\n }\n\n const programPath = pathNode.findParent((parent: NodePath) => parent.isProgram());\n if (!programPath || !programPath.isProgram()) {\n return;\n }\n\n ensureElementSourceHelper(programPath, state);\n pathNode.replaceWith(\n t.callExpression(t.identifier(\"_markReactElementSource\"), [\n pathNode.node,\n t.stringLiteral(sourceValue),\n ]),\n );\n pathNode.skip();\n },\n JSXElement: {\n exit(pathNode: NodePath<t.JSXElement>, state: BabelState) {\n if (!injectJsxSource) {\n return;\n }\n\n if (\n pathNode.parentPath.isCallExpression() &&\n t.isIdentifier(pathNode.parentPath.node.callee, { name: \"_markReactElementSource\" })\n ) {\n return;\n }\n\n const sourceValue = getSourceValue(\n state,\n pathNode.node.openingElement.loc?.start,\n projectRoot,\n );\n if (!sourceValue) {\n return;\n }\n\n const programPath = pathNode.findParent((parent: NodePath) => parent.isProgram());\n if (!programPath || !programPath.isProgram()) {\n return;\n }\n\n ensureElementSourceHelper(programPath, state);\n\n const wrappedNode = t.callExpression(t.identifier(\"_markReactElementSource\"), [\n pathNode.node,\n t.stringLiteral(sourceValue),\n ]);\n\n if (pathNode.parentPath.isJSXElement() || pathNode.parentPath.isJSXFragment()) {\n pathNode.replaceWith(t.jsxExpressionContainer(wrappedNode));\n return;\n }\n\n if (pathNode.parentPath.isJSXExpressionContainer()) {\n pathNode.parentPath.replaceWith(t.jsxExpressionContainer(wrappedNode));\n return;\n }\n\n pathNode.replaceWith(wrappedNode);\n },\n },\n Program(programPath: NodePath<t.Program>, state: BabelState) {\n if (!injectComponentSource) {\n return;\n }\n\n const seen = new Set<string>();\n\n for (const childPath of programPath.get(\"body\")) {\n if (\n childPath.isExportNamedDeclaration() ||\n childPath.isExportDefaultDeclaration()\n ) {\n const declarationPath = childPath.get(\"declaration\");\n if (!Array.isArray(declarationPath) && declarationPath.node) {\n visitDeclaration(declarationPath, childPath, state, seen, projectRoot);\n }\n continue;\n }\n\n visitDeclaration(childPath, childPath, state, seen, projectRoot);\n }\n },\n },\n };\n}\n","export const SOURCE_PROP = \"__componentSourceLoc\";\nexport const JSX_SOURCE_PROP = \"$componentSourceLoc\";\nexport const JSX_SOURCE_REGISTRY_SYMBOL = \"react-code-locator.jsxSourceRegistry\";\n","export type SourceLocation = {\n line: number;\n column: number;\n};\n\nfunction normalizeSlashes(value: string) {\n return value.replace(/\\\\/g, \"/\");\n}\n\nfunction trimTrailingSlash(value: string) {\n return value.replace(/\\/+$/, \"\");\n}\n\nfunction splitPathSegments(value: string) {\n return normalizeSlashes(value).split(\"/\").filter(Boolean);\n}\n\nfunction computeRelativePath(fromPath: string, toPath: string) {\n const fromSegments = splitPathSegments(fromPath);\n const toSegments = splitPathSegments(toPath);\n\n let sharedIndex = 0;\n while (\n sharedIndex < fromSegments.length &&\n sharedIndex < toSegments.length &&\n fromSegments[sharedIndex] === toSegments[sharedIndex]\n ) {\n sharedIndex += 1;\n }\n\n const upSegments = new Array(Math.max(0, fromSegments.length - sharedIndex)).fill(\"..\");\n const downSegments = toSegments.slice(sharedIndex);\n const relativeSegments = [...upSegments, ...downSegments];\n return relativeSegments.length > 0 ? relativeSegments.join(\"/\") : \".\";\n}\n\nexport function normalizeProjectRoot(projectRoot?: string) {\n if (projectRoot) {\n return trimTrailingSlash(normalizeSlashes(projectRoot));\n }\n return \"\";\n}\n\nexport function toRelativeSource(\n filename: string | undefined,\n loc: SourceLocation | null | undefined,\n projectRoot?: string,\n) {\n if (!filename || !loc) {\n return null;\n }\n\n const root = normalizeProjectRoot(projectRoot);\n const normalizedFilename = normalizeSlashes(filename);\n const relPath =\n root && normalizedFilename.startsWith(`${root}/`)\n ? normalizedFilename.slice(root.length + 1)\n : root\n ? computeRelativePath(root, normalizedFilename)\n : normalizedFilename;\n return `${relPath}:${loc.line}:${loc.column + 1}`;\n}\n\nexport function getSourceFile(source: string | null) {\n if (!source) {\n return null;\n }\n\n const match = source.match(/^(.*):\\d+:\\d+$/);\n return match?.[1] ?? null;\n}\n\nexport function isProjectLocalFile(filename: string | undefined, projectRoot?: string) {\n if (!filename) {\n return false;\n }\n\n const root = normalizeProjectRoot(projectRoot);\n const normalizedFilename = normalizeSlashes(filename);\n\n if (!root) {\n return (\n !normalizedFilename.startsWith(\"../\") &&\n !normalizedFilename.startsWith(\"/\") &&\n !/^[A-Za-z]:\\//.test(normalizedFilename)\n );\n }\n\n if (normalizedFilename.startsWith(`${root}/`) || normalizedFilename === root) {\n return true;\n }\n\n const relativePath = computeRelativePath(root, normalizedFilename);\n return !relativePath.startsWith(\"../\");\n}\n\nexport function isExternalToProjectRoot(filename: string | undefined, projectRoot?: string) {\n return !isProjectLocalFile(filename, projectRoot);\n}\n\nexport function isProjectLocalSource(source: string, projectRoot?: string) {\n const file = getSourceFile(source);\n return isProjectLocalFile(file ?? undefined, projectRoot);\n}\n"],"mappings":";AAAA,SAAS,SAAS,SAAwC;;;ACAnD,IAAM,cAAc;AAEpB,IAAM,6BAA6B;;;ACG1C,SAAS,iBAAiB,OAAe;AACvC,SAAO,MAAM,QAAQ,OAAO,GAAG;AACjC;AAEA,SAAS,kBAAkB,OAAe;AACxC,SAAO,MAAM,QAAQ,QAAQ,EAAE;AACjC;AAEA,SAAS,kBAAkB,OAAe;AACxC,SAAO,iBAAiB,KAAK,EAAE,MAAM,GAAG,EAAE,OAAO,OAAO;AAC1D;AAEA,SAAS,oBAAoB,UAAkB,QAAgB;AAC7D,QAAM,eAAe,kBAAkB,QAAQ;AAC/C,QAAM,aAAa,kBAAkB,MAAM;AAE3C,MAAI,cAAc;AAClB,SACE,cAAc,aAAa,UAC3B,cAAc,WAAW,UACzB,aAAa,WAAW,MAAM,WAAW,WAAW,GACpD;AACA,mBAAe;AAAA,EACjB;AAEA,QAAM,aAAa,IAAI,MAAM,KAAK,IAAI,GAAG,aAAa,SAAS,WAAW,CAAC,EAAE,KAAK,IAAI;AACtF,QAAM,eAAe,WAAW,MAAM,WAAW;AACjD,QAAM,mBAAmB,CAAC,GAAG,YAAY,GAAG,YAAY;AACxD,SAAO,iBAAiB,SAAS,IAAI,iBAAiB,KAAK,GAAG,IAAI;AACpE;AAEO,SAAS,qBAAqB,aAAsB;AACzD,MAAI,aAAa;AACf,WAAO,kBAAkB,iBAAiB,WAAW,CAAC;AAAA,EACxD;AACA,SAAO;AACT;AAEO,SAAS,iBACd,UACA,KACA,aACA;AACA,MAAI,CAAC,YAAY,CAAC,KAAK;AACrB,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,qBAAqB,WAAW;AAC7C,QAAM,qBAAqB,iBAAiB,QAAQ;AACpD,QAAM,UACJ,QAAQ,mBAAmB,WAAW,GAAG,I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AAAA,UACF;AAEA,gBAAM,cAAc,SAAS,WAAW,CAAC,WAAqB,OAAO,UAAU,CAAC;AAChF,cAAI,CAAC,eAAe,CAAC,YAAY,UAAU,GAAG;AAC5C;AAAA,UACF;AAEA,oCAA0B,aAAa,KAAK;AAE5C,gBAAM,cAAc,EAAE,eAAe,EAAE,WAAW,yBAAyB,GAAG;AAAA,YAC5E,SAAS;AAAA,YACT,EAAE,cAAc,WAAW;AAAA,UAC7B,CAAC;AAED,cAAI,SAAS,WAAW,aAAa,KAAK,SAAS,WAAW,cAAc,GAAG;AAC7E,qBAAS,YAAY,EAAE,uBAAuB,WAAW,CAAC;AAC1D;AAAA,UACF;AAEA,cAAI,SAAS,WAAW,yBAAyB,GAAG;AAClD,qBAAS,WAAW,YAAY,EAAE,uBAAuB,WAAW,CAAC;AACrE;AAAA,UACF;AAEA,mBAAS,YAAY,WAAW;AAAA,QAClC;AAAA,MACF;AAAA,MACA,QAAQ,aAAkC,OAAmB;AAC3D,YAAI,CAAC,uBAAuB;AAC1B;AAAA,QACF;AAEA,cAAM,OAAO,oBAAI,IAAY;AAE7B,mBAAW,aAAa,YAAY,IAAI,MAAM,GAAG;AAC/C,cACE,UAAU,yBAAyB,KACnC,UAAU,2BAA2B,GACrC;AACA,kBAAM,kBAAkB,UAAU,IAAI,aAAa;AACnD,gBAAI,CAAC,MAAM,QAAQ,eAAe,KAAK,gBAAgB,MAAM;AAC3D,+BAAiB,iBAAiB,WAAW,OAAO,MAAM,WAAW;AAAA,YACvE;AACA;AAAA,UACF;AAEA,2BAAiB,WAAW,WAAW,OAAO,MAAM,WAAW;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,14 +0,0 @@
1
- type SourceInjectionOptions = {
2
- injectJsxSource?: boolean;
3
- injectComponentSource?: boolean;
4
- projectRoot?: string;
5
- };
6
- type SourceAdapterKind = "babel" | "vite" | "esbuild" | "swc";
7
- type SourceAdapterDescriptor<TConfig = unknown, TOptions = SourceInjectionOptions> = {
8
- kind: SourceAdapterKind;
9
- name: string;
10
- options: TOptions;
11
- config: TConfig;
12
- };
13
-
14
- export type { SourceAdapterDescriptor as S, SourceInjectionOptions as a, SourceAdapterKind as b };
@@ -1,14 +0,0 @@
1
- type SourceInjectionOptions = {
2
- injectJsxSource?: boolean;
3
- injectComponentSource?: boolean;
4
- projectRoot?: string;
5
- };
6
- type SourceAdapterKind = "babel" | "vite" | "esbuild" | "swc";
7
- type SourceAdapterDescriptor<TConfig = unknown, TOptions = SourceInjectionOptions> = {
8
- kind: SourceAdapterKind;
9
- name: string;
10
- options: TOptions;
11
- config: TConfig;
12
- };
13
-
14
- export type { SourceAdapterDescriptor as S, SourceInjectionOptions as a, SourceAdapterKind as b };
package/dist/webpack.cjs DELETED
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- // src/webpack.cts
4
- var path = require("path");
5
- function injectEntry(entry, runtimeEntry) {
6
- if (!entry) {
7
- return entry;
8
- }
9
- if (typeof entry === "string") {
10
- return [runtimeEntry, entry];
11
- }
12
- if (Array.isArray(entry)) {
13
- return [runtimeEntry, ...entry];
14
- }
15
- return Object.fromEntries(
16
- Object.entries(entry).map(([key, value]) => {
17
- if (Array.isArray(value)) {
18
- return [key, [runtimeEntry, ...value]];
19
- }
20
- return [key, [runtimeEntry, value]];
21
- })
22
- );
23
- }
24
- function patchRules(rules, babelPluginPath) {
25
- if (!rules) {
26
- return;
27
- }
28
- for (const rule of rules) {
29
- if (rule.oneOf) {
30
- patchRules(rule.oneOf, babelPluginPath);
31
- }
32
- if (rule.loader?.includes("babel-loader")) {
33
- rule.options = {
34
- ...rule.options ?? {},
35
- plugins: [...rule.options?.plugins ?? [], babelPluginPath]
36
- };
37
- }
38
- if (rule.use) {
39
- rule.use = rule.use.map((useEntry) => {
40
- if (!useEntry.loader?.includes("babel-loader")) {
41
- return useEntry;
42
- }
43
- return {
44
- ...useEntry,
45
- options: {
46
- ...useEntry.options ?? {},
47
- plugins: [...useEntry.options?.plugins ?? [], babelPluginPath]
48
- }
49
- };
50
- });
51
- }
52
- }
53
- }
54
- function withReactComponentJump(config, options = {}) {
55
- const { env = process.env.NODE_ENV ?? "development" } = options;
56
- if (env !== "development") {
57
- return config;
58
- }
59
- const babelPluginPath = path.join(__dirname, "babelInjectComponentSource.cjs");
60
- const runtimeEntry = path.join(__dirname, "webpackRuntimeEntry.cjs");
61
- patchRules(config.module?.rules, babelPluginPath);
62
- config.entry = injectEntry(config.entry, runtimeEntry);
63
- return config;
64
- }
65
- module.exports = {
66
- withReactComponentJump
67
- };
68
- //# sourceMappingURL=webpack.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/webpack.cts"],"sourcesContent":["const path = require(\"node:path\");\n\ntype WebpackAdapterOptions = {\n env?: \"development\" | \"production\" | string;\n};\n\ntype Rule = {\n oneOf?: Rule[];\n use?: Array<{ loader?: string; options?: { plugins?: unknown[] } }>;\n loader?: string;\n options?: { plugins?: unknown[] };\n};\n\ntype WebpackConfig = {\n entry?: string | string[] | Record<string, string | string[]>;\n module?: {\n rules?: Rule[];\n };\n};\n\nfunction injectEntry(entry: WebpackConfig[\"entry\"], runtimeEntry: string) {\n if (!entry) {\n return entry;\n }\n\n if (typeof entry === \"string\") {\n return [runtimeEntry, entry];\n }\n\n if (Array.isArray(entry)) {\n return [runtimeEntry, ...entry];\n }\n\n return Object.fromEntries(\n Object.entries(entry).map(([key, value]) => {\n if (Array.isArray(value)) {\n return [key, [runtimeEntry, ...value]];\n }\n\n return [key, [runtimeEntry, value]];\n }),\n );\n}\n\nfunction patchRules(rules: Rule[] | undefined, babelPluginPath: string) {\n if (!rules) {\n return;\n }\n\n for (const rule of rules) {\n if (rule.oneOf) {\n patchRules(rule.oneOf, babelPluginPath);\n }\n\n if (rule.loader?.includes(\"babel-loader\")) {\n rule.options = {\n ...(rule.options ?? {}),\n plugins: [...(rule.options?.plugins ?? []), babelPluginPath],\n };\n }\n\n if (rule.use) {\n rule.use = rule.use.map((useEntry) => {\n if (!useEntry.loader?.includes(\"babel-loader\")) {\n return useEntry;\n }\n\n return {\n ...useEntry,\n options: {\n ...(useEntry.options ?? {}),\n plugins: [...(useEntry.options?.plugins ?? []), babelPluginPath],\n },\n };\n });\n }\n }\n}\n\nfunction withReactComponentJump(config: WebpackConfig, options: WebpackAdapterOptions = {}) {\n const { env = process.env.NODE_ENV ?? \"development\" } = options;\n if (env !== \"development\") {\n return config;\n }\n\n const babelPluginPath = path.join(__dirname, \"babelInjectComponentSource.cjs\");\n const runtimeEntry = path.join(__dirname, \"webpackRuntimeEntry.cjs\");\n\n patchRules(config.module?.rules, babelPluginPath);\n config.entry = injectEntry(config.entry, runtimeEntry);\n return config;\n}\n\nmodule.exports = {\n withReactComponentJump,\n};\n"],"mappings":";;;AAAA,IAAM,OAAO,QAAQ,MAAW;AAoBhC,SAAS,YAAY,OAA+B,cAAsB;AACxE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,CAAC,cAAc,KAAK;AAAA,EAC7B;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,CAAC,cAAc,GAAG,KAAK;AAAA,EAChC;AAEA,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAC1C,UAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,eAAO,CAAC,KAAK,CAAC,cAAc,GAAG,KAAK,CAAC;AAAA,MACvC;AAEA,aAAO,CAAC,KAAK,CAAC,cAAc,KAAK,CAAC;AAAA,IACpC,CAAC;AAAA,EACH;AACF;AAEA,SAAS,WAAW,OAA2B,iBAAyB;AACtE,MAAI,CAAC,OAAO;AACV;AAAA,EACF;AAEA,aAAW,QAAQ,OAAO;AACxB,QAAI,KAAK,OAAO;AACd,iBAAW,KAAK,OAAO,eAAe;AAAA,IACxC;AAEA,QAAI,KAAK,QAAQ,SAAS,cAAc,GAAG;AACzC,WAAK,UAAU;AAAA,QACb,GAAI,KAAK,WAAW,CAAC;AAAA,QACrB,SAAS,CAAC,GAAI,KAAK,SAAS,WAAW,CAAC,GAAI,eAAe;AAAA,MAC7D;AAAA,IACF;AAEA,QAAI,KAAK,KAAK;AACZ,WAAK,MAAM,KAAK,IAAI,IAAI,CAAC,aAAa;AACpC,YAAI,CAAC,SAAS,QAAQ,SAAS,cAAc,GAAG;AAC9C,iBAAO;AAAA,QACT;AAEA,eAAO;AAAA,UACL,GAAG;AAAA,UACH,SAAS;AAAA,YACP,GAAI,SAAS,WAAW,CAAC;AAAA,YACzB,SAAS,CAAC,GAAI,SAAS,SAAS,WAAW,CAAC,GAAI,eAAe;AAAA,UACjE;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,uBAAuB,QAAuB,UAAiC,CAAC,GAAG;AAC1F,QAAM,EAAE,MAAM,QAAQ,IAAI,YAAY,cAAc,IAAI;AACxD,MAAI,QAAQ,eAAe;AACzB,WAAO;AAAA,EACT;AAEA,QAAM,kBAAkB,KAAK,KAAK,WAAW,gCAAgC;AAC7E,QAAM,eAAe,KAAK,KAAK,WAAW,yBAAyB;AAEnE,aAAW,OAAO,QAAQ,OAAO,eAAe;AAChD,SAAO,QAAQ,YAAY,OAAO,OAAO,YAAY;AACrD,SAAO;AACT;AAEA,OAAO,UAAU;AAAA,EACf;AACF;","names":[]}
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/dist/webpack.d.ts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/dist/webpack.js DELETED
@@ -1,82 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined") return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
- var __commonJS = (cb, mod) => function __require2() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
-
12
- // src/webpack.cts
13
- var require_webpack = __commonJS({
14
- "src/webpack.cts"(exports, module) {
15
- var path = __require("path");
16
- function injectEntry(entry, runtimeEntry) {
17
- if (!entry) {
18
- return entry;
19
- }
20
- if (typeof entry === "string") {
21
- return [runtimeEntry, entry];
22
- }
23
- if (Array.isArray(entry)) {
24
- return [runtimeEntry, ...entry];
25
- }
26
- return Object.fromEntries(
27
- Object.entries(entry).map(([key, value]) => {
28
- if (Array.isArray(value)) {
29
- return [key, [runtimeEntry, ...value]];
30
- }
31
- return [key, [runtimeEntry, value]];
32
- })
33
- );
34
- }
35
- function patchRules(rules, babelPluginPath) {
36
- if (!rules) {
37
- return;
38
- }
39
- for (const rule of rules) {
40
- if (rule.oneOf) {
41
- patchRules(rule.oneOf, babelPluginPath);
42
- }
43
- if (rule.loader?.includes("babel-loader")) {
44
- rule.options = {
45
- ...rule.options ?? {},
46
- plugins: [...rule.options?.plugins ?? [], babelPluginPath]
47
- };
48
- }
49
- if (rule.use) {
50
- rule.use = rule.use.map((useEntry) => {
51
- if (!useEntry.loader?.includes("babel-loader")) {
52
- return useEntry;
53
- }
54
- return {
55
- ...useEntry,
56
- options: {
57
- ...useEntry.options ?? {},
58
- plugins: [...useEntry.options?.plugins ?? [], babelPluginPath]
59
- }
60
- };
61
- });
62
- }
63
- }
64
- }
65
- function withReactComponentJump(config, options = {}) {
66
- const { env = process.env.NODE_ENV ?? "development" } = options;
67
- if (env !== "development") {
68
- return config;
69
- }
70
- const babelPluginPath = path.join(__dirname, "babelInjectComponentSource.cjs");
71
- const runtimeEntry = path.join(__dirname, "webpackRuntimeEntry.cjs");
72
- patchRules(config.module?.rules, babelPluginPath);
73
- config.entry = injectEntry(config.entry, runtimeEntry);
74
- return config;
75
- }
76
- module.exports = {
77
- withReactComponentJump
78
- };
79
- }
80
- });
81
- export default require_webpack();
82
- //# sourceMappingURL=webpack.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/webpack.cts"],"sourcesContent":["const path = require(\"node:path\");\n\ntype WebpackAdapterOptions = {\n env?: \"development\" | \"production\" | string;\n};\n\ntype Rule = {\n oneOf?: Rule[];\n use?: Array<{ loader?: string; options?: { plugins?: unknown[] } }>;\n loader?: string;\n options?: { plugins?: unknown[] };\n};\n\ntype WebpackConfig = {\n entry?: string | string[] | Record<string, string | string[]>;\n module?: {\n rules?: Rule[];\n };\n};\n\nfunction injectEntry(entry: WebpackConfig[\"entry\"], runtimeEntry: string) {\n if (!entry) {\n return entry;\n }\n\n if (typeof entry === \"string\") {\n return [runtimeEntry, entry];\n }\n\n if (Array.isArray(entry)) {\n return [runtimeEntry, ...entry];\n }\n\n return Object.fromEntries(\n Object.entries(entry).map(([key, value]) => {\n if (Array.isArray(value)) {\n return [key, [runtimeEntry, ...value]];\n }\n\n return [key, [runtimeEntry, value]];\n }),\n );\n}\n\nfunction patchRules(rules: Rule[] | undefined, babelPluginPath: string) {\n if (!rules) {\n return;\n }\n\n for (const rule of rules) {\n if (rule.oneOf) {\n patchRules(rule.oneOf, babelPluginPath);\n }\n\n if (rule.loader?.includes(\"babel-loader\")) {\n rule.options = {\n ...(rule.options ?? {}),\n plugins: [...(rule.options?.plugins ?? []), babelPluginPath],\n };\n }\n\n if (rule.use) {\n rule.use = rule.use.map((useEntry) => {\n if (!useEntry.loader?.includes(\"babel-loader\")) {\n return useEntry;\n }\n\n return {\n ...useEntry,\n options: {\n ...(useEntry.options ?? {}),\n plugins: [...(useEntry.options?.plugins ?? []), babelPluginPath],\n },\n };\n });\n }\n }\n}\n\nfunction withReactComponentJump(config: WebpackConfig, options: WebpackAdapterOptions = {}) {\n const { env = process.env.NODE_ENV ?? \"development\" } = options;\n if (env !== \"development\") {\n return config;\n }\n\n const babelPluginPath = path.join(__dirname, \"babelInjectComponentSource.cjs\");\n const runtimeEntry = path.join(__dirname, \"webpackRuntimeEntry.cjs\");\n\n patchRules(config.module?.rules, babelPluginPath);\n config.entry = injectEntry(config.entry, runtimeEntry);\n return config;\n}\n\nmodule.exports = {\n withReactComponentJump,\n};\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA,QAAM,OAAO,UAAQ,MAAW;AAoBhC,aAAS,YAAY,OAA+B,cAAsB;AACxE,UAAI,CAAC,OAAO;AACV,eAAO;AAAA,MACT;AAEA,UAAI,OAAO,UAAU,UAAU;AAC7B,eAAO,CAAC,cAAc,KAAK;AAAA,MAC7B;AAEA,UAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,eAAO,CAAC,cAAc,GAAG,KAAK;AAAA,MAChC;AAEA,aAAO,OAAO;AAAA,QACZ,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAC1C,cAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,mBAAO,CAAC,KAAK,CAAC,cAAc,GAAG,KAAK,CAAC;AAAA,UACvC;AAEA,iBAAO,CAAC,KAAK,CAAC,cAAc,KAAK,CAAC;AAAA,QACpC,CAAC;AAAA,MACH;AAAA,IACF;AAEA,aAAS,WAAW,OAA2B,iBAAyB;AACtE,UAAI,CAAC,OAAO;AACV;AAAA,MACF;AAEA,iBAAW,QAAQ,OAAO;AACxB,YAAI,KAAK,OAAO;AACd,qBAAW,KAAK,OAAO,eAAe;AAAA,QACxC;AAEA,YAAI,KAAK,QAAQ,SAAS,cAAc,GAAG;AACzC,eAAK,UAAU;AAAA,YACb,GAAI,KAAK,WAAW,CAAC;AAAA,YACrB,SAAS,CAAC,GAAI,KAAK,SAAS,WAAW,CAAC,GAAI,eAAe;AAAA,UAC7D;AAAA,QACF;AAEA,YAAI,KAAK,KAAK;AACZ,eAAK,MAAM,KAAK,IAAI,IAAI,CAAC,aAAa;AACpC,gBAAI,CAAC,SAAS,QAAQ,SAAS,cA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