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.
- package/README.md +49 -44
- package/dist/babel.cjs +428 -40
- package/dist/babel.cjs.map +1 -1
- package/dist/babel.d.cts +12 -1
- package/dist/babel.d.ts +12 -1
- package/dist/babel.js +425 -29
- package/dist/babel.js.map +1 -1
- package/dist/babelInjectComponentSource.cjs +400 -38
- package/dist/babelInjectComponentSource.cjs.map +1 -1
- package/dist/babelInjectComponentSource.d.cts +3 -4
- package/dist/babelInjectComponentSource.d.ts +3 -4
- package/dist/babelInjectComponentSource.js +400 -28
- package/dist/babelInjectComponentSource.js.map +1 -1
- package/dist/client-sm5wi0uT.d.cts +15 -0
- package/dist/client-sm5wi0uT.d.ts +15 -0
- package/dist/client.cjs +157 -28
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -14
- package/dist/client.d.ts +1 -14
- package/dist/client.js +157 -28
- package/dist/client.js.map +1 -1
- package/dist/esbuild.cjs +616 -0
- package/dist/esbuild.cjs.map +1 -0
- package/dist/esbuild.d.cts +25 -0
- package/dist/esbuild.d.ts +25 -0
- package/dist/esbuild.js +589 -0
- package/dist/esbuild.js.map +1 -0
- package/dist/index.cjs +843 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +830 -29
- package/dist/index.js.map +1 -1
- package/dist/sourceAdapter-DLWo_ABo.d.cts +15 -0
- package/dist/sourceAdapter-DLWo_ABo.d.ts +15 -0
- package/dist/swc.cjs +589 -0
- package/dist/swc.cjs.map +1 -0
- package/dist/swc.d.cts +29 -0
- package/dist/swc.d.ts +29 -0
- package/dist/swc.js +560 -0
- package/dist/swc.js.map +1 -0
- package/dist/vite.cjs +529 -84
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +20 -6
- package/dist/vite.d.ts +20 -6
- package/dist/vite.js +524 -72
- package/dist/vite.js.map +1 -1
- package/dist/webpackRuntimeEntry.cjs +157 -28
- package/dist/webpackRuntimeEntry.cjs.map +1 -1
- package/dist/webpackRuntimeEntry.js +157 -28
- package/dist/webpackRuntimeEntry.js.map +1 -1
- package/package.json +12 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/babelInjectComponentSource.ts
|
|
@@ -33,16 +23,120 @@ __export(babelInjectComponentSource_exports, {
|
|
|
33
23
|
babelInjectComponentSource: () => babelInjectComponentSource
|
|
34
24
|
});
|
|
35
25
|
module.exports = __toCommonJS(babelInjectComponentSource_exports);
|
|
36
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
37
26
|
var import_core = require("@babel/core");
|
|
38
27
|
|
|
39
28
|
// src/constants.ts
|
|
40
29
|
var SOURCE_PROP = "__componentSourceLoc";
|
|
30
|
+
var JSX_SOURCE_PROP = "$componentSourceLoc";
|
|
31
|
+
var JSX_SOURCE_REGISTRY_SYMBOL = "react-code-locator.jsxSourceRegistry";
|
|
32
|
+
|
|
33
|
+
// src/sourceMetadata.ts
|
|
34
|
+
function normalizeSlashes(value) {
|
|
35
|
+
return value.replace(/\\/g, "/");
|
|
36
|
+
}
|
|
37
|
+
function trimTrailingSlash(value) {
|
|
38
|
+
return value.replace(/\/+$/, "");
|
|
39
|
+
}
|
|
40
|
+
function splitPathSegments(value) {
|
|
41
|
+
return normalizeSlashes(value).split("/").filter(Boolean);
|
|
42
|
+
}
|
|
43
|
+
function computeRelativePath(fromPath, toPath) {
|
|
44
|
+
const fromSegments = splitPathSegments(fromPath);
|
|
45
|
+
const toSegments = splitPathSegments(toPath);
|
|
46
|
+
let sharedIndex = 0;
|
|
47
|
+
while (sharedIndex < fromSegments.length && sharedIndex < toSegments.length && fromSegments[sharedIndex] === toSegments[sharedIndex]) {
|
|
48
|
+
sharedIndex += 1;
|
|
49
|
+
}
|
|
50
|
+
const upSegments = new Array(Math.max(0, fromSegments.length - sharedIndex)).fill("..");
|
|
51
|
+
const downSegments = toSegments.slice(sharedIndex);
|
|
52
|
+
const relativeSegments = [...upSegments, ...downSegments];
|
|
53
|
+
return relativeSegments.length > 0 ? relativeSegments.join("/") : ".";
|
|
54
|
+
}
|
|
55
|
+
function normalizeProjectRoot(projectRoot) {
|
|
56
|
+
if (projectRoot) {
|
|
57
|
+
return trimTrailingSlash(normalizeSlashes(projectRoot));
|
|
58
|
+
}
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
function toRelativeSource(filename, loc, projectRoot) {
|
|
62
|
+
if (!filename || !loc) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const root = normalizeProjectRoot(projectRoot);
|
|
66
|
+
const normalizedFilename = normalizeSlashes(filename);
|
|
67
|
+
const relPath = root && normalizedFilename.startsWith(`${root}/`) ? normalizedFilename.slice(root.length + 1) : root ? computeRelativePath(root, normalizedFilename) : normalizedFilename;
|
|
68
|
+
return `${relPath}:${loc.line}:${loc.column + 1}`;
|
|
69
|
+
}
|
|
70
|
+
function isProjectLocalFile(filename, projectRoot) {
|
|
71
|
+
if (!filename) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const root = normalizeProjectRoot(projectRoot);
|
|
75
|
+
const normalizedFilename = normalizeSlashes(filename);
|
|
76
|
+
if (!root) {
|
|
77
|
+
return !normalizedFilename.startsWith("../") && !normalizedFilename.startsWith("/") && !/^[A-Za-z]:\//.test(normalizedFilename);
|
|
78
|
+
}
|
|
79
|
+
if (normalizedFilename.startsWith(`${root}/`) || normalizedFilename === root) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
const relativePath = computeRelativePath(root, normalizedFilename);
|
|
83
|
+
return !relativePath.startsWith("../");
|
|
84
|
+
}
|
|
85
|
+
function isExternalToProjectRoot(filename, projectRoot) {
|
|
86
|
+
return !isProjectLocalFile(filename, projectRoot);
|
|
87
|
+
}
|
|
41
88
|
|
|
42
89
|
// src/babelInjectComponentSource.ts
|
|
90
|
+
var SOURCE_PROP_LOCAL = "_componentSourceLoc";
|
|
91
|
+
var SOURCE_PROPS_REST = "__reactCodeLocatorProps";
|
|
43
92
|
function isComponentName(name) {
|
|
44
93
|
return /^[A-Z]/.test(name);
|
|
45
94
|
}
|
|
95
|
+
function isCustomComponentTag(name) {
|
|
96
|
+
if (import_core.types.isJSXIdentifier(name)) {
|
|
97
|
+
return isComponentName(name.name);
|
|
98
|
+
}
|
|
99
|
+
if (import_core.types.isJSXMemberExpression(name)) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
function isIntrinsicElementTag(name) {
|
|
105
|
+
return import_core.types.isJSXIdentifier(name) && /^[a-z]/.test(name.name);
|
|
106
|
+
}
|
|
107
|
+
function isElementFactoryIdentifier(name) {
|
|
108
|
+
return name === "jsx" || name === "jsxs" || name === "jsxDEV" || name === "_jsx" || name === "_jsxs" || name === "_jsxDEV" || name === "createElement";
|
|
109
|
+
}
|
|
110
|
+
function isReactElementFactoryCall(pathNode) {
|
|
111
|
+
const callee = pathNode.node.callee;
|
|
112
|
+
if (import_core.types.isIdentifier(callee)) {
|
|
113
|
+
return isElementFactoryIdentifier(callee.name);
|
|
114
|
+
}
|
|
115
|
+
return import_core.types.isMemberExpression(callee) && import_core.types.isIdentifier(callee.object, { name: "React" }) && import_core.types.isIdentifier(callee.property, { name: "createElement" });
|
|
116
|
+
}
|
|
117
|
+
function getRootJsxIdentifierName(name) {
|
|
118
|
+
if (import_core.types.isJSXIdentifier(name)) {
|
|
119
|
+
return name.name;
|
|
120
|
+
}
|
|
121
|
+
if (import_core.types.isJSXMemberExpression(name)) {
|
|
122
|
+
return getRootJsxIdentifierName(name.object);
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
function isStyledModuleImport(binding) {
|
|
127
|
+
if (!binding) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (!binding.path.isImportSpecifier() && !binding.path.isImportDefaultSpecifier() && !binding.path.isImportNamespaceSpecifier()) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
const source = binding.path.parentPath.isImportDeclaration() ? binding.path.parentPath.node.source.value : null;
|
|
134
|
+
if (typeof source !== "string") {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
const normalized = source.replace(/\\/g, "/");
|
|
138
|
+
return normalized === "./styled" || normalized === "../styled" || normalized.endsWith("/styled");
|
|
139
|
+
}
|
|
46
140
|
function isSupportedComponentInit(node) {
|
|
47
141
|
if (!node) {
|
|
48
142
|
return false;
|
|
@@ -58,13 +152,104 @@ function isSupportedComponentInit(node) {
|
|
|
58
152
|
}
|
|
59
153
|
return import_core.types.isMemberExpression(node.callee) && import_core.types.isIdentifier(node.callee.object, { name: "React" }) && import_core.types.isIdentifier(node.callee.property) && (node.callee.property.name === "memo" || node.callee.property.name === "forwardRef");
|
|
60
154
|
}
|
|
61
|
-
function
|
|
155
|
+
function hasSourcePropBinding(pattern) {
|
|
156
|
+
return pattern.properties.some((property) => {
|
|
157
|
+
if (!import_core.types.isObjectProperty(property)) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
return import_core.types.isIdentifier(property.key) && property.key.name === JSX_SOURCE_PROP;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function injectSourcePropBinding(pattern) {
|
|
164
|
+
if (hasSourcePropBinding(pattern)) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const sourceBinding = import_core.types.objectProperty(
|
|
168
|
+
import_core.types.identifier(JSX_SOURCE_PROP),
|
|
169
|
+
import_core.types.identifier(SOURCE_PROP_LOCAL),
|
|
170
|
+
false,
|
|
171
|
+
false
|
|
172
|
+
);
|
|
173
|
+
const restIndex = pattern.properties.findIndex(
|
|
174
|
+
(property) => import_core.types.isRestElement(property)
|
|
175
|
+
);
|
|
176
|
+
if (restIndex === -1) {
|
|
177
|
+
pattern.properties.push(sourceBinding);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
pattern.properties.splice(restIndex, 0, sourceBinding);
|
|
181
|
+
}
|
|
182
|
+
function injectSourcePropIntoIdentifierParam(node, param) {
|
|
183
|
+
if (!import_core.types.isBlockStatement(node.body)) {
|
|
184
|
+
node.body = import_core.types.blockStatement([import_core.types.returnStatement(node.body)]);
|
|
185
|
+
}
|
|
186
|
+
const alreadyInjected = node.body.body.some(
|
|
187
|
+
(statement) => import_core.types.isVariableDeclaration(statement) && statement.declarations.some(
|
|
188
|
+
(declaration) => import_core.types.isIdentifier(declaration.id) && declaration.id.name === SOURCE_PROPS_REST
|
|
189
|
+
)
|
|
190
|
+
);
|
|
191
|
+
if (alreadyInjected) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
node.body.body.unshift(
|
|
195
|
+
import_core.types.variableDeclaration("const", [
|
|
196
|
+
import_core.types.variableDeclarator(
|
|
197
|
+
import_core.types.objectPattern([
|
|
198
|
+
import_core.types.objectProperty(
|
|
199
|
+
import_core.types.identifier(JSX_SOURCE_PROP),
|
|
200
|
+
import_core.types.identifier(SOURCE_PROP_LOCAL),
|
|
201
|
+
false,
|
|
202
|
+
false
|
|
203
|
+
),
|
|
204
|
+
import_core.types.restElement(import_core.types.identifier(SOURCE_PROPS_REST))
|
|
205
|
+
]),
|
|
206
|
+
param
|
|
207
|
+
)
|
|
208
|
+
]),
|
|
209
|
+
import_core.types.expressionStatement(
|
|
210
|
+
import_core.types.assignmentExpression(
|
|
211
|
+
"=",
|
|
212
|
+
import_core.types.identifier(param.name),
|
|
213
|
+
import_core.types.identifier(SOURCE_PROPS_REST)
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
function injectSourcePropIntoFunctionParams(node) {
|
|
219
|
+
const firstParam = node.params[0];
|
|
220
|
+
if (!firstParam) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (import_core.types.isObjectPattern(firstParam)) {
|
|
224
|
+
injectSourcePropBinding(firstParam);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (import_core.types.isIdentifier(firstParam)) {
|
|
228
|
+
injectSourcePropIntoIdentifierParam(node, firstParam);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function injectSourcePropIntoExpression(node) {
|
|
232
|
+
if (!node) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (import_core.types.isFunctionExpression(node) || import_core.types.isArrowFunctionExpression(node)) {
|
|
236
|
+
injectSourcePropIntoFunctionParams(node);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (!import_core.types.isCallExpression(node)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const firstArg = node.arguments[0];
|
|
243
|
+
if (firstArg && !import_core.types.isSpreadElement(firstArg) && (import_core.types.isFunctionExpression(firstArg) || import_core.types.isArrowFunctionExpression(firstArg))) {
|
|
244
|
+
injectSourcePropIntoFunctionParams(firstArg);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function getSourceValue(state, loc, projectRoot) {
|
|
62
248
|
const filename = state.file?.opts?.filename;
|
|
63
249
|
if (!filename || !loc) {
|
|
64
250
|
return null;
|
|
65
251
|
}
|
|
66
|
-
|
|
67
|
-
return `${relPath}:${loc.line}:${loc.column + 1}`;
|
|
252
|
+
return toRelativeSource(filename, loc, projectRoot);
|
|
68
253
|
}
|
|
69
254
|
function buildAssignment(name, sourceValue) {
|
|
70
255
|
return import_core.types.expressionStatement(
|
|
@@ -75,13 +260,98 @@ function buildAssignment(name, sourceValue) {
|
|
|
75
260
|
)
|
|
76
261
|
);
|
|
77
262
|
}
|
|
78
|
-
function
|
|
263
|
+
function buildIntrinsicSourceHelper() {
|
|
264
|
+
return import_core.types.functionDeclaration(
|
|
265
|
+
import_core.types.identifier("_markIntrinsicElementSource"),
|
|
266
|
+
[import_core.types.identifier("element"), import_core.types.identifier("source")],
|
|
267
|
+
import_core.types.blockStatement([
|
|
268
|
+
import_core.types.variableDeclaration("const", [
|
|
269
|
+
import_core.types.variableDeclarator(
|
|
270
|
+
import_core.types.identifier("registryKey"),
|
|
271
|
+
import_core.types.callExpression(
|
|
272
|
+
import_core.types.memberExpression(import_core.types.identifier("Symbol"), import_core.types.identifier("for")),
|
|
273
|
+
[import_core.types.stringLiteral(JSX_SOURCE_REGISTRY_SYMBOL)]
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
]),
|
|
277
|
+
import_core.types.variableDeclaration("let", [
|
|
278
|
+
import_core.types.variableDeclarator(
|
|
279
|
+
import_core.types.identifier("registry"),
|
|
280
|
+
import_core.types.memberExpression(import_core.types.identifier("globalThis"), import_core.types.identifier("registryKey"), true)
|
|
281
|
+
)
|
|
282
|
+
]),
|
|
283
|
+
import_core.types.ifStatement(
|
|
284
|
+
import_core.types.unaryExpression(
|
|
285
|
+
"!",
|
|
286
|
+
import_core.types.binaryExpression("instanceof", import_core.types.identifier("registry"), import_core.types.identifier("WeakMap"))
|
|
287
|
+
),
|
|
288
|
+
import_core.types.blockStatement([
|
|
289
|
+
import_core.types.expressionStatement(
|
|
290
|
+
import_core.types.assignmentExpression(
|
|
291
|
+
"=",
|
|
292
|
+
import_core.types.identifier("registry"),
|
|
293
|
+
import_core.types.assignmentExpression(
|
|
294
|
+
"=",
|
|
295
|
+
import_core.types.memberExpression(import_core.types.identifier("globalThis"), import_core.types.identifier("registryKey"), true),
|
|
296
|
+
import_core.types.newExpression(import_core.types.identifier("WeakMap"), [])
|
|
297
|
+
)
|
|
298
|
+
)
|
|
299
|
+
)
|
|
300
|
+
])
|
|
301
|
+
),
|
|
302
|
+
import_core.types.ifStatement(
|
|
303
|
+
import_core.types.logicalExpression(
|
|
304
|
+
"&&",
|
|
305
|
+
import_core.types.identifier("element"),
|
|
306
|
+
import_core.types.logicalExpression(
|
|
307
|
+
"&&",
|
|
308
|
+
import_core.types.binaryExpression("===", import_core.types.unaryExpression("typeof", import_core.types.identifier("element")), import_core.types.stringLiteral("object")),
|
|
309
|
+
import_core.types.binaryExpression(
|
|
310
|
+
"===",
|
|
311
|
+
import_core.types.unaryExpression("typeof", import_core.types.memberExpression(import_core.types.identifier("element"), import_core.types.identifier("props"))),
|
|
312
|
+
import_core.types.stringLiteral("object")
|
|
313
|
+
)
|
|
314
|
+
)
|
|
315
|
+
),
|
|
316
|
+
import_core.types.blockStatement([
|
|
317
|
+
import_core.types.expressionStatement(
|
|
318
|
+
import_core.types.callExpression(
|
|
319
|
+
import_core.types.memberExpression(import_core.types.identifier("registry"), import_core.types.identifier("set")),
|
|
320
|
+
[import_core.types.memberExpression(import_core.types.identifier("element"), import_core.types.identifier("props")), import_core.types.identifier("source")]
|
|
321
|
+
)
|
|
322
|
+
)
|
|
323
|
+
])
|
|
324
|
+
),
|
|
325
|
+
import_core.types.returnStatement(import_core.types.identifier("element"))
|
|
326
|
+
])
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
function ensureIntrinsicSourceHelper(programPath, state) {
|
|
330
|
+
if (state.injectedIntrinsicHelper) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const alreadyExists = programPath.node.body.some(
|
|
334
|
+
(node) => import_core.types.isFunctionDeclaration(node) && import_core.types.isIdentifier(node.id, { name: "_markIntrinsicElementSource" })
|
|
335
|
+
);
|
|
336
|
+
if (!alreadyExists) {
|
|
337
|
+
programPath.unshiftContainer("body", buildIntrinsicSourceHelper());
|
|
338
|
+
}
|
|
339
|
+
state.injectedIntrinsicHelper = true;
|
|
340
|
+
}
|
|
341
|
+
function visitDeclaration(declarationPath, insertAfterPath, state, seen, projectRoot) {
|
|
79
342
|
if (declarationPath.isFunctionDeclaration() || declarationPath.isClassDeclaration()) {
|
|
80
343
|
const name = declarationPath.node.id?.name;
|
|
81
344
|
if (!name || !isComponentName(name) || seen.has(name)) {
|
|
82
345
|
return;
|
|
83
346
|
}
|
|
84
|
-
|
|
347
|
+
if (declarationPath.isFunctionDeclaration()) {
|
|
348
|
+
injectSourcePropIntoFunctionParams(declarationPath.node);
|
|
349
|
+
}
|
|
350
|
+
const sourceValue = getSourceValue(
|
|
351
|
+
state,
|
|
352
|
+
declarationPath.node.loc?.start,
|
|
353
|
+
projectRoot
|
|
354
|
+
);
|
|
85
355
|
if (!sourceValue) {
|
|
86
356
|
return;
|
|
87
357
|
}
|
|
@@ -92,38 +362,128 @@ function visitDeclaration(declarationPath, insertAfterPath, state, seen) {
|
|
|
92
362
|
if (!declarationPath.isVariableDeclaration()) {
|
|
93
363
|
return;
|
|
94
364
|
}
|
|
95
|
-
const assignments = declarationPath.node.declarations.flatMap(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
365
|
+
const assignments = declarationPath.node.declarations.flatMap(
|
|
366
|
+
(declarator) => {
|
|
367
|
+
if (!import_core.types.isIdentifier(declarator.id) || !isComponentName(declarator.id.name) || seen.has(declarator.id.name)) {
|
|
368
|
+
return [];
|
|
369
|
+
}
|
|
370
|
+
if (!declarator.init) {
|
|
371
|
+
return [];
|
|
372
|
+
}
|
|
373
|
+
if (!isSupportedComponentInit(declarator.init)) {
|
|
374
|
+
return [];
|
|
375
|
+
}
|
|
376
|
+
injectSourcePropIntoExpression(declarator.init);
|
|
377
|
+
const sourceValue = getSourceValue(
|
|
378
|
+
state,
|
|
379
|
+
declarator.loc?.start ?? declarator.init.loc?.start,
|
|
380
|
+
projectRoot
|
|
381
|
+
);
|
|
382
|
+
if (!sourceValue) {
|
|
383
|
+
return [];
|
|
384
|
+
}
|
|
385
|
+
seen.add(declarator.id.name);
|
|
386
|
+
return [buildAssignment(declarator.id.name, sourceValue)];
|
|
108
387
|
}
|
|
109
|
-
|
|
110
|
-
return [buildAssignment(declarator.id.name, sourceValue)];
|
|
111
|
-
});
|
|
388
|
+
);
|
|
112
389
|
if (assignments.length > 0) {
|
|
113
390
|
insertAfterPath.insertAfter(assignments);
|
|
114
391
|
}
|
|
115
392
|
}
|
|
116
393
|
function babelInjectComponentSource(options = {}) {
|
|
117
|
-
const {
|
|
394
|
+
const {
|
|
395
|
+
injectJsxSource = true,
|
|
396
|
+
injectComponentSource = true,
|
|
397
|
+
projectRoot
|
|
398
|
+
} = options;
|
|
118
399
|
return {
|
|
119
400
|
name: "babel-inject-component-source",
|
|
120
401
|
visitor: {
|
|
402
|
+
CallExpression(pathNode, state) {
|
|
403
|
+
if (!injectJsxSource) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (!isReactElementFactoryCall(pathNode)) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (pathNode.parentPath.isCallExpression() && import_core.types.isIdentifier(pathNode.parentPath.node.callee, {
|
|
410
|
+
name: "_markIntrinsicElementSource"
|
|
411
|
+
})) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const sourceValue = getSourceValue(
|
|
415
|
+
state,
|
|
416
|
+
pathNode.node.loc?.start,
|
|
417
|
+
projectRoot
|
|
418
|
+
);
|
|
419
|
+
if (!sourceValue) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const programPath = pathNode.findParent((parent) => parent.isProgram());
|
|
423
|
+
if (!programPath || !programPath.isProgram()) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
ensureIntrinsicSourceHelper(programPath, state);
|
|
427
|
+
pathNode.replaceWith(
|
|
428
|
+
import_core.types.callExpression(import_core.types.identifier("_markIntrinsicElementSource"), [
|
|
429
|
+
pathNode.node,
|
|
430
|
+
import_core.types.stringLiteral(sourceValue)
|
|
431
|
+
])
|
|
432
|
+
);
|
|
433
|
+
pathNode.skip();
|
|
434
|
+
},
|
|
435
|
+
JSXElement: {
|
|
436
|
+
exit(pathNode, state) {
|
|
437
|
+
if (!injectJsxSource) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (!isIntrinsicElementTag(pathNode.node.openingElement.name)) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (pathNode.parentPath.isCallExpression() && import_core.types.isIdentifier(pathNode.parentPath.node.callee, { name: "_markIntrinsicElementSource" })) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
const sourceValue = getSourceValue(
|
|
447
|
+
state,
|
|
448
|
+
pathNode.node.openingElement.loc?.start,
|
|
449
|
+
projectRoot
|
|
450
|
+
);
|
|
451
|
+
if (!sourceValue) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
const programPath = pathNode.findParent((parent) => parent.isProgram());
|
|
455
|
+
if (!programPath || !programPath.isProgram()) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
ensureIntrinsicSourceHelper(programPath, state);
|
|
459
|
+
const wrappedNode = import_core.types.callExpression(import_core.types.identifier("_markIntrinsicElementSource"), [
|
|
460
|
+
pathNode.node,
|
|
461
|
+
import_core.types.stringLiteral(sourceValue)
|
|
462
|
+
]);
|
|
463
|
+
if (pathNode.parentPath.isJSXElement() || pathNode.parentPath.isJSXFragment()) {
|
|
464
|
+
pathNode.replaceWith(import_core.types.jsxExpressionContainer(wrappedNode));
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
if (pathNode.parentPath.isJSXExpressionContainer()) {
|
|
468
|
+
pathNode.parentPath.replaceWith(import_core.types.jsxExpressionContainer(wrappedNode));
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
pathNode.replaceWith(wrappedNode);
|
|
472
|
+
}
|
|
473
|
+
},
|
|
121
474
|
JSXOpeningElement(pathNode, state) {
|
|
122
475
|
if (!injectJsxSource) {
|
|
123
476
|
return;
|
|
124
477
|
}
|
|
478
|
+
if (!isCustomComponentTag(pathNode.node.name)) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const rootIdentifierName = getRootJsxIdentifierName(pathNode.node.name);
|
|
482
|
+
if (rootIdentifierName && isExternalToProjectRoot(state.file?.opts?.filename, projectRoot) && isStyledModuleImport(pathNode.scope.getBinding(rootIdentifierName))) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
125
485
|
const hasSourceProp = pathNode.node.attributes.some(
|
|
126
|
-
(attr) => import_core.types.isJSXAttribute(attr) && import_core.types.isJSXIdentifier(attr.name) && attr.name.name ===
|
|
486
|
+
(attr) => import_core.types.isJSXAttribute(attr) && import_core.types.isJSXIdentifier(attr.name) && attr.name.name === JSX_SOURCE_PROP
|
|
127
487
|
);
|
|
128
488
|
if (hasSourceProp) {
|
|
129
489
|
return;
|
|
@@ -135,8 +495,10 @@ function babelInjectComponentSource(options = {}) {
|
|
|
135
495
|
}
|
|
136
496
|
pathNode.node.attributes.push(
|
|
137
497
|
import_core.types.jsxAttribute(
|
|
138
|
-
import_core.types.jsxIdentifier(
|
|
139
|
-
import_core.types.stringLiteral(
|
|
498
|
+
import_core.types.jsxIdentifier(JSX_SOURCE_PROP),
|
|
499
|
+
import_core.types.stringLiteral(
|
|
500
|
+
getSourceValue(state, loc, projectRoot) ?? `${filename.replace(/\\/g, "/")}:${loc.line}:${loc.column + 1}`
|
|
501
|
+
)
|
|
140
502
|
)
|
|
141
503
|
);
|
|
142
504
|
},
|
|
@@ -149,11 +511,11 @@ function babelInjectComponentSource(options = {}) {
|
|
|
149
511
|
if (childPath.isExportNamedDeclaration() || childPath.isExportDefaultDeclaration()) {
|
|
150
512
|
const declarationPath = childPath.get("declaration");
|
|
151
513
|
if (!Array.isArray(declarationPath) && declarationPath.node) {
|
|
152
|
-
visitDeclaration(declarationPath, childPath, state, seen);
|
|
514
|
+
visitDeclaration(declarationPath, childPath, state, seen, projectRoot);
|
|
153
515
|
}
|
|
154
516
|
continue;
|
|
155
517
|
}
|
|
156
|
-
visitDeclaration(childPath, childPath, state, seen);
|
|
518
|
+
visitDeclaration(childPath, childPath, state, seen, projectRoot);
|
|
157
519
|
}
|
|
158
520
|
}
|
|
159
521
|
}
|
|
@@ -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;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,kBAA0D;;;ACDnD,IAAM,cAAc;;;ADiB3B,SAAS,gBAAgB,MAAc;AACrC,SAAO,SAAS,KAAK,IAAI;AAC3B;AAEA,SAAS,yBAAyB,MAAgD;AAChF,MAAI,CAAC,MAAM;AACT,WAAO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AAW;AAAA,UAC7C,CAAC,SAAS,YAAAA,MAAE,eAAe,IAAI,KAAK,YAAAA,MAAE,gBAAgB,KAAK,IAAI,KAAK,KAAK,KAAK,SAAS;AAAA,QACzF;AACA,YAAI,eAAe;AACjB;AAAA,QACF;AAEA,cAAM,WAAW,MAAM,MAAM,MAAM;AACnC,cAAM,MAAM,SAAS,KAAK,KAAK;AAC/B,YAAI,CAAC,YAAY,CAAC,KAAK;AACrB;AAAA,QACF;AAEA,iBAAS,KAAK,WAAW;AAAA,UACvB,YAAAA,MAAE;AAAA,YACA,YAAAA,MAAE,cAAc,WAAW;AAAA,YAC3B,YAAAA,MAAE,cAAc,eAAe,OAAO,GAAG,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":["t","path"]}
|
|
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 {\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0D;;;ACAnD,IAAM,cAAc;AACpB,IAAM,kBAAkB;AACxB,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,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ter-DLWo_ABo.cjs';
|
|
2
3
|
|
|
3
|
-
type BabelInjectComponentSourceOptions =
|
|
4
|
-
injectJsxSource?: boolean;
|
|
5
|
-
injectComponentSource?: boolean;
|
|
6
|
-
};
|
|
4
|
+
type BabelInjectComponentSourceOptions = SourceInjectionOptions;
|
|
7
5
|
type BabelState = {
|
|
8
6
|
file?: {
|
|
9
7
|
opts?: {
|
|
10
8
|
filename?: string;
|
|
11
9
|
};
|
|
12
10
|
};
|
|
11
|
+
injectedIntrinsicHelper?: boolean;
|
|
13
12
|
};
|
|
14
13
|
declare function babelInjectComponentSource(options?: BabelInjectComponentSourceOptions): PluginObj<BabelState>;
|
|
15
14
|
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { PluginObj } from '@babel/core';
|
|
2
|
+
import { b as SourceInjectionOptions } from './sourceAdapter-DLWo_ABo.js';
|
|
2
3
|
|
|
3
|
-
type BabelInjectComponentSourceOptions =
|
|
4
|
-
injectJsxSource?: boolean;
|
|
5
|
-
injectComponentSource?: boolean;
|
|
6
|
-
};
|
|
4
|
+
type BabelInjectComponentSourceOptions = SourceInjectionOptions;
|
|
7
5
|
type BabelState = {
|
|
8
6
|
file?: {
|
|
9
7
|
opts?: {
|
|
10
8
|
filename?: string;
|
|
11
9
|
};
|
|
12
10
|
};
|
|
11
|
+
injectedIntrinsicHelper?: boolean;
|
|
13
12
|
};
|
|
14
13
|
declare function babelInjectComponentSource(options?: BabelInjectComponentSourceOptions): PluginObj<BabelState>;
|
|
15
14
|
|