@prover-coder-ai/component-tagger 1.0.26 → 1.0.27
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/babel.cjs
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
const path = require("node:path")
|
|
24
24
|
|
|
25
|
+
const babelPluginName = "component-path-babel-tagger"
|
|
25
26
|
const componentPathAttributeName = "data-path"
|
|
26
27
|
const jsxFilePattern = /\.(tsx|jsx)(\?.*)?$/u
|
|
27
28
|
|
|
@@ -37,7 +38,7 @@ const attrExists = (node, attrName, t) =>
|
|
|
37
38
|
|
|
38
39
|
module.exports = function componentTaggerBabelPlugin({ types: t }) {
|
|
39
40
|
return {
|
|
40
|
-
name:
|
|
41
|
+
name: babelPluginName,
|
|
41
42
|
visitor: {
|
|
42
43
|
JSXOpeningElement(nodePath, state) {
|
|
43
44
|
const { node } = nodePath
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
const jsxFilePattern = /\.(tsx|jsx)(\?.*)?$/u;
|
|
2
|
+
// CHANGE: define canonical Babel plugin name for component path tagging.
|
|
3
|
+
// WHY: eliminate magic string duplication across plugin implementations.
|
|
4
|
+
// QUOTE(ТЗ): "Вынести строки имён плагинов в константы (чтобы не дублировать \"component-path-babel-tagger\")."
|
|
5
|
+
// REF: issue-19
|
|
6
|
+
// SOURCE: n/a
|
|
7
|
+
// FORMAT THEOREM: forall p in PluginName: p = "component-path-babel-tagger"
|
|
8
|
+
// PURITY: CORE
|
|
9
|
+
// EFFECT: n/a
|
|
10
|
+
// INVARIANT: plugin name remains stable across all implementations
|
|
11
|
+
// COMPLEXITY: O(1)/O(1)
|
|
12
|
+
export const babelPluginName = "component-path-babel-tagger";
|
|
2
13
|
/**
|
|
3
14
|
* Normalizes a module ID by stripping query parameters.
|
|
4
15
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { types as t } from "@babel/core";
|
|
2
|
-
import { componentPathAttributeName, isJsxFile } from "../core/component-path.js";
|
|
2
|
+
import { babelPluginName, componentPathAttributeName, isJsxFile } from "../core/component-path.js";
|
|
3
3
|
import { createJsxTaggerVisitor } from "../core/jsx-tagger.js";
|
|
4
4
|
import { computeRelativePath } from "../core/path-service.js";
|
|
5
5
|
/**
|
|
@@ -83,7 +83,7 @@ const getContextFromState = (state) => {
|
|
|
83
83
|
// INVARIANT: each JSX opening element has at most one path attribute
|
|
84
84
|
// COMPLEXITY: O(n)/O(1)
|
|
85
85
|
export const componentTaggerBabelPlugin = () => ({
|
|
86
|
-
name:
|
|
86
|
+
name: babelPluginName,
|
|
87
87
|
visitor: createJsxTaggerVisitor(getContextFromState, t)
|
|
88
88
|
});
|
|
89
89
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { transformAsync, types as t } from "@babel/core";
|
|
2
2
|
import { Effect, pipe } from "effect";
|
|
3
|
-
import { componentPathAttributeName, isJsxFile, normalizeModuleId } from "../core/component-path.js";
|
|
3
|
+
import { babelPluginName, componentPathAttributeName, isJsxFile, normalizeModuleId } from "../core/component-path.js";
|
|
4
4
|
import { createJsxTaggerVisitor } from "../core/jsx-tagger.js";
|
|
5
5
|
import { NodePathLayer, relativeFromRoot } from "../core/path-service.js";
|
|
6
6
|
class ComponentTaggerError extends Error {
|
|
@@ -21,10 +21,20 @@ const toViteResult = (result) => {
|
|
|
21
21
|
map: result.map ?? null
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
|
+
// CHANGE: use unified JSX tagger visitor from core module.
|
|
25
|
+
// WHY: share business logic between Vite and Babel plugins as requested.
|
|
26
|
+
// QUOTE(TZ): "А ты можешь сделать что бы бизнес логика оставалось одной? Ну типо переиспользуй код с vite версии на babel"
|
|
27
|
+
// REF: issue-12-comment (unified interface request)
|
|
28
|
+
// SOURCE: n/a
|
|
29
|
+
// FORMAT THEOREM: forall f in JSXOpeningElement: rendered(f) -> annotated(f)
|
|
30
|
+
// PURITY: SHELL
|
|
31
|
+
// EFFECT: Babel AST transformation
|
|
32
|
+
// INVARIANT: each JSX opening element has at most one path attribute
|
|
33
|
+
// COMPLEXITY: O(n)/O(1), n = number of JSX elements
|
|
24
34
|
const makeBabelTagger = (relativeFilename, attributeName) => {
|
|
25
35
|
const context = { relativeFilename, attributeName };
|
|
26
36
|
return {
|
|
27
|
-
name:
|
|
37
|
+
name: babelPluginName,
|
|
28
38
|
visitor: createJsxTaggerVisitor(() => context, t)
|
|
29
39
|
};
|
|
30
40
|
};
|