react-code-locator 0.1.9 → 0.1.13

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 (52) hide show
  1. package/README.md +49 -44
  2. package/dist/babel.cjs +428 -40
  3. package/dist/babel.cjs.map +1 -1
  4. package/dist/babel.d.cts +12 -1
  5. package/dist/babel.d.ts +12 -1
  6. package/dist/babel.js +425 -29
  7. package/dist/babel.js.map +1 -1
  8. package/dist/babelInjectComponentSource.cjs +400 -38
  9. package/dist/babelInjectComponentSource.cjs.map +1 -1
  10. package/dist/babelInjectComponentSource.d.cts +3 -4
  11. package/dist/babelInjectComponentSource.d.ts +3 -4
  12. package/dist/babelInjectComponentSource.js +400 -28
  13. package/dist/babelInjectComponentSource.js.map +1 -1
  14. package/dist/client-sm5wi0uT.d.cts +15 -0
  15. package/dist/client-sm5wi0uT.d.ts +15 -0
  16. package/dist/client.cjs +157 -28
  17. package/dist/client.cjs.map +1 -1
  18. package/dist/client.d.cts +1 -14
  19. package/dist/client.d.ts +1 -14
  20. package/dist/client.js +157 -28
  21. package/dist/client.js.map +1 -1
  22. package/dist/esbuild.cjs +616 -0
  23. package/dist/esbuild.cjs.map +1 -0
  24. package/dist/esbuild.d.cts +25 -0
  25. package/dist/esbuild.d.ts +25 -0
  26. package/dist/esbuild.js +589 -0
  27. package/dist/esbuild.js.map +1 -0
  28. package/dist/index.cjs +843 -30
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +9 -1
  31. package/dist/index.d.ts +9 -1
  32. package/dist/index.js +830 -29
  33. package/dist/index.js.map +1 -1
  34. package/dist/sourceAdapter-DLWo_ABo.d.cts +15 -0
  35. package/dist/sourceAdapter-DLWo_ABo.d.ts +15 -0
  36. package/dist/swc.cjs +589 -0
  37. package/dist/swc.cjs.map +1 -0
  38. package/dist/swc.d.cts +29 -0
  39. package/dist/swc.d.ts +29 -0
  40. package/dist/swc.js +560 -0
  41. package/dist/swc.js.map +1 -0
  42. package/dist/vite.cjs +529 -84
  43. package/dist/vite.cjs.map +1 -1
  44. package/dist/vite.d.cts +20 -6
  45. package/dist/vite.d.ts +20 -6
  46. package/dist/vite.js +524 -72
  47. package/dist/vite.js.map +1 -1
  48. package/dist/webpackRuntimeEntry.cjs +157 -28
  49. package/dist/webpackRuntimeEntry.cjs.map +1 -1
  50. package/dist/webpackRuntimeEntry.js +157 -28
  51. package/dist/webpackRuntimeEntry.js.map +1 -1
  52. package/package.json +12 -1
package/dist/babel.d.cts CHANGED
@@ -1,2 +1,13 @@
1
- export { BabelInjectComponentSourceOptions, babelInjectComponentSource } from './babelInjectComponentSource.cjs';
1
+ import { S as SourceAdapterDescriptor, b as SourceInjectionOptions } from './sourceAdapter-DLWo_ABo.cjs';
2
+ export { a as SourceAdapterKind } from './sourceAdapter-DLWo_ABo.cjs';
3
+ import { babelInjectComponentSource, BabelInjectComponentSourceOptions } from './babelInjectComponentSource.cjs';
2
4
  import '@babel/core';
5
+
6
+ type BabelSourceAdapterConfig = {
7
+ plugins: Array<[typeof babelInjectComponentSource, BabelInjectComponentSourceOptions]>;
8
+ };
9
+
10
+ declare function createBabelSourceAdapter(options?: BabelInjectComponentSourceOptions): SourceAdapterDescriptor<BabelSourceAdapterConfig, SourceInjectionOptions>;
11
+ declare const babelSourceAdapter: SourceAdapterDescriptor<BabelSourceAdapterConfig, SourceInjectionOptions>;
12
+
13
+ export { BabelInjectComponentSourceOptions, type BabelSourceAdapterConfig, SourceAdapterDescriptor, SourceInjectionOptions, babelInjectComponentSource, babelSourceAdapter, createBabelSourceAdapter };
package/dist/babel.d.ts CHANGED
@@ -1,2 +1,13 @@
1
- export { BabelInjectComponentSourceOptions, babelInjectComponentSource } from './babelInjectComponentSource.js';
1
+ import { S as SourceAdapterDescriptor, b as SourceInjectionOptions } from './sourceAdapter-DLWo_ABo.js';
2
+ export { a as SourceAdapterKind } from './sourceAdapter-DLWo_ABo.js';
3
+ import { babelInjectComponentSource, BabelInjectComponentSourceOptions } from './babelInjectComponentSource.js';
2
4
  import '@babel/core';
5
+
6
+ type BabelSourceAdapterConfig = {
7
+ plugins: Array<[typeof babelInjectComponentSource, BabelInjectComponentSourceOptions]>;
8
+ };
9
+
10
+ declare function createBabelSourceAdapter(options?: BabelInjectComponentSourceOptions): SourceAdapterDescriptor<BabelSourceAdapterConfig, SourceInjectionOptions>;
11
+ declare const babelSourceAdapter: SourceAdapterDescriptor<BabelSourceAdapterConfig, SourceInjectionOptions>;
12
+
13
+ export { BabelInjectComponentSourceOptions, type BabelSourceAdapterConfig, SourceAdapterDescriptor, SourceInjectionOptions, babelInjectComponentSource, babelSourceAdapter, createBabelSourceAdapter };
package/dist/babel.js CHANGED
@@ -1,14 +1,118 @@
1
1
  // src/babelInjectComponentSource.ts
