Skip to content

Commit f5c9134

Browse files
konardclaude
andcommitted
refactor(app): remove unused ViteBabelState and extract plugin name constant
- Remove ViteBabelState type definition from component-tagger.ts as it was never accessed - Extract "component-path-babel-tagger" string to babelPluginName constant in component-path.ts - Replace all hardcoded plugin name strings across babel-plugin.ts, component-tagger.ts, and babel.cjs - Maintain mathematical purity: ∀p ∈ PluginName: p = babelPluginName (single source of truth) INVARIANT: Plugin name remains stable across all implementations via shared constant THEOREM: ∀ implementation: plugin.name = babelPluginName QUOTE(ТЗ): "Вынести строки имён плагинов в константы (чтобы не дублировать \"component-path-babel-tagger\")." REF: #19 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 881737e commit f5c9134

4 files changed

Lines changed: 20 additions & 11 deletions

File tree

packages/app/babel.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
const path = require("node:path")
2424

25+
const babelPluginName = "component-path-babel-tagger"
2526
const componentPathAttributeName = "path"
2627
const jsxFilePattern = /\.(tsx|jsx)(\?.*)?$/u
2728

@@ -37,7 +38,7 @@ const attrExists = (node, attrName, t) =>
3738

3839
module.exports = function componentTaggerBabelPlugin({ types: t }) {
3940
return {
40-
name: "component-path-babel-tagger",
41+
name: babelPluginName,
4142
visitor: {
4243
JSXOpeningElement(nodePath, state) {
4344
const { node } = nodePath

packages/app/src/core/component-path.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
const jsxFilePattern = /\.(tsx|jsx)(\?.*)?$/u
22

3+
// CHANGE: define canonical Babel plugin name for component path tagging.
4+
// WHY: eliminate magic string duplication across plugin implementations.
5+
// QUOTE(ТЗ): "Вынести строки имён плагинов в константы (чтобы не дублировать \"component-path-babel-tagger\")."
6+
// REF: issue-19
7+
// SOURCE: n/a
8+
// FORMAT THEOREM: forall p in PluginName: p = "component-path-babel-tagger"
9+
// PURITY: CORE
10+
// EFFECT: n/a
11+
// INVARIANT: plugin name remains stable across all implementations
12+
// COMPLEXITY: O(1)/O(1)
13+
export const babelPluginName = "component-path-babel-tagger"
14+
315
// CHANGE: define canonical attribute name for component path tagging.
416
// WHY: reduce metadata to a single attribute while keeping full source location.
517
// QUOTE(TZ): "\u0421\u0430\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c app \u043d\u043e \u0432\u043e\u0442 \u0447\u0442\u043e \u0431\u044b \u0435\u0433\u043e \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0434\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0435\u043a\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0448 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0430\u043f\u043f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c"

packages/app/src/shell/babel-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type PluginObj, types as t } from "@babel/core"
22

3-
import { isJsxFile } from "../core/component-path.js"
3+
import { babelPluginName, isJsxFile } from "../core/component-path.js"
44
import { createJsxTaggerVisitor, type JsxTaggerContext } from "../core/jsx-tagger.js"
55
import { computeRelativePath } from "../core/path-service.js"
66

@@ -106,7 +106,7 @@ const getContextFromState = (state: BabelState): JsxTaggerContext | null => {
106106
// INVARIANT: each JSX opening element has at most one path attribute
107107
// COMPLEXITY: O(n)/O(1)
108108
export const componentTaggerBabelPlugin = (): PluginObj<BabelState> => ({
109-
name: "component-path-babel-tagger",
109+
name: babelPluginName,
110110
visitor: createJsxTaggerVisitor<BabelState>(getContextFromState, t)
111111
})
112112

packages/app/src/shell/component-tagger.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Path } from "@effect/platform/Path"
33
import { Effect, pipe } from "effect"
44
import type { PluginOption } from "vite"
55

6-
import { isJsxFile } from "../core/component-path.js"
6+
import { babelPluginName, isJsxFile } from "../core/component-path.js"
77
import { createJsxTaggerVisitor, type JsxTaggerContext } from "../core/jsx-tagger.js"
88
import { NodePathLayer, relativeFromRoot } from "../core/path-service.js"
99

@@ -50,16 +50,12 @@ const toViteResult = (result: BabelTransformResult): ViteTransformResult | null
5050
// EFFECT: Babel AST transformation
5151
// INVARIANT: each JSX opening element has at most one path attribute
5252
// COMPLEXITY: O(n)/O(1), n = number of JSX elements
53-
type ViteBabelState = {
54-
readonly context: JsxTaggerContext
55-
}
56-
57-
const makeBabelTagger = (relativeFilename: string): PluginObj<ViteBabelState> => {
53+
const makeBabelTagger = (relativeFilename: string): PluginObj => {
5854
const context: JsxTaggerContext = { relativeFilename }
5955

6056
return {
61-
name: "component-path-babel-tagger",
62-
visitor: createJsxTaggerVisitor<ViteBabelState>(
57+
name: babelPluginName,
58+
visitor: createJsxTaggerVisitor(
6359
() => context,
6460
t
6561
)

0 commit comments

Comments
 (0)