@angular-modernizer/plugin-solid 0.1.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/LICENSE +21 -0
- package/README.md +835 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestrators/god-switch-transform-orchestrator.d.ts +350 -0
- package/dist/orchestrators/god-switch-transform-orchestrator.d.ts.map +1 -0
- package/dist/orchestrators/god-switch-transform-orchestrator.js +1165 -0
- package/dist/orchestrators/god-switch-transform-orchestrator.js.map +1 -0
- package/dist/orchestrators/service-dip-violation-transform.orchestrator.d.ts +72 -0
- package/dist/orchestrators/service-dip-violation-transform.orchestrator.d.ts.map +1 -0
- package/dist/orchestrators/service-dip-violation-transform.orchestrator.js +243 -0
- package/dist/orchestrators/service-dip-violation-transform.orchestrator.js.map +1 -0
- package/dist/rules/dip-violation.rule.d.ts +54 -0
- package/dist/rules/dip-violation.rule.d.ts.map +1 -0
- package/dist/rules/dip-violation.rule.js +156 -0
- package/dist/rules/dip-violation.rule.js.map +1 -0
- package/dist/rules/god-switch-analysis.rule.d.ts +73 -0
- package/dist/rules/god-switch-analysis.rule.d.ts.map +1 -0
- package/dist/rules/god-switch-analysis.rule.js +174 -0
- package/dist/rules/god-switch-analysis.rule.js.map +1 -0
- package/dist/rules/isp-violation.rule.d.ts +62 -0
- package/dist/rules/isp-violation.rule.d.ts.map +1 -0
- package/dist/rules/isp-violation.rule.js +250 -0
- package/dist/rules/isp-violation.rule.js.map +1 -0
- package/dist/rules/lsp-violation.rule.d.ts +57 -0
- package/dist/rules/lsp-violation.rule.d.ts.map +1 -0
- package/dist/rules/lsp-violation.rule.js +321 -0
- package/dist/rules/lsp-violation.rule.js.map +1 -0
- package/dist/rules/ocp-violation.rule.d.ts +69 -0
- package/dist/rules/ocp-violation.rule.d.ts.map +1 -0
- package/dist/rules/ocp-violation.rule.js +204 -0
- package/dist/rules/ocp-violation.rule.js.map +1 -0
- package/dist/rules/service-dip-violation.analysis.rule.d.ts +85 -0
- package/dist/rules/service-dip-violation.analysis.rule.d.ts.map +1 -0
- package/dist/rules/service-dip-violation.analysis.rule.js +217 -0
- package/dist/rules/service-dip-violation.analysis.rule.js.map +1 -0
- package/dist/rules/srp-violation.rule.d.ts +71 -0
- package/dist/rules/srp-violation.rule.d.ts.map +1 -0
- package/dist/rules/srp-violation.rule.js +307 -0
- package/dist/rules/srp-violation.rule.js.map +1 -0
- package/dist/solid-plugin.d.ts +82 -0
- package/dist/solid-plugin.d.ts.map +1 -0
- package/dist/solid-plugin.js +115 -0
- package/dist/solid-plugin.js.map +1 -0
- package/dist/transform-rules/god-switch-transform.rule.d.ts +128 -0
- package/dist/transform-rules/god-switch-transform.rule.d.ts.map +1 -0
- package/dist/transform-rules/god-switch-transform.rule.js +167 -0
- package/dist/transform-rules/god-switch-transform.rule.js.map +1 -0
- package/dist/transform-rules/service-dip-violation.transform.rule.d.ts +75 -0
- package/dist/transform-rules/service-dip-violation.transform.rule.d.ts.map +1 -0
- package/dist/transform-rules/service-dip-violation.transform.rule.js +115 -0
- package/dist/transform-rules/service-dip-violation.transform.rule.js.map +1 -0
- package/package.json +59 -0
- package/src/index.ts +30 -0
- package/src/orchestrators/god-switch-transform-orchestrator.ts +1562 -0
- package/src/orchestrators/service-dip-violation-transform.orchestrator.ts +331 -0
- package/src/rules/dip-violation.rule.ts +194 -0
- package/src/rules/god-switch-analysis.rule.ts +209 -0
- package/src/rules/isp-violation.rule.ts +315 -0
- package/src/rules/lsp-violation.rule.ts +393 -0
- package/src/rules/ocp-violation.rule.ts +264 -0
- package/src/rules/service-dip-violation.analysis.rule.ts +285 -0
- package/src/rules/srp-violation.rule.ts +366 -0
- package/src/solid-plugin.ts +127 -0
- package/src/transform-rules/god-switch-transform.rule.ts +189 -0
- package/src/transform-rules/service-dip-violation.transform.rule.ts +134 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/plugin-solid
|
|
3
|
+
*
|
|
4
|
+
* SOLID principles analysis plugin for the Angular Modernization Platform.
|
|
5
|
+
* Detects architectural violations and provides guidance for better code structure.
|
|
6
|
+
*/
|
|
7
|
+
export { SolidPlugin } from './solid-plugin.js';
|
|
8
|
+
export { DIPViolationRule } from './rules/dip-violation.rule.js';
|
|
9
|
+
export { SingleResponsibilityRule } from './rules/srp-violation.rule.js';
|
|
10
|
+
export { LSPViolationRule } from './rules/lsp-violation.rule.js';
|
|
11
|
+
export { OCPViolationRule } from './rules/ocp-violation.rule.js';
|
|
12
|
+
export { ISPViolationRule } from './rules/isp-violation.rule.js';
|
|
13
|
+
export { GodSwitchAnalysisRule } from './rules/god-switch-analysis.rule.js';
|
|
14
|
+
export { ServiceDipViolationRule } from './rules/service-dip-violation.analysis.rule.js';
|
|
15
|
+
export type { ServiceDipViolationConfig, ServiceDipViolationMetadata, } from './rules/service-dip-violation.analysis.rule.js';
|
|
16
|
+
export { GodSwitchTransformRule } from './transform-rules/god-switch-transform.rule.js';
|
|
17
|
+
export { ServiceDipViolationTransformRule } from './transform-rules/service-dip-violation.transform.rule.js';
|
|
18
|
+
export { GodSwitchTransformOrchestrator } from './orchestrators/god-switch-transform-orchestrator.js';
|
|
19
|
+
export { ServiceDipViolationTransformOrchestrator } from './orchestrators/service-dip-violation-transform.orchestrator.js';
|
|
20
|
+
export type { ServiceDipTransformResult } from './orchestrators/service-dip-violation-transform.orchestrator.js';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,YAAY,EACV,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,gDAAgD,CAAC;AAGxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,gCAAgC,EAAE,MAAM,2DAA2D,CAAC;AAG7G,OAAO,EAAE,8BAA8B,EAAE,MAAM,sDAAsD,CAAC;AACtG,OAAO,EAAE,wCAAwC,EAAE,MAAM,iEAAiE,CAAC;AAC3H,YAAY,EAAE,yBAAyB,EAAE,MAAM,iEAAiE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @angular-modernizer/plugin-solid
|
|
4
|
+
*
|
|
5
|
+
* SOLID principles analysis plugin for the Angular Modernization Platform.
|
|
6
|
+
* Detects architectural violations and provides guidance for better code structure.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ServiceDipViolationTransformOrchestrator = exports.GodSwitchTransformOrchestrator = exports.ServiceDipViolationTransformRule = exports.GodSwitchTransformRule = exports.ServiceDipViolationRule = exports.GodSwitchAnalysisRule = exports.ISPViolationRule = exports.OCPViolationRule = exports.LSPViolationRule = exports.SingleResponsibilityRule = exports.DIPViolationRule = exports.SolidPlugin = void 0;
|
|
10
|
+
var solid_plugin_js_1 = require("./solid-plugin.js");
|
|
11
|
+
Object.defineProperty(exports, "SolidPlugin", { enumerable: true, get: function () { return solid_plugin_js_1.SolidPlugin; } });
|
|
12
|
+
// Analysis Rules
|
|
13
|
+
var dip_violation_rule_js_1 = require("./rules/dip-violation.rule.js");
|
|
14
|
+
Object.defineProperty(exports, "DIPViolationRule", { enumerable: true, get: function () { return dip_violation_rule_js_1.DIPViolationRule; } });
|
|
15
|
+
var srp_violation_rule_js_1 = require("./rules/srp-violation.rule.js");
|
|
16
|
+
Object.defineProperty(exports, "SingleResponsibilityRule", { enumerable: true, get: function () { return srp_violation_rule_js_1.SingleResponsibilityRule; } });
|
|
17
|
+
var lsp_violation_rule_js_1 = require("./rules/lsp-violation.rule.js");
|
|
18
|
+
Object.defineProperty(exports, "LSPViolationRule", { enumerable: true, get: function () { return lsp_violation_rule_js_1.LSPViolationRule; } });
|
|
19
|
+
var ocp_violation_rule_js_1 = require("./rules/ocp-violation.rule.js");
|
|
20
|
+
Object.defineProperty(exports, "OCPViolationRule", { enumerable: true, get: function () { return ocp_violation_rule_js_1.OCPViolationRule; } });
|
|
21
|
+
var isp_violation_rule_js_1 = require("./rules/isp-violation.rule.js");
|
|
22
|
+
Object.defineProperty(exports, "ISPViolationRule", { enumerable: true, get: function () { return isp_violation_rule_js_1.ISPViolationRule; } });
|
|
23
|
+
var god_switch_analysis_rule_js_1 = require("./rules/god-switch-analysis.rule.js");
|
|
24
|
+
Object.defineProperty(exports, "GodSwitchAnalysisRule", { enumerable: true, get: function () { return god_switch_analysis_rule_js_1.GodSwitchAnalysisRule; } });
|
|
25
|
+
var service_dip_violation_analysis_rule_js_1 = require("./rules/service-dip-violation.analysis.rule.js");
|
|
26
|
+
Object.defineProperty(exports, "ServiceDipViolationRule", { enumerable: true, get: function () { return service_dip_violation_analysis_rule_js_1.ServiceDipViolationRule; } });
|
|
27
|
+
// Transform Rules
|
|
28
|
+
var god_switch_transform_rule_js_1 = require("./transform-rules/god-switch-transform.rule.js");
|
|
29
|
+
Object.defineProperty(exports, "GodSwitchTransformRule", { enumerable: true, get: function () { return god_switch_transform_rule_js_1.GodSwitchTransformRule; } });
|
|
30
|
+
var service_dip_violation_transform_rule_js_1 = require("./transform-rules/service-dip-violation.transform.rule.js");
|
|
31
|
+
Object.defineProperty(exports, "ServiceDipViolationTransformRule", { enumerable: true, get: function () { return service_dip_violation_transform_rule_js_1.ServiceDipViolationTransformRule; } });
|
|
32
|
+
// Orchestrators (for advanced usage)
|
|
33
|
+
var god_switch_transform_orchestrator_js_1 = require("./orchestrators/god-switch-transform-orchestrator.js");
|
|
34
|
+
Object.defineProperty(exports, "GodSwitchTransformOrchestrator", { enumerable: true, get: function () { return god_switch_transform_orchestrator_js_1.GodSwitchTransformOrchestrator; } });
|
|
35
|
+
var service_dip_violation_transform_orchestrator_js_1 = require("./orchestrators/service-dip-violation-transform.orchestrator.js");
|
|
36
|
+
Object.defineProperty(exports, "ServiceDipViolationTransformOrchestrator", { enumerable: true, get: function () { return service_dip_violation_transform_orchestrator_js_1.ServiceDipViolationTransformOrchestrator; } });
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qDAAgD;AAAvC,8GAAA,WAAW,OAAA;AAEpB,iBAAiB;AACjB,uEAAiE;AAAxD,yHAAA,gBAAgB,OAAA;AACzB,uEAAyE;AAAhE,iIAAA,wBAAwB,OAAA;AACjC,uEAAiE;AAAxD,yHAAA,gBAAgB,OAAA;AACzB,uEAAiE;AAAxD,yHAAA,gBAAgB,OAAA;AACzB,uEAAiE;AAAxD,yHAAA,gBAAgB,OAAA;AACzB,mFAA4E;AAAnE,oIAAA,qBAAqB,OAAA;AAC9B,yGAAyF;AAAhF,iJAAA,uBAAuB,OAAA;AAMhC,kBAAkB;AAClB,+FAAwF;AAA/E,sIAAA,sBAAsB,OAAA;AAC/B,qHAA6G;AAApG,2JAAA,gCAAgC,OAAA;AAEzC,qCAAqC;AACrC,6GAAsG;AAA7F,sJAAA,8BAA8B,OAAA;AACvC,mIAA2H;AAAlH,2KAAA,wCAAwC,OAAA"}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/plugin-solid - God Switch Transform Orchestrator
|
|
3
|
+
*
|
|
4
|
+
* The central "brain" of the God Switch transformation plugin.
|
|
5
|
+
* Transforms large switch statements into maintainable Factory Pattern implementations.
|
|
6
|
+
*
|
|
7
|
+
* Philosophy: "API-Driven Orchestration"
|
|
8
|
+
* - Receives all capabilities via TransformContext
|
|
9
|
+
* - Uses ts-morph for all AST operations
|
|
10
|
+
* - Stateless - no constructor dependencies
|
|
11
|
+
* - Pure business logic, no low-level manipulation
|
|
12
|
+
*/
|
|
13
|
+
import type { TransformContext } from '@angular-modernizer/plugin-system';
|
|
14
|
+
import type { PublicApi } from '@angular-modernizer/api';
|
|
15
|
+
/**
|
|
16
|
+
* Configuration options for God Switch transformation.
|
|
17
|
+
*/
|
|
18
|
+
export interface GodSwitchTransformConfig {
|
|
19
|
+
/**
|
|
20
|
+
* Whether to generate strategy interfaces.
|
|
21
|
+
* Default: true
|
|
22
|
+
*/
|
|
23
|
+
generateInterfaces?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to generate factory classes.
|
|
26
|
+
* Default: true
|
|
27
|
+
*/
|
|
28
|
+
generateFactory?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Naming pattern for strategy classes.
|
|
31
|
+
* Template variables: {CaseValue}, {SwitchExpression}
|
|
32
|
+
* Default: '{CaseValue}Strategy'
|
|
33
|
+
*/
|
|
34
|
+
strategyNamingPattern?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Naming pattern for factory classes.
|
|
37
|
+
* Template variables: {SwitchExpression}
|
|
38
|
+
* Default: '{SwitchExpression}Factory'
|
|
39
|
+
*/
|
|
40
|
+
factoryNamingPattern?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Minimum case count to trigger transformation.
|
|
43
|
+
* Should match the analysis rule threshold.
|
|
44
|
+
* Default: 10
|
|
45
|
+
*/
|
|
46
|
+
minCaseCount?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* God Switch Transform Orchestrator
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* The central orchestrator for transforming God Switch patterns into Factory Pattern.
|
|
53
|
+
* This class analyzes large switch statements and refactors them into maintainable
|
|
54
|
+
* strategy-based implementations using the Factory Pattern.
|
|
55
|
+
*
|
|
56
|
+
* ## Architecture Pattern
|
|
57
|
+
*
|
|
58
|
+
* This orchestrator follows three core principles:
|
|
59
|
+
* 1. **Stateless Design** - No constructor dependencies
|
|
60
|
+
* 2. **Context-Driven** - All capabilities injected via {@link TransformContext}
|
|
61
|
+
* 3. **API-First** - Uses ts-morph for all AST operations
|
|
62
|
+
*
|
|
63
|
+
* ## Transformation Workflow
|
|
64
|
+
*
|
|
65
|
+
* The orchestrator performs the following transformations:
|
|
66
|
+
* 1. Find all God Switch violations in the source file
|
|
67
|
+
* 2. Extract switch metadata (expression, cases, return type)
|
|
68
|
+
* 3. Generate strategy interface with execute() method
|
|
69
|
+
* 4. Generate strategy classes (one per case)
|
|
70
|
+
* 5. Generate factory class with strategy instantiation
|
|
71
|
+
* 6. Replace switch statement with factory call
|
|
72
|
+
* 7. Update imports as needed
|
|
73
|
+
*
|
|
74
|
+
* ## Example Usage
|
|
75
|
+
*
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const orchestrator = new GodSwitchTransformOrchestrator();
|
|
78
|
+
* const context = ContextFactory.createTransformContext({
|
|
79
|
+
* sourceFile,
|
|
80
|
+
* project,
|
|
81
|
+
* api,
|
|
82
|
+
* config: { minCaseCount: 10 }
|
|
83
|
+
* });
|
|
84
|
+
* orchestrator.run(context);
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @see {@link TransformContext} for context structure
|
|
88
|
+
* @see {@link GodSwitchTransformConfig} for configuration options
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
export declare class GodSwitchTransformOrchestrator {
|
|
93
|
+
/**
|
|
94
|
+
* Creates a new GodSwitchTransformOrchestrator instance.
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* The constructor is intentionally stateless. All dependencies are provided
|
|
98
|
+
* through the {@link TransformContext} passed to the {@link run} method.
|
|
99
|
+
* This enables testing, composition, and prevents tight coupling.
|
|
100
|
+
*
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
constructor();
|
|
104
|
+
/**
|
|
105
|
+
* Executes the God Switch transformation on a single source file.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* This method is the main entry point for the orchestrator. It receives all
|
|
109
|
+
* necessary dependencies (project, API, config) through the context parameter,
|
|
110
|
+
* analyzes switch statements, and transforms them into Factory Pattern.
|
|
111
|
+
*
|
|
112
|
+
* The method operates on one source file at a time and is safe to call
|
|
113
|
+
* multiple times. It will:
|
|
114
|
+
* - Find all God Switch violations (switches exceeding case threshold)
|
|
115
|
+
* - Extract metadata from each switch statement
|
|
116
|
+
* - Generate strategy interface, classes, and factory
|
|
117
|
+
* - Replace switch with factory call
|
|
118
|
+
* - Update imports
|
|
119
|
+
*
|
|
120
|
+
* ## Transformation Behavior
|
|
121
|
+
*
|
|
122
|
+
* **Switch Analysis**:
|
|
123
|
+
* - Identifies switch statements exceeding configured case threshold
|
|
124
|
+
* - Extracts case labels, logic, and return values
|
|
125
|
+
* - Analyzes captured variables from outer scope
|
|
126
|
+
*
|
|
127
|
+
* **Code Generation**:
|
|
128
|
+
* - Creates IStrategy interface with execute() method signature
|
|
129
|
+
* - Generates one strategy class per case implementing IStrategy
|
|
130
|
+
* - Creates factory class with strategy instantiation mapping
|
|
131
|
+
*
|
|
132
|
+
* **Code Replacement**:
|
|
133
|
+
* - Replaces switch statement with factory instantiation and execute call
|
|
134
|
+
* - Preserves original switch in comment for reference
|
|
135
|
+
* - Updates imports for new classes
|
|
136
|
+
*
|
|
137
|
+
* ## Safety Guarantees
|
|
138
|
+
*
|
|
139
|
+
* **Idempotency**: Checks if factory/strategies already exist before generating
|
|
140
|
+
* **Atomicity**: Uses try-catch with rollback on error
|
|
141
|
+
* **Reversibility**: Preserves original switch in comments with transformation metadata
|
|
142
|
+
*
|
|
143
|
+
* @param context - The transformation context containing:
|
|
144
|
+
* - `sourceFile`: The TypeScript source file to analyze
|
|
145
|
+
* - `project`: The ts-morph Project for cross-file operations
|
|
146
|
+
* - `api`: The PublicApi with analysis and transformation tools
|
|
147
|
+
* - `config`: User-provided configuration options
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* // Basic usage
|
|
152
|
+
* orchestrator.run(context);
|
|
153
|
+
*
|
|
154
|
+
* // With custom configuration
|
|
155
|
+
* const context = ContextFactory.createTransformContext({
|
|
156
|
+
* sourceFile,
|
|
157
|
+
* project,
|
|
158
|
+
* api,
|
|
159
|
+
* config: {
|
|
160
|
+
* '@angular-modernizer/plugin-solid': {
|
|
161
|
+
* godSwitch: {
|
|
162
|
+
* minCaseCount: 15,
|
|
163
|
+
* generateInterfaces: true,
|
|
164
|
+
* strategyNamingPattern: '{CaseValue}Handler'
|
|
165
|
+
* }
|
|
166
|
+
* }
|
|
167
|
+
* }
|
|
168
|
+
* });
|
|
169
|
+
* orchestrator.run(context);
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @see {@link TransformContext} for context structure
|
|
173
|
+
* @see {@link GodSwitchTransformConfig} for configuration options
|
|
174
|
+
*
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
run(context: TransformContext<PublicApi>): void;
|
|
178
|
+
/**
|
|
179
|
+
* Find all switch statements that exceed the case threshold.
|
|
180
|
+
*
|
|
181
|
+
* @param sourceFile - The source file to analyze
|
|
182
|
+
* @param minCaseCount - Minimum case count to be considered a God Switch
|
|
183
|
+
* @returns Array of switch statements exceeding threshold
|
|
184
|
+
*/
|
|
185
|
+
private findGodSwitches;
|
|
186
|
+
/**
|
|
187
|
+
* Check if a switch statement has already been transformed.
|
|
188
|
+
*
|
|
189
|
+
* @param switchStmt - The switch statement to check
|
|
190
|
+
* @returns True if already transformed, false otherwise
|
|
191
|
+
*/
|
|
192
|
+
private isAlreadyTransformed;
|
|
193
|
+
/**
|
|
194
|
+
* Extract comprehensive metadata from a switch statement.
|
|
195
|
+
*
|
|
196
|
+
* @param switchStmt - The switch statement to analyze
|
|
197
|
+
* @returns Complete switch metadata for code generation
|
|
198
|
+
*/
|
|
199
|
+
private extractSwitchMetadata;
|
|
200
|
+
/**
|
|
201
|
+
* Analyze a case clause to extract logic and metadata.
|
|
202
|
+
*
|
|
203
|
+
* @param caseClause - The case clause to analyze
|
|
204
|
+
* @param containingFunc - The containing function or method
|
|
205
|
+
* @returns Case metadata including statements and control flow
|
|
206
|
+
*/
|
|
207
|
+
private analyzeCaseLogic;
|
|
208
|
+
/**
|
|
209
|
+
* Identify variables captured from outer scope.
|
|
210
|
+
*
|
|
211
|
+
* @param caseClause - The case clause to analyze
|
|
212
|
+
* @param parentScope - The parent scope (e.g., function, block)
|
|
213
|
+
* @returns Array of captured variable names
|
|
214
|
+
*/
|
|
215
|
+
private identifyCapturedVariables;
|
|
216
|
+
/**
|
|
217
|
+
* Identify captured variables that are mutated in the case clause.
|
|
218
|
+
* Detects assignments, increment/decrement operations on captured variables.
|
|
219
|
+
*
|
|
220
|
+
* @param caseClause - The case clause to analyze
|
|
221
|
+
* @param capturedVariables - Array of captured variable names
|
|
222
|
+
* @returns Array of mutated variable names
|
|
223
|
+
*/
|
|
224
|
+
private identifyMutatedVariables;
|
|
225
|
+
/**
|
|
226
|
+
* Extract return type from switch statement.
|
|
227
|
+
* Prioritizes function's declared return type over inferred literal types.
|
|
228
|
+
*
|
|
229
|
+
* @param switchStmt - The switch statement
|
|
230
|
+
* @returns Return type as string
|
|
231
|
+
*/
|
|
232
|
+
private extractReturnType;
|
|
233
|
+
/**
|
|
234
|
+
* Extract parameters needed by strategy execute method.
|
|
235
|
+
* Merges function parameters with captured variables from cases.
|
|
236
|
+
*
|
|
237
|
+
* @param switchStmt - The switch statement
|
|
238
|
+
* @param cases - Array of case metadata with captured variables
|
|
239
|
+
* @returns Array of parameter information
|
|
240
|
+
*/
|
|
241
|
+
private extractParameters;
|
|
242
|
+
/**
|
|
243
|
+
* Generate strategy interface code.
|
|
244
|
+
*
|
|
245
|
+
* @param switchStmt - The switch statement
|
|
246
|
+
* @param metadata - Switch metadata
|
|
247
|
+
* @param config - Configuration options
|
|
248
|
+
* @returns Interface code as string
|
|
249
|
+
*/
|
|
250
|
+
private generateStrategyInterface;
|
|
251
|
+
/**
|
|
252
|
+
* Generate strategy class implementations.
|
|
253
|
+
*
|
|
254
|
+
* @param cases - Array of case metadata
|
|
255
|
+
* @param metadata - Complete switch metadata
|
|
256
|
+
* @param config - Configuration options
|
|
257
|
+
* @returns Object containing strategy class code and case-to-strategy mapping
|
|
258
|
+
*/
|
|
259
|
+
private generateStrategyClasses;
|
|
260
|
+
/**
|
|
261
|
+
* Generate factory class code.
|
|
262
|
+
*
|
|
263
|
+
* @param metadata - Switch metadata
|
|
264
|
+
* @param config - Configuration options
|
|
265
|
+
* @param caseToStrategyMap - Mapping from case values to strategy class names
|
|
266
|
+
* @returns Factory class code as string
|
|
267
|
+
*/
|
|
268
|
+
private generateFactoryClass;
|
|
269
|
+
/**
|
|
270
|
+
* Generate replacement text for switch statement.
|
|
271
|
+
*
|
|
272
|
+
* @param metadata - Switch metadata
|
|
273
|
+
* @param config - Configuration options
|
|
274
|
+
* @param originalSwitchText - Original switch text
|
|
275
|
+
* @param isInReturnStatement - Whether the switch is in a return statement
|
|
276
|
+
* @returns Replacement text
|
|
277
|
+
*/
|
|
278
|
+
private generateReplacementText;
|
|
279
|
+
/**
|
|
280
|
+
* Generate mutation application code.
|
|
281
|
+
* Applies mutations returned from strategy back to original variables.
|
|
282
|
+
*
|
|
283
|
+
* @param metadata - Switch metadata
|
|
284
|
+
* @returns Mutation application code
|
|
285
|
+
*/
|
|
286
|
+
private generateMutationApplication;
|
|
287
|
+
/**
|
|
288
|
+
* Apply switch replacement after AST has been modified.
|
|
289
|
+
*
|
|
290
|
+
* @param sourceFile - The source file
|
|
291
|
+
* @param originalSwitchText - Original switch text to find
|
|
292
|
+
* @param replacementText - Replacement text
|
|
293
|
+
* @param isInReturnStatement - Whether to replace return statement
|
|
294
|
+
*/
|
|
295
|
+
private applySwitchReplacement;
|
|
296
|
+
/**
|
|
297
|
+
* Insert generated code into the source file.
|
|
298
|
+
*
|
|
299
|
+
* @param sourceFile - The source file
|
|
300
|
+
* @param interfaceCode - Strategy interface code (null if not generated)
|
|
301
|
+
* @param strategyClasses - Array of strategy class code
|
|
302
|
+
* @param factoryClass - Factory class code (null if not generated)
|
|
303
|
+
*/
|
|
304
|
+
private insertGeneratedCode;
|
|
305
|
+
/**
|
|
306
|
+
* Update imports as needed.
|
|
307
|
+
*
|
|
308
|
+
* @param sourceFile - The source file
|
|
309
|
+
* @param api - The Public API
|
|
310
|
+
*/
|
|
311
|
+
private updateImports;
|
|
312
|
+
/**
|
|
313
|
+
* Apply naming pattern template to generate class names.
|
|
314
|
+
*
|
|
315
|
+
* @param pattern - Naming pattern with template variables
|
|
316
|
+
* @param caseValue - The case value (for strategies)
|
|
317
|
+
* @param switchExpression - The switch expression
|
|
318
|
+
* @returns Generated name
|
|
319
|
+
*/
|
|
320
|
+
private applyNamingPattern;
|
|
321
|
+
/**
|
|
322
|
+
* Extract identifier from expression (e.g., "user.type" -> "UserType").
|
|
323
|
+
*
|
|
324
|
+
* @param expression - The switch expression
|
|
325
|
+
* @returns Extracted identifier
|
|
326
|
+
*/
|
|
327
|
+
private extractIdentifierFromExpression;
|
|
328
|
+
/**
|
|
329
|
+
* Convert string to PascalCase.
|
|
330
|
+
*
|
|
331
|
+
* @param str - String to convert
|
|
332
|
+
* @returns PascalCase string
|
|
333
|
+
*/
|
|
334
|
+
private toPascalCase;
|
|
335
|
+
/**
|
|
336
|
+
* Sanitize case value for use in identifiers.
|
|
337
|
+
*
|
|
338
|
+
* @param value - Case value to sanitize
|
|
339
|
+
* @returns Sanitized value safe for identifiers
|
|
340
|
+
*/
|
|
341
|
+
private sanitizeCaseValue;
|
|
342
|
+
/**
|
|
343
|
+
* Get God Switch configuration with defaults.
|
|
344
|
+
*
|
|
345
|
+
* @param config - Plugin configuration
|
|
346
|
+
* @returns Complete configuration with defaults
|
|
347
|
+
*/
|
|
348
|
+
private getGodSwitchConfig;
|
|
349
|
+
}
|
|
350
|
+
//# sourceMappingURL=god-switch-transform-orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"god-switch-transform-orchestrator.d.ts","sourceRoot":"","sources":["../../src/orchestrators/god-switch-transform-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAezD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAuCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,qBAAa,8BAA8B;IACzC;;;;;;;;;OASG;;IAKH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwEG;IACH,GAAG,CAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,GAAG,IAAI;IAkI/C;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAkBvB;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAY5B;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IA4D7B;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAqDxB;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IAiDjC;;;;;;;OAOG;IACH,OAAO,CAAC,wBAAwB;IA2EhC;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAqCzB;;;;;;;OAOG;IACH,OAAO,CAAC,iBAAiB;IA8FzB;;;;;;;OAOG;IACH,OAAO,CAAC,yBAAyB;IA+DjC;;;;;;;OAOG;IACH,OAAO,CAAC,uBAAuB;IAuR/B;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IAgE5B;;;;;;;;OAQG;IACH,OAAO,CAAC,uBAAuB;IA+D/B;;;;;;OAMG;IACH,OAAO,CAAC,2BAA2B;IAiBnC;;;;;;;OAOG;IACH,OAAO,CAAC,sBAAsB;IAmC9B;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAsC3B;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAWrB;;;;;;;OAOG;IACH,OAAO,CAAC,kBAAkB;IAuB1B;;;;;OAKG;IACH,OAAO,CAAC,+BAA+B;IAcvC;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IASpB;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAezB;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;CAgB3B"}
|