2
- import path from "path";
3
2
  import { types as t } from "@babel/core";
4
3
 
5
4
  // src/constants.ts
6
5
  var SOURCE_PROP = "__componentSourceLoc";
6
+ var JSX_SOURCE_PROP = "$componentSourceLoc";
7
+ var JSX_SOURCE_REGISTRY_SYMBOL = "react-code-locator.jsxSourceRegistry";
8
+
9
+ // src/sourceMetadata.ts
10
+ function normalizeSlashes(value) {
11
+ return value.replace(/\\/g, "/");
12
+ }
13
+ function trimTrailingSlash(value) {
14
+ return value.replace(/\/+$/, "");
15
+ }
16
+ function splitPathSegments(value) {
17
+ return normalizeSlashes(value).split("/").filter(Boolean);
18
+ }
19
+ function computeRelativePath(fromPath, toPath) {
20
+ const fromSegments = splitPathSegments(fromPath);
21
+ const toSegments = splitPathSegments(toPath);
22
+ let sharedIndex = 0;
23
+ while (sharedIndex < fromSegments.length && sharedIndex < toSegments.length && fromSegments[sharedIndex] === toSegments[sharedIndex]) {
24
+ sharedIndex += 1;
25
+ }
26
+ const upSegments = new Array(Math.max(0, fromSegments.length - sharedIndex)).fill("..");
27
+ const downSegments = toSegments.slice(sharedIndex);
28
+ const relativeSegments = [...upSegments, ...downSegments];
29
+ return relativeSegments.length > 0 ? relativeSegments.join("/") : ".";
30
+ }
31
+ function normalizeProjectRoot(projectRoot) {
32
+ if (projectRoot) {
33
+ return trimTrailingSlash(normalizeSlashes(projectRoot));
34
+ }
35
+ return "";
36
+ }
37
+ function toRelativeSource(filename, loc, projectRoot) {
38
+ if (!filename || !loc) {
39
+ return null;
40
+ }
41
+ const root = normalizeProjectRoot(projectRoot);
42
+ const normalizedFilename = normalizeSlashes(filename);
43
+ const relPath = root && normalizedFilename.startsWith(`${root}/`) ? normalizedFilename.slice(root.length + 1) : root ? computeRelativePath(root, normalizedFilename) : normalizedFilename;
44
+ return `${relPath}:${loc.line}:${loc.column + 1}`;
45
+ }
46
+ function isProjectLocalFile(filename, projectRoot) {
47
+ if (!filename) {
48
+ return false;
49
+ }
50
+ const root = normalizeProjectRoot(projectRoot);
51
+ const normalizedFilename = normalizeSlashes(filename);
52
+ if (!root) {
53
+ return !normalizedFilename.startsWith("../") && !normalizedFilename.startsWith("/") && !/^[A-Za-z]:\//.test(normalizedFilename);
54
+ }
55
+ if (normalizedFilename.startsWith(`${root}/`) || normalizedFilename === root) {
56
+ return true;
57
+ }
58
+ const relativePath = computeRelativePath(root, normalizedFilename);
59
+ return !relativePath.startsWith("../");
60
+ }
61
+ function isExternalToProjectRoot(filename, projectRoot) {
62
+ return !isProjectLocalFile(filename, projectRoot);
63
+ }
7
64
 
8
65
  // src/babelInjectComponentSource.ts
66
+ var SOURCE_PROP_LOCAL = "_componentSourceLoc";
67
+ var SOURCE_PROPS_REST = "__reactCodeLocatorProps";
9
68
  function isComponentName(name) {
10
69
  return /^[A-Z]/.test(name);
11
70
  }
