react-code-locator 0.1.14 → 0.1.16

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.
@@ -0,0 +1,308 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/unplugin.ts
21
+ var unplugin_exports = {};
22
+ __export(unplugin_exports, {
23
+ default: () => unplugin_default,
24
+ esbuildPlugin: () => esbuildPlugin,
25
+ rollupPlugin: () => rollupPlugin,
26
+ rspackPlugin: () => rspackPlugin,
27
+ unplugin: () => unplugin,
28
+ vitePlugin: () => vitePlugin,
29
+ webpackPlugin: () => webpackPlugin
30
+ });
31
+ module.exports = __toCommonJS(unplugin_exports);
32
+ var import_unplugin = require("unplugin");
33
+
34
+ // src/core/transform.ts
35
+ var import_acorn = require("acorn");
36
+ var import_astring = require("astring");
37
+ var import_estree_walker = require("estree-walker");
38
+
39
+ // src/constants.ts
40
+ var SOURCE_PROP = "__componentSourceLoc";
41
+ var JSX_SOURCE_PROP = "$componentSourceLoc";
42
+ var JSX_SOURCE_REGISTRY_SYMBOL = "react-code-locator.jsxSourceRegistry";
43
+
44
+ // src/core/transform.ts
45
+ function toRelativeSource(filename, loc, projectRoot) {
46
+ const root = projectRoot || process.cwd();
47
+ const relativePath = filename.startsWith(root) ? filename.slice(root.length + 1) : filename;
48
+ return `${relativePath}:${loc.line}:${loc.column + 1}`;
49
+ }
50
+ function isComponentName(name) {
51
+ return /^[A-Z]/.test(name);
52
+ }
53
+ function isReactElementFactoryCall(node) {
54
+ const callee = node.callee;
55
+ if (callee.type === "Identifier") {
56
+ const name = callee.name;
57
+ return [
58
+ "jsx",
59
+ "jsxs",
60
+ "jsxDEV",
61
+ "_jsx",
62
+ "_jsxs",
63
+ "_jsxDEV",
64
+ "createElement"
65
+ ].includes(name);
66
+ }
67
+ if (callee.type === "MemberExpression") {
68
+ const obj = callee.object;
69
+ const prop = callee.property;
70
+ if (obj.type === "Identifier" && obj.name === "React" && prop.type === "Identifier" && prop.name === "createElement") {
71
+ return true;
72
+ }
73
+ }
74
+ return false;
75
+ }
76
+ function isSupportedComponentInit(node) {
77
+ if (!node) return false;
78
+ if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression") {
79
+ return true;
80
+ }
81
+ if (node.type !== "CallExpression") return false;
82
+ const callee = node.callee;
83
+ if (callee.type === "Identifier") {
84
+ return ["memo", "forwardRef"].includes(callee.name);
85
+ }
86
+ if (callee.type === "MemberExpression") {
87
+ const obj = callee.object;
88
+ const prop = callee.property;
89
+ if (obj.type === "Identifier" && obj.name === "React" && prop.type === "Identifier") {
90
+ return ["memo", "forwardRef"].includes(prop.name);
91
+ }
92
+ }
93
+ return false;
94
+ }
95
+ function createSourceAssignment(name, sourceValue) {
96
+ return {
97
+ type: "ExpressionStatement",
98
+ expression: {
99
+ type: "AssignmentExpression",
100
+ operator: "=",
101
+ left: {
102
+ type: "MemberExpression",
103
+ object: { type: "Identifier", name },
104
+ property: { type: "Identifier", name: SOURCE_PROP },
105
+ computed: false
106
+ },
107
+ right: { type: "Literal", value: sourceValue }
108
+ }
109
+ };
110
+ }
111
+ function createMarkElementHelper() {
112
+ const code = `
113
+ function _markReactElementSource(element, source) {
114
+ const registryKey = Symbol.for("${JSX_SOURCE_REGISTRY_SYMBOL}");
115
+ let registry = globalThis[registryKey];
116
+ if (!(registry instanceof WeakMap)) {
117
+ registry = globalThis[registryKey] = new WeakMap();
118
+ }
119
+ if (element && typeof element === "object" && typeof element.props === "object") {
120
+ registry.set(element.props, source);
121
+ }
122
+ return element;
123
+ }
124
+ `;
125
+ return (0, import_acorn.parse)(code, { ecmaVersion: "latest" }).body[0];
126
+ }
127
+ function wrapWithMarkElement(node, sourceValue) {
128
+ return {
129
+ type: "CallExpression",
130
+ callee: { type: "Identifier", name: "_markReactElementSource" },
131
+ arguments: [node, { type: "Literal", value: sourceValue }],
132
+ optional: false
133
+ };
134
+ }
135
+ function transformSource(code, options) {
136
+ const {
137
+ filename,
138
+ projectRoot = process.cwd(),
139
+ injectJsxSource = true,
140
+ injectComponentSource = true
141
+ } = options;
142
+ let ast;
143
+ try {
144
+ ast = (0, import_acorn.parse)(code, {
145
+ ecmaVersion: "latest",
146
+ sourceType: "module",
147
+ ecmaFeatures: { jsx: true },
148
+ locations: true,
149
+ ranges: true
150
+ });
151
+ } catch (err) {
152
+ return null;
153
+ }
154
+ let modified = false;
155
+ let needsHelper = false;
156
+ const seenComponents = /* @__PURE__ */ new Set();
157
+ const assignments = [];
158
+ (0, import_estree_walker.walk)(ast, {
159
+ enter(node, parent, key, index) {
160
+ if (injectJsxSource && node.type === "CallExpression") {
161
+ if (isReactElementFactoryCall(node)) {
162
+ const loc = node.loc;
163
+ if (loc) {
164
+ const sourceValue = toRelativeSource(filename, loc.start, projectRoot);
165
+ const wrapped = wrapWithMarkElement(node, sourceValue);
166
+ this.replace(wrapped);
167
+ needsHelper = true;
168
+ modified = true;
169
+ }
170
+ }
171
+ }
172
+ if (injectJsxSource && node.type === "JSXElement") {
173
+ const opening = node.openingElement;
174
+ const loc = opening.loc;
175
+ if (loc) {
176
+ const sourceValue = toRelativeSource(filename, loc.start, projectRoot);
177
+ const name = opening.name;
178
+ if (name.type === "JSXIdentifier") {
179
+ if (name.name[0] === name.name[0].toLowerCase()) {
180
+ } else {
181
+ const sourceAttr = {
182
+ type: "JSXAttribute",
183
+ name: { type: "JSXIdentifier", name: JSX_SOURCE_PROP },
184
+ value: { type: "Literal", value: sourceValue }
185
+ };
186
+ opening.attributes.push(sourceAttr);
187
+ modified = true;
188
+ }
189
+ }
190
+ }
191
+ }
192
+ if (injectComponentSource && node.type === "FunctionDeclaration") {
193
+ const name = node.id?.name;
194
+ if (name && isComponentName(name) && !seenComponents.has(name)) {
195
+ const loc = node.loc;
196
+ if (loc) {
197
+ const sourceValue = toRelativeSource(filename, loc.start, projectRoot);
198
+ const assignment = createSourceAssignment(name, sourceValue);
199
+ assignments.push({ node, parent, assignment });
200
+ seenComponents.add(name);
201
+ modified = true;
202
+ }
203
+ }
204
+ }
205
+ if (injectComponentSource && node.type === "VariableDeclarator") {
206
+ const id = node.id;
207
+ if (id.type === "Identifier" && isComponentName(id.name) && !seenComponents.has(id.name)) {
208
+ const init = node.init;
209
+ if (init && isSupportedComponentInit(init)) {
210
+ const loc = node.loc || init.loc;
211
+ if (loc) {
212
+ const sourceValue = toRelativeSource(filename, loc.start, projectRoot);
213
+ const assignment = createSourceAssignment(id.name, sourceValue);
214
+ assignments.push({ node, parent, assignment });
215
+ seenComponents.add(id.name);
216
+ modified = true;
217
+ }
218
+ }
219
+ }
220
+ }
221
+ }
222
+ });
223
+ if (!modified) {
224
+ return null;
225
+ }
226
+ if (needsHelper) {
227
+ const helper = createMarkElementHelper();
228
+ const exists = ast.body.some(
229
+ (n) => n.type === "FunctionDeclaration" && n.id?.name === "_markReactElementSource"
230
+ );
231
+ if (!exists) {
232
+ ast.body.unshift(helper);
233
+ }
234
+ }
235
+ for (const { node, parent, assignment } of assignments.reverse()) {
236
+ if (parent && parent.type === "Program") {
237
+ const index = ast.body.indexOf(node);
238
+ if (index !== -1) {
239
+ ast.body.splice(index + 1, 0, assignment);
240
+ }
241
+ } else if (parent && parent.type === "ExportNamedDeclaration") {
242
+ const exportParent = ast.body.find(
243
+ (n) => n.type === "ExportNamedDeclaration" && n.declaration === parent
244
+ );
245
+ if (exportParent) {
246
+ const index = ast.body.indexOf(exportParent);
247
+ ast.body.splice(index + 1, 0, assignment);
248
+ }
249
+ } else if (parent && parent.type === "ExportDefaultDeclaration") {
250
+ const index = ast.body.indexOf(parent);
251
+ ast.body.splice(index + 1, 0, assignment);
252
+ }
253
+ }
254
+ const result = (0, import_astring.generate)(ast, { indent: " " });
255
+ return { code: result };
256
+ }
257
+
258
+ // src/unplugin.ts
259
+ var DEFAULT_INCLUDE = /\.([jt]sx)$/;
260
+ var DEFAULT_EXCLUDE = /node_modules/;
261
+ function shouldTransform(id, include, exclude) {
262
+ const includePatterns = Array.isArray(include) ? include : [include];
263
+ const excludePatterns = Array.isArray(exclude) ? exclude : [exclude];
264
+ if (excludePatterns.some((pattern) => pattern.test(id))) {
265
+ return false;
266
+ }
267
+ return includePatterns.some((pattern) => pattern.test(id));
268
+ }
269
+ var unplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
270
+ const {
271
+ include = DEFAULT_INCLUDE,
272
+ exclude = DEFAULT_EXCLUDE,
273
+ projectRoot = process.cwd(),
274
+ injectComponentSource = true,
275
+ injectJsxSource = true
276
+ } = options;
277
+ return {
278
+ name: "react-code-locator",
279
+ transform(code, id) {
280
+ if (!shouldTransform(id, include, exclude)) {
281
+ return null;
282
+ }
283
+ const result = transformSource(code, {
284
+ filename: id,
285
+ projectRoot,
286
+ injectComponentSource,
287
+ injectJsxSource
288
+ });
289
+ return result;
290
+ }
291
+ };
292
+ });
293
+ var vitePlugin = unplugin.vite;
294
+ var webpackPlugin = unplugin.webpack;
295
+ var rollupPlugin = unplugin.rollup;
296
+ var esbuildPlugin = unplugin.esbuild;
297
+ var rspackPlugin = unplugin.rspack;
298
+ var unplugin_default = unplugin;
299
+ // Annotate the CommonJS export names for ESM import in node:
300
+ 0 && (module.exports = {
301
+ esbuildPlugin,
302
+ rollupPlugin,
303
+ rspackPlugin,
304
+ unplugin,
305
+ vitePlugin,
306
+ webpackPlugin
307
+ });
308
+ //# sourceMappingURL=unplugin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/unplugin.ts","../src/core/transform.ts","../src/constants.ts"],"sourcesContent":["/**\n * Unplugin-based universal adapter for all build tools\n * Supports: Vite, Webpack, Rollup, esbuild, Rspack\n * \n * Zero-dependency transform using acorn instead of Babel\n */\n\nimport { createUnplugin, type UnpluginInstance, type UnpluginOptions } from \"unplugin\";\nimport { transformSource, type TransformOptions } from \"./core/transform\";\n\nexport interface ReactCodeLocatorOptions extends Omit<TransformOptions, 'filename'> {\n /** \n * Enable source transform for component definitions\n * @default true\n */\n injectComponentSource?: boolean;\n \n /** \n * Enable source transform for JSX call sites\n * @default true\n */\n injectJsxSource?: boolean;\n \n /**\n * Project root for relative path calculation\n * @default process.cwd()\n */\n projectRoot?: string;\n \n /**\n * Include filter for file paths\n * @default /\\.[jt]sx$/\n */\n include?: RegExp | RegExp[];\n \n /**\n * Exclude filter for file paths\n * @default /node_modules/\n */\n exclude?: RegExp | RegExp[];\n}\n\nexport type { TransformOptions };\n\nconst DEFAULT_INCLUDE = /\\.([jt]sx)$/;\nconst DEFAULT_EXCLUDE = /node_modules/;\n\nfunction shouldTransform(id: string, include: RegExp | RegExp[], exclude: RegExp | RegExp[]): boolean {\n const includePatterns = Array.isArray(include) ? include : [include];\n const excludePatterns = Array.isArray(exclude) ? exclude : [exclude];\n \n // Check exclude first\n if (excludePatterns.some(pattern => pattern.test(id))) {\n return false;\n }\n \n // Then check include\n return includePatterns.some(pattern => pattern.test(id));\n}\n\nexport const unplugin: UnpluginInstance<ReactCodeLocatorOptions | undefined, false> = \n createUnplugin((options = {}) => {\n const {\n include = DEFAULT_INCLUDE,\n exclude = DEFAULT_EXCLUDE,\n projectRoot = process.cwd(),\n injectComponentSource = true,\n injectJsxSource = true,\n } = options;\n\n return {\n name: \"react-code-locator\",\n \n transform(code, id) {\n // Skip if doesn't match patterns\n if (!shouldTransform(id, include, exclude)) {\n return null;\n }\n\n // Perform transform using acorn (zero-dependency)\n const result = transformSource(code, {\n filename: id,\n projectRoot,\n injectComponentSource,\n injectJsxSource,\n });\n\n return result;\n },\n } as UnpluginOptions;\n });\n\n// Export individual build tool adapters\nexport const vitePlugin = unplugin.vite;\nexport const webpackPlugin = unplugin.webpack;\nexport const rollupPlugin = unplugin.rollup;\nexport const esbuildPlugin = unplugin.esbuild;\nexport const rspackPlugin = unplugin.rspack;\n\n// Default export for direct usage\nexport default unplugin;\n","/**\n * Zero-dependency source transform using acorn\n * No Babel required - pure JavaScript AST manipulation\n */\n\nimport { parse, type Node as AcornNode } from \"acorn\";\nimport { generate } from \"astring\";\nimport { walk } from \"estree-walker\";\nimport type {\n Node,\n Program,\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n VariableDeclarator,\n CallExpression,\n MemberExpression,\n Identifier,\n ExpressionStatement,\n AssignmentExpression,\n} from \"estree\";\nimport { SOURCE_PROP, JSX_SOURCE_PROP, JSX_SOURCE_REGISTRY_SYMBOL } from \"../constants\";\n\nexport interface TransformOptions {\n filename: string;\n projectRoot?: string;\n injectJsxSource?: boolean;\n injectComponentSource?: boolean;\n}\n\ninterface Location {\n line: number;\n column: number;\n}\n\nfunction toRelativeSource(filename: string, loc: Location, projectRoot?: string): string {\n const root = projectRoot || process.cwd();\n const relativePath = filename.startsWith(root) \n ? filename.slice(root.length + 1) \n : filename;\n return `${relativePath}:${loc.line}:${loc.column + 1}`;\n}\n\nfunction isComponentName(name: string): boolean {\n return /^[A-Z]/.test(name);\n}\n\nfunction isReactElementFactoryCall(node: CallExpression): boolean {\n const callee = node.callee;\n \n if (callee.type === \"Identifier\") {\n const name = callee.name;\n return [\n \"jsx\", \"jsxs\", \"jsxDEV\",\n \"_jsx\", \"_jsxs\", \"_jsxDEV\",\n \"createElement\"\n ].includes(name);\n }\n \n // React.createElement\n if (callee.type === \"MemberExpression\") {\n const obj = callee.object;\n const prop = callee.property;\n if (obj.type === \"Identifier\" && obj.name === \"React\" && \n prop.type === \"Identifier\" && prop.name === \"createElement\") {\n return true;\n }\n }\n \n return false;\n}\n\nfunction isSupportedComponentInit(\n node: Node | null\n): boolean {\n if (!node) return false;\n \n if (node.type === \"ArrowFunctionExpression\" || \n node.type === \"FunctionExpression\") {\n return true;\n }\n \n if (node.type !== \"CallExpression\") return false;\n \n const callee = node.callee;\n if (callee.type === \"Identifier\") {\n return [\"memo\", \"forwardRef\"].includes(callee.name);\n }\n \n // React.memo, React.forwardRef\n if (callee.type === \"MemberExpression\") {\n const obj = callee.object;\n const prop = callee.property;\n if (obj.type === \"Identifier\" && obj.name === \"React\" && \n prop.type === \"Identifier\") {\n return [\"memo\", \"forwardRef\"].includes(prop.name);\n }\n }\n \n return false;\n}\n\nfunction createSourceAssignment(name: string, sourceValue: string): ExpressionStatement {\n return {\n type: \"ExpressionStatement\",\n expression: {\n type: \"AssignmentExpression\",\n operator: \"=\",\n left: {\n type: \"MemberExpression\",\n object: { type: \"Identifier\", name },\n property: { type: \"Identifier\", name: SOURCE_PROP },\n computed: false,\n } as MemberExpression,\n right: { type: \"Literal\", value: sourceValue },\n } as AssignmentExpression,\n };\n}\n\nfunction createMarkElementHelper(): FunctionDeclaration {\n const code = `\nfunction _markReactElementSource(element, source) {\n const registryKey = Symbol.for(\"${JSX_SOURCE_REGISTRY_SYMBOL}\");\n let registry = globalThis[registryKey];\n if (!(registry instanceof WeakMap)) {\n registry = globalThis[registryKey] = new WeakMap();\n }\n if (element && typeof element === \"object\" && typeof element.props === \"object\") {\n registry.set(element.props, source);\n }\n return element;\n}\n`;\n return parse(code, { ecmaVersion: \"latest\" }).body[0] as FunctionDeclaration;\n}\n\nfunction wrapWithMarkElement(\n node: Node,\n sourceValue: string\n): CallExpression {\n return {\n type: \"CallExpression\",\n callee: { type: \"Identifier\", name: \"_markReactElementSource\" },\n arguments: [node as any, { type: \"Literal\", value: sourceValue }],\n optional: false,\n };\n}\n\nexport function transformSource(\n code: string,\n options: TransformOptions\n): { code: string; map?: any } | null {\n const {\n filename,\n projectRoot = process.cwd(),\n injectJsxSource = true,\n injectComponentSource = true,\n } = options;\n\n // Parse with acorn\n let ast: Program;\n try {\n ast = parse(code, {\n ecmaVersion: \"latest\",\n sourceType: \"module\",\n ecmaFeatures: { jsx: true },\n locations: true,\n ranges: true,\n } as any) as Program;\n } catch (err) {\n // Parse error - return null to skip this file\n return null;\n }\n\n let modified = false;\n let needsHelper = false;\n const seenComponents = new Set<string>();\n const assignments: Array<{ node: Node; parent: Node | null; assignment: ExpressionStatement }> = [];\n\n walk(ast as any, {\n enter(node: any, parent: any, key: any, index: any) {\n // Inject JSX source for element factory calls\n if (injectJsxSource && node.type === \"CallExpression\") {\n if (isReactElementFactoryCall(node)) {\n const loc = node.loc;\n if (loc) {\n const sourceValue = toRelativeSource(filename, loc.start, projectRoot);\n const wrapped = wrapWithMarkElement(node, sourceValue);\n \n // Replace the node\n this.replace(wrapped);\n needsHelper = true;\n modified = true;\n }\n }\n }\n\n // Inject JSX source for JSX elements\n if (injectJsxSource && node.type === \"JSXElement\") {\n const opening = node.openingElement;\n const loc = opening.loc;\n \n if (loc) {\n const sourceValue = toRelativeSource(filename, loc.start, projectRoot);\n \n // Check if intrinsic element (lowercase) or component (uppercase)\n const name = opening.name;\n if (name.type === \"JSXIdentifier\") {\n if (name.name[0] === name.name[0].toLowerCase()) {\n // Intrinsic element - use _markReactElementSource\n // This is handled by the CallExpression visitor for jsx()\n // But for JSX syntax directly, we need different handling\n } else {\n // Component - add $componentSourceLoc prop\n const sourceAttr = {\n type: \"JSXAttribute\",\n name: { type: \"JSXIdentifier\", name: JSX_SOURCE_PROP },\n value: { type: \"Literal\", value: sourceValue },\n };\n opening.attributes.push(sourceAttr);\n modified = true;\n }\n }\n }\n }\n\n // Inject component source for function declarations\n if (injectComponentSource && node.type === \"FunctionDeclaration\") {\n const name = node.id?.name;\n if (name && isComponentName(name) && !seenComponents.has(name)) {\n const loc = node.loc;\n if (loc) {\n const sourceValue = toRelativeSource(filename, loc.start, projectRoot);\n const assignment = createSourceAssignment(name, sourceValue);\n assignments.push({ node, parent, assignment });\n seenComponents.add(name);\n modified = true;\n }\n }\n }\n\n // Inject component source for variable declarations\n if (injectComponentSource && node.type === \"VariableDeclarator\") {\n const id = node.id;\n if (id.type === \"Identifier\" && isComponentName(id.name) && !seenComponents.has(id.name)) {\n const init = node.init;\n if (init && isSupportedComponentInit(init)) {\n const loc = node.loc || init.loc;\n if (loc) {\n const sourceValue = toRelativeSource(filename, loc.start, projectRoot);\n const assignment = createSourceAssignment(id.name, sourceValue);\n assignments.push({ node, parent, assignment });\n seenComponents.add(id.name);\n modified = true;\n }\n }\n }\n }\n },\n });\n\n if (!modified) {\n return null;\n }\n\n // Insert helper function if needed\n if (needsHelper) {\n const helper = createMarkElementHelper();\n // Check if already exists\n const exists = ast.body.some(\n (n) => n.type === \"FunctionDeclaration\" && \n n.id?.name === \"_markReactElementSource\"\n );\n if (!exists) {\n ast.body.unshift(helper);\n }\n }\n\n // Insert component source assignments\n // We need to insert after the declaration, so we process in reverse order\n for (const { node, parent, assignment } of assignments.reverse()) {\n if (parent && parent.type === \"Program\") {\n const index = ast.body.indexOf(node as any);\n if (index !== -1) {\n ast.body.splice(index + 1, 0, assignment as any);\n }\n } else if (parent && parent.type === \"ExportNamedDeclaration\") {\n // For export const Component = ...\n // Insert after the export statement\n const exportParent = (ast as any).body.find((n: any) => \n n.type === \"ExportNamedDeclaration\" && n.declaration === parent\n );\n if (exportParent) {\n const index = ast.body.indexOf(exportParent);\n ast.body.splice(index + 1, 0, assignment as any);\n }\n } else if (parent && parent.type === \"ExportDefaultDeclaration\") {\n // For export default function Component() ...\n const index = ast.body.indexOf(parent as any);\n ast.body.splice(index + 1, 0, assignment as any);\n }\n }\n\n // Generate code\n const result = generate(ast as any, { indent: \" \" });\n\n return { code: result };\n}\n","export const SOURCE_PROP = \"__componentSourceLoc\";\nexport const JSX_SOURCE_P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,IACV,UAAU;AAAA,IACV,cAAc,QAAQ,IAAI;AAAA,IAC1B,wBAAwB;AAAA,IACxB,kBAAkB;AAAA,EACpB,IAAI;AAEJ,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,UAAU,MAAM,IAAI;AAElB,UAAI,CAAC,gBAAgB,IAAI,SAAS,OAAO,GAAG;AAC1C,eAAO;AAAA,MACT;AAGA,YAAM,SAAS,gBAAgB,MAAM;AAAA,QACnC,UAAU;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAED,aAAO;AAAA,IACT;AAAA,EACF;AACF,CAAC;AAGI,IAAM,aAAa,SAAS;AAC5B,IAAM,gBAAgB,SAAS;AAC/B,IAAM,eAAe,SAAS;AAC9B,IAAM,gBAAgB,SAAS;AAC/B,IAAM,eAAe,SAAS;AAGrC,IAAO,mBAAQ;","names":[]}
@@ -0,0 +1,52 @@
1
+ import * as esbuild from 'esbuild';
2
+ import * as rollup from 'rollup';
3
+ import * as vite from 'vite';
4
+ import { UnpluginInstance } from 'unplugin';
5
+
6
+ /**
7
+ * Zero-dependency source transform using acorn
8
+ * No Babel required - pure JavaScript AST manipulation
9
+ */
10
+ interface TransformOptions {
11
+ filename: string;
12
+ projectRoot?: string;
13
+ injectJsxSource?: boolean;
14
+ injectComponentSource?: boolean;
15
+ }
16
+
17
+ interface ReactCodeLocatorOptions extends Omit<TransformOptions, 'filename'> {
18
+ /**
19
+ * Enable source transform for component definitions
20
+ * @default true
21
+ */
22
+ injectComponentSource?: boolean;
23
+ /**
24
+ * Enable source transform for JSX call sites
25
+ * @default true
26
+ */
27
+ injectJsxSource?: boolean;
28
+ /**
29
+ * Project root for relative path calculation
30
+ * @default process.cwd()
31
+ */
32
+ projectRoot?: string;
33
+ /**
34
+ * Include filter for file paths
35
+ * @default /\.[jt]sx$/
36
+ */
37
+ include?: RegExp | RegExp[];
38
+ /**
39
+ * Exclude filter for file paths
40
+ * @default /node_modules/
41
+ */
42
+ exclude?: RegExp | RegExp[];
43
+ }
44
+
45
+ declare const unplugin: UnpluginInstance<ReactCodeLocatorOptions | undefined, false>;
46
+ declare const vitePlugin: (options?: ReactCodeLocatorOptions | undefined) => vite.Plugin<any>;
47
+ declare const webpackPlugin: (options?: ReactCodeLocatorOptions | undefined) => WebpackPluginInstance;
48
+ declare const rollupPlugin: (options?: ReactCodeLocatorOptions | undefined) => rollup.Plugin<any>;
49
+ declare const esbuildPlugin: (options?: ReactCodeLocatorOptions | undefined) => esbuild.Plugin;
50
+ declare const rspackPlugin: (options?: ReactCodeLocatorOptions | undefined) => RspackPluginInstance;
51
+
52
+ export { type ReactCodeLocatorOptions, type TransformOptions, unplugin as default, esbuildPlugin, rollupPlugin, rspackPlugin, unplugin, vitePlugin, webpackPlugin };
@@ -0,0 +1,52 @@
1
+ import * as esbuild from 'esbuild';
2
+ import * as rollup from 'rollup';
3
+ import * as vite from 'vite';
4
+ import { UnpluginInstance } from 'unplugin';
5
+
6
+ /**
7
+ * Zero-dependency source transform using acorn
8
+ * No Babel required - pure JavaScript AST manipulation
9
+ */
10
+ interface TransformOptions {
11
+ filename: string;
12
+ projectRoot?: string;
13
+ injectJsxSource?: boolean;
14
+ injectComponentSource?: boolean;
15
+ }
16
+
17
+ interface ReactCodeLocatorOptions extends Omit<TransformOptions, 'filename'> {
18
+ /**
19
+ * Enable source transform for component definitions
20
+ * @default true
21
+ */
22
+ injectComponentSource?: boolean;
23
+ /**
24
+ * Enable source transform for JSX call sites
25
+ * @default true
26
+ */
27
+ injectJsxSource?: boolean;
28
+ /**
29
+ * Project root for relative path calculation
30
+ * @default process.cwd()
31
+ */
32
+ projectRoot?: string;
33
+ /**
34
+ * Include filter for file paths
35
+ * @default /\.[jt]sx$/
36
+ */
37
+ include?: RegExp | RegExp[];
38
+ /**
39
+ * Exclude filter for file paths
40
+ * @default /node_modules/
41
+ */
42
+ exclude?: RegExp | RegExp[];
43
+ }
44
+
45
+ declare const unplugin: UnpluginInstance<ReactCodeLocatorOptions | undefined, false>;
46
+ declare const vitePlugin: (options?: ReactCodeLocatorOptions | undefined) => vite.Plugin<any>;
47
+ declare const webpackPlugin: (options?: ReactCodeLocatorOptions | undefined) => WebpackPluginInstance;
48
+ declare const rollupPlugin: (options?: ReactCodeLocatorOptions | undefined) => rollup.Plugin<any>;
49
+ declare const esbuildPlugin: (options?: ReactCodeLocatorOptions | undefined) => esbuild.Plugin;
50
+ declare const rspackPlugin: (options?: ReactCodeLocatorOptions | undefined) => RspackPluginInstance;
51
+
52
+ export { type ReactCodeLocatorOptions, type TransformOptions, unplugin as default, esbuildPlugin, rollupPlugin, rspackPlugin, unplugin, vitePlugin, webpackPlugin };