@reticlehq/babel-plugin 3.2.0 → 3.4.0

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 CHANGED
@@ -23,4 +23,6 @@ export default defineConfig({
23
23
  module.exports = { plugins: [require('@reticlehq/babel-plugin').default] };
24
24
  ```
25
25
 
26
- After this, `reticle_inspect` returns `component.source = { file, line, column }`. Only host elements (`<div>`, `<button>`, …) are stamped; components are left untouched. Apache-2.0.
26
+ After this, `reticle_look { action: "element" }` returns `component.source = { file, line, column }`. Only host elements (`<div>`, `<button>`, …) are stamped; components are left untouched.
27
+
28
+ **Opting one file out:** a file whose first non-empty line is `// @reticle-ignore` (or `/* @reticle-ignore */`) is not stamped at all. Whole file, first line — the reasons to opt out are file-shaped, and a marker that works from anywhere is a marker nobody can find. Apache-2.0.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Is this file opted out of source stamping?
3
+ *
4
+ * True when the FIRST non-empty line is a comment carrying `@reticle-ignore` — the line form, the
5
+ * block form, or the HTML form a `.svelte` file needs because it has no line for a `//` before its
6
+ * markup. Position is strict: a license header on line 1 and the marker on line 2 is not an opt-out,
7
+ * so the rule can be checked at a glance and documented in one sentence. The word is strict too:
8
+ * the comment's whole content must BE the marker, so `@reticle-ignore-next-line` is not this.
9
+ *
10
+ * Shared by the Babel plugin (which covers Vite, `@reticlehq/next` and direct Babel users) and the
11
+ * Vite plugin (which also owns the Svelte stamper), so there is one reading of the marker. The
12
+ * marker string itself is a core constant for the same reason (#853).
13
+ */
14
+ export declare function isSourceStampingIgnored(code: string): boolean;
package/dist/ignore.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSourceStampingIgnored = isSourceStampingIgnored;
4
+ const source_constants_1 = require("@reticlehq/core/source-constants");
5
+ /**
6
+ * Is this file opted out of source stamping?
7
+ *
8
+ * True when the FIRST non-empty line is a comment carrying `@reticle-ignore` — the line form, the
9
+ * block form, or the HTML form a `.svelte` file needs because it has no line for a `//` before its
10
+ * markup. Position is strict: a license header on line 1 and the marker on line 2 is not an opt-out,
11
+ * so the rule can be checked at a glance and documented in one sentence. The word is strict too:
12
+ * the comment's whole content must BE the marker, so `@reticle-ignore-next-line` is not this.
13
+ *
14
+ * Shared by the Babel plugin (which covers Vite, `@reticlehq/next` and direct Babel users) and the
15
+ * Vite plugin (which also owns the Svelte stamper), so there is one reading of the marker. The
16
+ * marker string itself is a core constant for the same reason (#853).
17
+ */
18
+ function isSourceStampingIgnored(code) {
19
+ const line = firstNonEmptyLine(code);
20
+ if (line === undefined)
21
+ return false;
22
+ const content = commentContent(line);
23
+ return content === source_constants_1.RETICLE_IGNORE_MARKER;
24
+ }
25
+ function firstNonEmptyLine(code) {
26
+ for (const raw of code.split(/\r?\n/)) {
27
+ const line = raw.trim();
28
+ if (line.length > 0)
29
+ return line;
30
+ }
31
+ return undefined;
32
+ }
33
+ /** The text inside a one-line comment, trimmed — or undefined when the line is not one. */
34
+ function commentContent(line) {
35
+ if (line.startsWith('//'))
36
+ return line.slice(2).trim();
37
+ if (line.startsWith('/*') && line.endsWith('*/'))
38
+ return line.slice(2, -2).trim();
39
+ if (line.startsWith('<!--') && line.endsWith('-->'))
40
+ return line.slice(4, -3).trim();
41
+ return undefined;
42
+ }
package/dist/index.js CHANGED
@@ -2,7 +2,10 @@
2
2
  const node_path_1 = require("node:path");
3
3
  const source_constants_1 = require("@reticlehq/core/source-constants");
4
4
  const dom_tags_js_1 = require("./dom-tags.js");
5
+ const ignore_js_1 = require("./ignore.js");
5
6
  const SOURCE_ATTR = source_constants_1.DATA_RETICLE_SOURCE_ATTR;
7
+ /** Per-file plugin state key: this file carries `@reticle-ignore` on its first non-empty line. */
8
+ const IGNORED = 'reticleIgnored';
6
9
  /**
7
10
  * Stamps `data-reticle-source="relativeFile:line:col"` on every JSX host element (lowercase
8
11
  * tag). @reticlehq/react reads it to map a DOM node back to its source — needed on React 19,
@@ -18,7 +21,15 @@ function reticleSourcePlugin({ types: t }) {
18
21
  return {
19
22
  name: 'reticle-source',
20
23
  visitor: {
24
+ // Decided once per FILE, on the file's own text, and kept on the per-file `state` — never on
25
+ // the plugin instance, which Babel reuses across every file in a build. A plugin-level flag
26
+ // set by one opted-out file would switch stamping off for everything after it.
27
+ Program(_path, state) {
28
+ state.set(IGNORED, (0, ignore_js_1.isSourceStampingIgnored)(state.file.code));
29
+ },
21
30
  JSXOpeningElement(path, state) {
31
+ if (true === state.get(IGNORED))
32
+ return;
22
33
  const node = path.node;
23
34
  // Host elements only (e.g. <div>, <button>) — skip components (<App />).
24
35
  if (node.name.type !== 'JSXIdentifier')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reticlehq/babel-plugin",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "description": "Babel plugin that stamps data-reticle-source=\"file:line:col\" on JSX host elements so @reticlehq/react can map a DOM node to its source (works on React 19, which dropped _debugSource).",
5
5
  "type": "commonjs",
6
6
  "license": "Apache-2.0",
@@ -27,6 +27,11 @@
27
27
  "types": "./dist/index.d.ts",
28
28
  "require": "./dist/index.js",
29
29
  "default": "./dist/index.js"
30
+ },
31
+ "./ignore": {
32
+ "types": "./dist/ignore.d.ts",
33
+ "require": "./dist/ignore.js",
34
+ "default": "./dist/ignore.js"
30
35
  }
31
36
  },
32
37
  "files": [
@@ -35,7 +40,7 @@
35
40
  "NOTICE"
36
41
  ],
37
42
  "dependencies": {
38
- "@reticlehq/core": "3.2.0"
43
+ "@reticlehq/core": "3.4.0"
39
44
  },
40
45
  "peerDependencies": {
41
46
  "@babel/core": "^7"