71
+ function isCustomComponentTag(name) {
72
+ if (t.isJSXIdentifier(name)) {
73
+ return isComponentName(name.name);
74
+ }
75
+ if (t.isJSXMemberExpression(name)) {
76
+ return true;
77
+ }
78
+ return false;
79
+ }
80
+ function isIntrinsicElementTag(name) {
81
+ return t.isJSXIdentifier(name) && /^[a-z]/.test(name.name);
82
+ }
83
+ function isElementFactoryIdentifier(name) {
84
+ return name === "jsx" || name === "jsxs" || name === "jsxDEV" || name === "_jsx" || name === "_jsxs" || name === "_jsxDEV" || name === "createElement";
85
+ }
86
+ function isReactElementFactoryCall(pathNode) {
87
+ const callee = pathNode.node.callee;
88
+ if (t.isIdentifier(callee)) {
89
+ return isElementFactoryIdentifier(callee.name);
90
+ }
91
+ return t.isMemberExpression(callee) && t.isIdentifier(callee.object, { name: "React" }) && t.isIdentifier(callee.property, { name: "createElement" });
92
+ }
93
+ function getRootJsxIdentifierName(name) {
94
+ if (t.isJSXIdentifier(name)) {
95
+ return name.name;
96
+ }
97
+ if (t.isJSXMemberExpression(name)) {
98
+ return getRootJsxIdentifierName(name.object);
99
+ }
100
+ return null;
101
+ }
102
+ function isStyledModuleImport(binding) {
103
+ if (!binding) {
104
+ return false;
105
+ }
106
+ if (!binding.path.isImportSpecifier() && !binding.path.isImportDefaultSpecifier() && !binding.path.isImportNamespaceSpecifier()) {
107
+ return false;
108
+ }
109
+ const source = binding.path.parentPath.isImportDeclaration() ? binding.path.parentPath.node.source.value : null;
110
+ if (typeof source !== "string") {
111
+ return false;
112
+ }
113
+ const normalized = source.replace(/\\/g, "/");
114
+ return normalized === "./styled" || normalized === "../styled" || normalized.endsWith("/styled");
115
+ }
12
116
  function isSupportedComponentInit(node) {
13
117
  if (!node) {
14
118
  return false;
@@ -24,13 +128,104 @@ function isSupportedComponentInit(node) {
24
128
  }
25
129
  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");
26
130
  }
27
- function getSourceValue(state, loc) {
131
+ function hasSourcePropBinding(pattern) {
132
+ return pattern.properties.some((property) => {
133
+ if (!t.isObjectProperty(property)) {
134
+ return false;
135
+ }
136
+ return t.isIdentifier(property.key) && property.key.name === JSX_SOURCE_PROP;
137
+ });
138
+ }
139
+ function injectSourcePropBinding(pattern) {
140
+ if (hasSourcePropBinding(pattern)) {
141
+ return;
142
+ }
143
+ const sourceBinding = t.objectProperty(
144
+ t.identifier(JSX_SOURCE_PROP),
145
+ t.identifier(SOURCE_PROP_LOCAL),
146
+ false,
147
+ false
148
+ );
149
+ const restIndex = pattern.properties.findIndex(
150
+ (property) => t.isRestElement(property)
151
+ );
152
+ if (restIndex === -1) {
153
+ pattern.properties.push(sourceBinding);
154
+ return;
155
+ }
156
+ pattern.properties.splice(restIndex, 0, sourceBinding);
157
+ }
158
+ function injectSourcePropIntoIdentifierParam(node, param) {
159
+ if (!t.isBlockStatement(node.body)) {
160
+ node.body = t.blockStatement([t.returnStatement(node.body)]);
161
+ }
162
+ const alreadyInjected = node.body.body.some(
163
+ (statement) => t.isVariableDeclaration(statement) && statement.declarations.some(
164
+ (declaration) => t.isIdentifier(declaration.id) && declaration.id.name === SOURCE_PROPS_REST
165
+ )
166
+ );
167
+ if (alreadyInjected) {
168
+ return;
169
+ }
170
+ node.body.body.unshift(
171
+ t.variableDeclaration("const", [
172
+ t.variableDeclarator(
173
+ t.objectPattern([
174
+ t.objectProperty(
175
+ t.identifier(JSX_SOURCE_PROP),
176
+ t.identifier(SOURCE_PROP_LOCAL),
177
+ false,
178
+ false
179
+ ),
180
+ t.restElement(t.identifier(SOURCE_PROPS_REST))
181
+ ]),
182
+ param
183
+ )
184
+ ]),
185
+ t.expressionStatement(
186
+ t.assignmentExpression(
187
+ "=",
188
+ t.identifier(param.name),
189
+ t.identifier(SOURCE_PROPS_REST)
190
+ )
191
+ )
192
+ );
193
+ }
194
+ function injectSourcePropIntoFunctionParams(node) {
195
+ const firstParam = node.params[0];
196
+ if (!firstParam) {
197
+ return;
198
+ }
199
+ if (t.isObjectPattern(firstParam)) {
200
+ injectSourcePropBinding(firstParam);
201
+ return;
202
+ }
203
+ if (t.isIdentifier(firstParam)) {
204
+ injectSourcePropIntoIdentifierParam(node, firstParam);
205
+ }
206
+ }
207
+ function injectSourcePropIntoExpression(node) {
208
+ if (!node) {
209
+ return;
210
+ }
211
+ if (t.isFunctionExpression(node) || t.isArrowFunctionExpression(node)) {
212
+ injectSourcePropIntoFunctionParams(node);
213
+ return;
214
+ }
215
+ if (!t.isCallExpression(node)) {
216
+ return;
217
+ }
218
+ const firstArg = node.arguments[0];
219
+ if (firstArg && !t.isSpreadElement(firstArg) && (t.isFunctionExpression(firstArg) || t.isArrowFunctionExpression(firstArg))) {
220
+ injectSourcePropIntoFunctionParams(firstArg);
221
+ }
222
+ }
223
+ function getSourceValue(state, loc, projectRoot) {
28
224
  const filename = state.file?.opts?.filename;
29
225
  if (!filename || !loc) {
30
226
  return null;
31
227
  }
32
- const relPath = path.relative(process.cwd(), filename).replace(/\\/g, "/");
33
- return `${relPath}:${loc.line}:${loc.column + 1}`;
228
+ return toRelativeSource(filename, loc, projectRoot);
34
229
  }
35
230
  function buildAssignment(name, sourceValue) {
36
231
  return t.expressionStatement(
@@ -41,13 +236,98 @@ function buildAssignment(name, sourceValue) {
41
236
  )
42
237
  );
43
238
  }
44
- function visitDeclaration(declarationPath, insertAfterPath, state, seen) {
239
+ function buildIntrinsicSourceHelper() {
240
+ return t.functionDeclaration(
241
+ t.identifier("_markIntrinsicElementSource"),
242
+ [t.identifier("element"), t.identifier("source")],
243
+ t.blockStatement([
244
+ t.variableDeclaration("const", [
245
+ t.variableDeclarator(
246
+ t.identifier("registryKey"),
247
+ t.callExpression(
248
+ t.memberExpression(t.identifier("Symbol"), t.identifier("for")),
249
+ [t.stringLiteral(JSX_SOURCE_REGISTRY_SYMBOL)]
250
+ )
251
+ )
252
+ ]),
253
+ t.variableDeclaration("let", [
254
+ t.variableDeclarator(
255
+ t.identifier("registry"),
256
+ t.memberExpression(t.identifier("globalThis"), t.identifier("registryKey"), true)
257
+ )
258
+ ]),
259
+ t.ifStatement(
260
+ t.unaryExpression(
261
+ "!",
262
+ t.binaryExpression("instanceof", t.identifier("registry"), t.identifier("WeakMap"))
263
+ ),
264
+ t.blockStatement([
265
+ t.expressionStatement(
266
+ t.assignmentExpression(
267
+ "=",
268
+ t.identifier("registry"),
269
+ t.assignmentExpression(
270
+ "=",
271
+ t.memberExpression(t.identifier("globalThis"), t.identifier("registryKey"), true),
272
+ t.newExpression(t.identifier("WeakMap"), [])
273
+ )
274
+ )
275
+ )
276
+ ])
277
+ ),
278
+ t.ifStatement(
279
+ t.logicalExpression(
280
+ "&&",
281
+ t.identifier("element"),
282
+ t.logicalExpression(
283
+ "&&",
284
+ t.binaryExpression("===", t.unaryExpression("typeof", t.identifier("element")), t.stringLiteral("object")),
285
+ t.binaryExpression(
286
+ "===",
287
+ t.unaryExpression("typeof", t.memberExpression(t.identifier("element"), t.identifier("props"))),
288
+ t.stringLiteral("object")
289
+ )
290
+ )
291
+ ),
292
+ t.blockStatement([
293
+ t.expressionStatement(
294
+ t.callExpression(
295
+ t.memberExpression(t.identifier("registry"), t.identifier("set")),
296
+ [t.memberExpression(t.identifier("element"), t.identifier("props")), t.identifier("source")]
297
+ )
298
+ )
299
+ ])
300
+ ),
301
+ t.returnStatement(t.identifier("element"))
302
+ ])
303
+ );
304
+ }
305
+ function ensureIntrinsicSourceHelper(programPath, state) {
306
+ if (state.injectedIntrinsicHelper) {
307
+ return;
308
+ }
309
+ const alreadyExists = programPath.node.body.some(
310
+ (node) => t.isFunctionDeclaration(node) && t.isIdentifier(node.id, { name: "_markIntrinsicElementSource" })
311
+ );
312
+ if (!alreadyExists) {
313
+ programPath.unshiftContainer("body", buildIntrinsicSourceHelper());
314
+ }
315
+ state.injectedIntrinsicHelper = true;
316
+ }
317
+ function visitDeclaration(declarationPath, insertAfterPath, state, seen, projectRoot) {
45
318
  if (declarationPath.isFunctionDeclaration() || declarationPath.isClassDeclaration()) {
46
319
  const name = declarationPath.node.id?.name;
47
320
  if (!name || !isComponentName(name) || seen.has(name)) {
48
321
  return;
49
322
  }
50
- const sourceValue = getSourceValue(state, declarationPath.node.loc?.start);
323
+ if (declarationPath.isFunctionDeclaration()) {
324
+ injectSourcePropIntoFunctionParams(declarationPath.node);
325
+ }
326
+ const sourceValue = getSourceValue(
327
+ state,
328
+ declarationPath.node.loc?.start,
329
+ projectRoot
330
+ );
51
331
  if (!sourceValue) {
52
332
  return;
53
333
  }
@@ -58,38 +338,128 @@ function visitDeclaration(declarationPath, insertAfterPath, state, seen) {
58
338
  if (!declarationPath.isVariableDeclaration()) {
59
339
  return;
60
340
  }
61
- const assignments = declarationPath.node.declarations.flatMap((declarator) => {
62
- if (!t.isIdentifier(declarator.id) || !isComponentName(declarator.id.name) || seen.has(declarator.id.name)) {
63
- return [];
64
- }
65
- if (!declarator.init) {
66
- return [];
67
- }
68
- if (!isSupportedComponentInit(declarator.init)) {
69
- return [];
70
- }
71
- const sourceValue = getSourceValue(state, declarator.loc?.start ?? declarator.init.loc?.start);
72
- if (!sourceValue) {
73
- return [];
341
+ const assignments = declarationPath.node.declarations.flatMap(
342
+ (declarator) => {
343
+ if (!t.isIdentifier(declarator.id) || !isComponentName(declarator.id.name) || seen.has(declarator.id.name)) {
344
+ return [];
345
+ }
346
+ if (!declarator.init) {
347
+ return [];
348
+ }
349
+ if (!isSupportedComponentInit(declarator.init)) {
350
+ return [];
351
+ }
352
+ injectSourcePropIntoExpression(declarator.init);
353
+ const sourceValue = getSourceValue(
354
+ state,
355
+ declarator.loc?.start ?? declarator.init.loc?.start,
356
+ projectRoot
357
+ );
358
+ if (!sourceValue) {
359
+ return [];
360
+ }
361
+ seen.add(declarator.id.name);
362
+ return [buildAssignment(declarator.id.name, sourceValue)];
74
363
  }
75
- seen.add(declarator.id.name);
76
- return [buildAssignment(declarator.id.name, sourceValue)];
77
- });
364
+ );
78
365
  if (assignments.length > 0) {
79
366
  insertAfterPath.insertAfter(assignments);
80
367
  }
81
368
  }
82
369
  function babelInjectComponentSource(options = {}) {
83
- const { injectJsxSource = false, injectComponentSource = true } = options;
370
+ const {
371
+ injectJsxSource = true,
372
+ injectComponentSource = true,
373
+ projectRoot
374
+ } = options;
84
375
  return {
85
376
  name: "babel-inject-component-source",
86
377
  visitor: {
378
+ CallExpression(pathNode, state) {
379
+ if (!injectJsxSource) {
380
+ return;
381
+ }
382
+ if (!isReactElementFactoryCall(pathNode)) {
383
+ return;
384
+ }
385
+ if (pathNode.parentPath.isCallExpression() && t.isIdentifier(pathNode.parentPath.node.callee, {
386
+ name: "_markIntrinsicElementSource"
387
+ })) {
388
+ return;
389
+ }
390
+ const sourceValue = getSourceValue(
391
+ state,
392
+ pathNode.node.loc?.start,
393
+ projectRoot
394
+ );
395
+ if (!sourceValue) {
396
+ return;
397
+ }
398
+ const programPath = pathNode.findParent((parent) => parent.isProgram());
399
+ if (!programPath || !programPath.isProgram()) {
400
+ return;
401
+ }
402
+ ensureIntrinsicSourceHelper(programPath, state);
403
+ pathNode.replaceWith(
404
+ t.callExpression(t.identifier("_markIntrinsicElementSource"), [
405
+ pathNode.node,
406
+ t.stringLiteral(sourceValue)
407
+ ])
408
+ );
409
+ pathNode.skip();
410
+ },
411
+ JSXElement: {
412
+ exit(pathNode, state) {
413
+ if (!injectJsxSource) {
414
+ return;
415
+ }
416
+ if (!isIntrinsicElementTag(pathNode.node.openingElement.name)) {
417
+ return;
418
+ }
419
+ if (pathNode.parentPath.isCallExpression() && t.isIdentifier(pathNode.parentPath.node.callee, { name: "_markIntrinsicElementSource" })) {
420
+ return;
421
+ }
422
+ const sourceValue = getSourceValue(
423
+ state,
424
+ pathNode.node.openingElement.loc?.start,
425
+ projectRoot
426
+ );
427
+ if (!sourceValue) {
428
+ return;
429
+ }
430
+ const programPath = pathNode.findParent((parent) => parent.isProgram());
431
+ if (!programPath || !programPath.isProgram()) {
432
+ return;
433
+ }
434
+ ensureIntrinsicSourceHelper(programPath, state);
435
+ const wrappedNode = t.callExpression(t.identifier("_markIntrinsicElementSource"), [
436
+ pathNode.node,
437
+ t.stringLiteral(sourceValue)
438
+ ]);
439
+ if (pathNode.parentPath.isJSXElement() || pathNode.parentPath.isJSXFragment()) {
440
+ pathNode.replaceWith(t.jsxExpressionContainer(wrappedNode));
441
+ return;
442
+ }
443
+ if (pathNode.parentPath.isJSXExpressionContainer()) {
444
+ pathNode.parentPath.replaceWith(t.jsxExpressionContainer(wrappedNode));
445
+ return;
446
+ }
447
+ pathNode.replaceWith(wrappedNode);
448
+ }
449
+ },
87
450
  JSXOpeningElement(pathNode, state) {
88
451
  if (!injectJsxSource) {
89
452
  return;
90
453
  }
454
+ if (!isCustomComponentTag(pathNode.node.name)) {
455
+ return;
456
+ }
457
+ const rootIdentifierName = getRootJsxIdentifierName(pathNode.node.name);
458
+ if (rootIdentifierName && isExternalToProjectRoot(state.file?.opts?.filename, projectRoot) && isStyledModuleImport(pathNode.scope.getBinding(rootIdentifierName))) {
459
+ return;
460
+ }
91
461
  const hasSourceProp = pathNode.node.attributes.some(
92
- (attr) => t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name) && attr.name.name === SOURCE_PROP
462
+ (attr) => t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name) && attr.name.name === JSX_SOURCE_PROP
93
463
  );
94
464
  if (hasSourceProp) {
95
465
  return;
@@ -101,8 +471,10 @@ function babelInjectComponentSource(options = {}) {
101
471
  }
102
472
  pathNode.node.attributes.push(
103
473
  t.jsxAttribute(
104
- t.jsxIdentifier(SOURCE_PROP),
105
- t.stringLiteral(getSourceValue(state, loc) ?? `${filename.replace(/\\/g, "/")}:${loc.line}:${loc.column + 1}`)
474
+ t.jsxIdentifier(JSX_SOURCE_PROP),
475
+ t.stringLiteral(
476
+ getSourceValue(state, loc, projectRoot) ?? `${filename.replace(/\\/g, "/")}:${loc.line}:${loc.column + 1}`
477
+ )
106
478
  )
107
479
  );
108
480
  },
@@ -115,17 +487,41 @@ function babelInjectComponentSource(options = {}) {
115
487
  if (childPath.isExportNamedDeclaration() || childPath.isExportDefaultDeclaration()) {
116
488
  const declarationPath = childPath.get("declaration");
117
489
  if (!Array.isArray(declarationPath) && declarationPath.node) {
118
- visitDeclaration(declarationPath, childPath, state, seen);
490
+ visitDeclaration(declarationPath, childPath, state, seen, projectRoot);
119
491
  }
120
492
  continue;
121
493
  }
122
- visitDeclaration(childPath, childPath, state, seen);
494
+ visitDeclaration(childPath, childPath, state, seen, projectRoot);
123
495
  }
124
496
  }
125
497
  }
126
498
  };
127
499
  }
500
+
501
+ // src/sourceAdapter.ts
502
+ function defineSourceAdapter(descriptor) {
503
+ return descriptor;
504
+ }
505
+
506
+ // src/babel.ts
507
+ function createBabelSourceAdapter(options = {}) {
508
+ const resolvedOptions = {
509
+ projectRoot: process.cwd(),
510
+ ...options
511
+ };
512
+ return defineSourceAdapter({
513
+ kind: "babel",
514
+ name: "react-code-locator/babel",
515
+ options: resolvedOptions,
516
+ config: {
517
+ plugins: [[babelInjectComponentSource, resolvedOptions]]
518
+ }
519
+ });
520
+ }
521
+ var babelSourceAdapter = createBabelSourceAdapter();
128
522
  export {
129
- babelInjectComponentSource
523
+ babelInjectComponentSource,
524
+ babelSourceAdapter,
525
+ createBabelSourceAdapter
130
526
  };
131
527
  //# sourceMappingURL=babel.js.map
package/dist/babel.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/babelInjectComponentSource.ts","../src/constants.ts"],"sourcesContent":["import path from \"node:path\";\nimport { types as t, type NodePath, type PluginObj } from \"@babel/core\";\nimport { SOURCE_PROP } from \"./constants\";\n\nexport type BabelInjectComponentSourceOptions = {\n injectJsxSource?: boolean;\n injectComponentSource?: boolean;\n};\n\ntype BabelState = {\n file?: {\n opts?: {\n filename?: string;\n };\n };\n};\n\nfunction isComponentName(name: string) {\n return /^[A-Z]/.test(name);\n}\n\nfunction isSupportedComponentInit(node: t.Expression | null | undefined): 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 (t.isIdentifier(node.callee) && (node.callee.name === \"memo\" || node.callee.name === \"forwardRef\")) {\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\" || node.callee.property.name === \"forwardRef\")\n );\n}\n\nfunction getSourceValue(state: BabelState, loc: { line: number; column: number } | null | undefined) {\n const filename = state.file?.opts?.filename;\n if (!filename || !loc) {\n return null;\n }\n\n const relPath = path.relative(process.cwd(), filename).replace(/\\\\/g, \"/\");\n return `${relPath}:${loc.line}:${loc.column + 1}`;\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 visitDeclaration(\n declarationPath: NodePath,\n insertAfterPath: NodePath,\n state: BabelState,\n seen: Set<string>,\n) {\n if (declarationPath.isFunctionDeclaration() || declarationPath.isClassDeclaration()) {\n const name = declarationPath.node.id?.name;\n if (!name || !isComponentName(name) || seen.has(name)) {\n return;\n }\n\n const sourceValue = getSourceValue(state, declarationPath.node.loc?.start);\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((declarator) => {\n if (!t.isIdentifier(declarator.id) || !isComponentName(declarator.id.name) || seen.has(declarator.id.name)) {\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(state, declarator.loc?.start ?? declarator.init.loc?.start);\n if (!sourceValue) {\n return [];\n }\n\n seen.add(declarator.id.name);\n return [buildAssignment(declarator.id.name, sourceValue)];\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 { injectJsxSource = false, injectComponentSource = true } = options;\n\n return {\n name: \"babel-inject-component-source\",\n visitor: {\n JSXOpeningElement(pathNode, state) {\n if (!injectJsxSource) {\n return;\n }\n\n const hasSourceProp = pathNode.node.attributes.some(\n (attr) => t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name) && attr.name.name === SOURCE_PROP,\n );\n if (hasSourceProp) {\n return;\n }\n\n const filename = state.file?.opts?.filename;\n const loc = pathNode.node.loc?.start;\n if (!filename || !loc) {\n return;\n }\n\n pathNode.node.attributes.push(\n t.jsxAttribute(\n t.jsxIdentifier(SOURCE_PROP),\n t.stringLiteral(getSourceValue(state, loc) ?? `${filename.replace(/\\\\/g, \"/\")}:${loc.line}:${loc.column + 1}`),\n ),\n );\n },\n Program(programPath, state) {\n if (!injectComponentSource) {\n return;\n }\n\n const seen = new Set<string>();\n\n for (const childPath of programPath.get(\"body\")) {\n if (childPath.isExportNamedDeclaration() || childPath.isExportDefaultDeclaration()) {\n const declarationPath = childPath.get(\"declaration\");\n if (!Array.isArray(declarationPath) && declarationPath.node) {\n visitDeclaration(declarationPath, childPath, state, seen);\n }\n continue;\n }\n\n visitDeclaration(childPath, childPath, state, seen);\n }\n },\n },\n };\n}\n","export const SOURCE_PROP = \"__componentSourceLoc\";\n\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,SAAS,SAAS,SAAwC;;;ACDnD,IAAM,cAAc;;;ADiB3B,SAAS,gBAAgB,MAAc;AACrC,SAAO,SAAS,KAAK,IAAI;AAC3B;AAEA,SAAS,yBAAyB,MAAgD;AAChF,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,MAAI,EAAE,0BAA0B,IAAI,KAAK,EAAE,qBAAqB,IAAI,GAAG;AACrE,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,EAAE,iBAAiB,IAAI,GAAG;AAC7B,WAAO;AAAA,EACT;AAEA,MAAI,EAAE,aAAa,KAAK,MAAM,MAAM,KAAK,OAAO,SAAS,UAAU,KAAK,OAAO,SAAS,eAAe;AACrG,WAAO;AAAA,EAC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AG,KAAK,GAAG,SAAS,QAAQ,OAAO,GAAG,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,SAAS,CAAC,EAAE;AAAA,UAC/G;AAAA,QACF;AAAA,MACF;AAAA,MACA,QAAQ,aAAa,OAAO;AAC1B,YAAI,CAAC,uBAAuB;AAC1B;AAAA,QACF;AAEA,cAAM,OAAO,oBAAI,IAAY;AAE7B,mBAAW,aAAa,YAAY,IAAI,MAAM,GAAG;AAC/C,cAAI,UAAU,yBAAyB,KAAK,UAAU,2BAA2B,GAAG;AAClF,kBAAM,kBAAkB,UAAU,IAAI,aAAa;AACnD,gBAAI,CAAC,MAAM,QAAQ,eAAe,KAAK,gBAAgB,MAAM;AAC3D,+BAAiB,iBAAiB,WAAW,OAAO,IAAI;AAAA,YAC1D;AACA;AAAA,UACF;AAEA,2BAAiB,WAAW,WAAW,OAAO,IAAI;AAAA,QACpD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/babelInjectComponentSource.ts","../src/constants.ts","../src/sourceMetadata.ts","../src/sourceAdapter.ts","../src/babel.ts"],"sourcesContent":["import { types as t, type NodePath, type PluginObj } from \"@babel/core\";\nimport {\n JSX_SOURCE_PROP,\n JSX_SOURCE_REGISTRY_SYMBOL,\n SOURCE_PROP,\n} from \"./constants\";\nimport type { SourceInjectionOptions } from \"./sourceAdapter\";\nimport {\n isExternalToProjectRoot,\n toRelativeSource,\n} from \"./sourceMetadata\";\n\nexport type BabelInjectComponentSourceOptions = SourceInjectionOptions;\n\ntype BabelState = {\n file?: {\n opts?: {\n filename?: string;\n };\n };\n injectedIntrinsicHelper?: boolean;\n};\n\ntype BindingLike = {\n path: NodePath;\n};\n\nconst SOURCE_PROP_LOCAL = \"_componentSourceLoc\";\nconst SOURCE_PROPS_REST = \"__reactCodeLocatorProps\";\n\nfunction isComponentName(name: string) {\n return /^[A-Z]/.test(name);\n}\n\nfunction isCustomComponentTag(\n name: t.JSXIdentifier | t.JSXMemberExpression | t.JSXNamespacedName,\n) {\n if (t.isJSXIdentifier(name)) {\n return isComponentName(name.name);\n }\n\n if (t.isJSXMemberExpression(name)) {\n return true;\n }\n\n return false;\n}\n\nfunction isIntrinsicElementTag(\n name: t.JSXIdentifier | t.JSXMemberExpression | t.JSXNamespacedName,\n) {\n return t.isJSXIdentifier(name) && /^[a-z]/.test(name.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 getRootJsxIdentifierName(\n name: t.JSXIdentifier | t.JSXMemberExpression | t.JSXNamespacedName,\n): string | null {\n if (t.isJSXIdentifier(name)) {\n return name.name;\n }\n\n if (t.isJSXMemberExpression(name)) {\n return getRootJsxIdentifierName(name.object);\n }\n\n return null;\n}\n\nfunction isStyledModuleImport(binding: BindingLike | undefined) {\n if (!binding) {\n return false;\n }\n\n if (\n !binding.path.isImportSpecifier() &&\n !binding.path.isImportDefaultSpecifier() &&\n !binding.path.isImportNamespaceSpecifier()\n ) {\n return false;\n }\n\n const source = binding.path.parentPath.isImportDeclaration()\n ? binding.path.parentPath.node.source.value\n : null;\n if (typeof source !== \"string\") {\n return false;\n }\n\n const normalized = source.replace(/\\\\/g, \"/\");\n return (\n normalized === \"./styled\" ||\n normalized === \"../styled\" ||\n normalized.endsWith(\"/styled\")\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 hasSourcePropBinding(pattern: t.ObjectPattern) {\n return pattern.properties.some((property: t.ObjectPattern[\"properties\"][number]) => {\n if (!t.isObjectProperty(property)) {\n return false;\n }\n\n return (\n t.isIdentifier(property.key) && property.key.name === JSX_SOURCE_PROP\n );\n });\n}\n\nfunction injectSourcePropBinding(pattern: t.ObjectPattern) {\n if (hasSourcePropBinding(pattern)) {\n return;\n }\n\n const sourceBinding = t.objectProperty(\n t.identifier(JSX_SOURCE_PROP),\n t.identifier(SOURCE_PROP_LOCAL),\n false,\n false,\n );\n\n const restIndex = pattern.properties.findIndex((property: t.ObjectPattern[\"properties\"][number]) =>\n t.isRestElement(property),\n );\n if (restIndex === -1) {\n pattern.properties.push(sourceBinding);\n return;\n }\n\n pattern.properties.splice(restIndex, 0, sourceBinding);\n}\n\nfunction injectSourcePropIntoIdentifierParam(\n node:\n | t.FunctionDeclaration\n | t.FunctionExpression\n | t.ArrowFunctionExpression,\n param: t.Identifier,\n) {\n if (!t.isBlockStatement(node.body)) {\n node.body = t.blockStatement([t.returnStatement(node.body)]);\n }\n\n const alreadyInjected = node.body.body.some(\n (statement: t.Statement) =>\n t.isVariableDeclaration(statement) &&\n statement.declarations.some(\n (declaration: t.VariableDeclarator) =>\n t.isIdentifier(declaration.id) &&\n declaration.id.name === SOURCE_PROPS_REST,\n ),\n );\n if (alreadyInjected) {\n return;\n }\n\n node.body.body.unshift(\n t.variableDeclaration(\"const\", [\n t.variableDeclarator(\n t.objectPattern([\n t.objectProperty(\n t.identifier(JSX_SOURCE_PROP),\n t.identifier(SOURCE_PROP_LOCAL),\n false,\n false,\n ),\n t.restElement(t.identifier(SOURCE_PROPS_REST)),\n ]),\n param,\n ),\n ]),\n t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.identifier(param.name),\n t.identifier(SOURCE_PROPS_REST),\n ),\n ),\n );\n}\n\nfunction injectSourcePropIntoFunctionParams(\n node:\n | t.FunctionDeclaration\n | t.FunctionExpression\n | t.ArrowFunctionExpression,\n) {\n const firstParam = node.params[0];\n if (!firstParam) {\n return;\n }\n\n if (t.isObjectPattern(firstParam)) {\n injectSourcePropBinding(firstParam);\n return;\n }\n\n if (t.isIdentifier(firstParam)) {\n injectSourcePropIntoIdentifierParam(node, firstParam);\n }\n}\n\nfunction injectSourcePropIntoExpression(node: t.Expression | null | undefined) {\n if (!node) {\n return;\n }\n\n if (t.isFunctionExpression(node) || t.isArrowFunctionExpression(node)) {\n injectSourcePropIntoFunctionParams(node);\n return;\n }\n\n if (!t.isCallExpression(node)) {\n return;\n }\n\n const firstArg = node.arguments[0];\n if (\n firstArg &&\n !t.isSpreadElement(firstArg) &&\n (t.isFunctionExpression(firstArg) || t.isArrowFunctionExpression(firstArg))\n ) {\n injectSourcePropIntoFunctionParams(firstArg);\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 buildIntrinsicSourceHelper() {\n return t.functionDeclaration(\n t.identifier(\"_markIntrinsicElementSource\"),\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 ensureIntrinsicSourceHelper(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: \"_markIntrinsicElementSource\" }),\n );\n if (!alreadyExists) {\n programPath.unshiftContainer(\"body\", buildIntrinsicSourceHelper());\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 if (declarationPath.isFunctionDeclaration()) {\n injectSourcePropIntoFunctionParams(declarationPath.node);\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 injectSourcePropIntoExpression(declarator.init);\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: \"_markIntrinsicElementSource\",\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 ensureIntrinsicSourceHelper(programPath, state);\n pathNode.replaceWith(\n t.callExpression(t.identifier(\"_markIntrinsicElementSource\"), [\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 (!isIntrinsicElementTag(pathNode.node.openingElement.name)) {\n return;\n }\n\n if (\n pathNode.parentPath.isCallExpression() &&\n t.isIdentifier(pathNode.parentPath.node.callee, { name: \"_markIntrinsicElementSource\" })\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 ensureIntrinsicSourceHelper(programPath, state);\n\n const wrappedNode = t.callExpression(t.identifier(\"_markIntrinsicElementSource\"), [\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 JSXOpeningElement(pathNode: NodePath<t.JSXOpeningElement>, state: BabelState) {\n if (!injectJsxSource) {\n return;\n }\n\n if (!isCustomComponentTag(pathNode.node.name)) {\n return;\n }\n\n const rootIdentifierName = getRootJsxIdentifierName(pathNode.node.name);\n if (\n rootIdentifierName &&\n isExternalToProjectRoot(state.file?.opts?.filename, projectRoot) &&\n isStyledModuleImport(pathNode.scope.getBinding(rootIdentifierName))\n ) {\n return;\n }\n\n const hasSourceProp = pathNode.node.attributes.some(\n (attr: t.JSXAttribute | t.JSXSpreadAttribute) =>\n t.isJSXAttribute(attr) &&\n t.isJSXIdentifier(attr.name) &&\n attr.name.name === JSX_SOURCE_PROP,\n );\n if (hasSourceProp) {\n return;\n }\n\n const filename = state.file?.opts?.filename;\n const loc = pathNode.node.loc?.start;\n if (!filename || !loc) {\n return;\n }\n\n pathNode.node.attributes.push(\n t.jsxAttribute(\n t.jsxIdentifier(JSX_SOURCE_PROP),\n t.stringLiteral(\n getSourceValue(state, loc, projectRoot) ??\n `${filename.replace(/\\\\/g, \"/\")}:${loc.line}:${loc.column + 1}`,\n ),\n ),\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","export type SourceInjectionOptions = {\n injectJsxSource?: boolean;\n injectComponentSource?: boolean;\n projectRoot?: string;\n};\n\nexport type SourceAdapterKind = \"babel\" | \"vite\" | \"esbuild\" | \"swc\";\n\nexport type SourceAdapterDescriptor<TConfig = unknown, TOptions = SourceInjectionOptions> = {\n kind: SourceAdapterKind;\n name: string;\n options: TOptions;\n config: TConfig;\n};\n\nexport function defineSourceAdapter<TConfig = unknown, TOptions = SourceInjectionOptions>(\n descriptor: SourceAdapterDescriptor<TConfig, TOptions>,\n) {\n return descriptor;\n}\n","import { babelInjectComponentSource, type BabelInjectComponentSourceOptions } from \"./babelInjectComponentSource\";\nimport { defineSourceAdapter } from \"./sourceAdapter\";\n\nexport type BabelSourceAdapterConfig = {\n plugins: Array<[typeof babelInjectComponentSource, BabelInjectComponentSourceOptions]>;\n};\n\nexport { babelInjectComponentSource } from \"./babelInjectComponentSource\";\nexport type { BabelInjectComponentSourceOptions } from \"./babelInjectComponentSource\";\nexport type { SourceAdapterDescriptor, SourceAdapterKind, SourceInjectionOptions } from \"./sourceAdapter\";\n\nexport function createBabelSourceAdapter(options: BabelInjectComponentSourceOptions = {}) {\n const resolvedOptions = {\n projectRoot: process.cwd(),\n ...options,\n };\n\n return defineSourceAdapter<BabelSourceAdapterConfig, BabelInjectComponentSourceOptions>({\n kind: \"babel\",\n name: \"react-code-locator/babel\",\n options: resolvedOptions,\n config: {\n plugins: [[babelInjectComponentSource, resolvedOptions]],\n },\n });\n}\n\nexport const babelSourceAdapter = createBabelSourceAdapter();\n"],"mappings":";AAAA,SAAS,SAAS,SAAwC;;;ACAnD,IAAM,cAAc;AACpB,IAAM,kBAAkB;AACxB,IAAM,6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