logicstamp-context 0.2.4 → 0.2.6
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/LLM_CONTEXT.md +2 -2
- package/README.md +28 -19
- package/dist/cli/commands/compare.d.ts.map +1 -1
- package/dist/cli/commands/compare.js +120 -13
- package/dist/cli/commands/compare.js.map +1 -1
- package/dist/cli/commands/context/fileWriter.d.ts.map +1 -1
- package/dist/cli/commands/context/fileWriter.js +68 -6
- package/dist/cli/commands/context/fileWriter.js.map +1 -1
- package/dist/cli/commands/context/tokenEstimator.d.ts.map +1 -1
- package/dist/cli/commands/context/tokenEstimator.js +12 -4
- package/dist/cli/commands/context/tokenEstimator.js.map +1 -1
- package/dist/cli/commands/context.d.ts.map +1 -1
- package/dist/cli/commands/context.js +71 -2
- package/dist/cli/commands/context.js.map +1 -1
- package/dist/cli/commands/validate.d.ts.map +1 -1
- package/dist/cli/commands/validate.js +84 -8
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/handlers/compareHandler.d.ts.map +1 -1
- package/dist/cli/handlers/compareHandler.js +123 -9
- package/dist/cli/handlers/compareHandler.js.map +1 -1
- package/dist/core/astParser/detectors.d.ts.map +1 -1
- package/dist/core/astParser/detectors.js +130 -57
- package/dist/core/astParser/detectors.js.map +1 -1
- package/dist/core/astParser/extractors/componentExtractor.d.ts.map +1 -1
- package/dist/core/astParser/extractors/componentExtractor.js +89 -20
- package/dist/core/astParser/extractors/componentExtractor.js.map +1 -1
- package/dist/core/astParser/extractors/eventExtractor.d.ts.map +1 -1
- package/dist/core/astParser/extractors/eventExtractor.js +83 -28
- package/dist/core/astParser/extractors/eventExtractor.js.map +1 -1
- package/dist/core/astParser/extractors/propExtractor.d.ts.map +1 -1
- package/dist/core/astParser/extractors/propExtractor.js +142 -51
- package/dist/core/astParser/extractors/propExtractor.js.map +1 -1
- package/dist/core/astParser/extractors/stateExtractor.d.ts.map +1 -1
- package/dist/core/astParser/extractors/stateExtractor.js +95 -44
- package/dist/core/astParser/extractors/stateExtractor.js.map +1 -1
- package/dist/core/astParser.d.ts +4 -1
- package/dist/core/astParser.d.ts.map +1 -1
- package/dist/core/astParser.js +183 -26
- package/dist/core/astParser.js.map +1 -1
- package/dist/core/contractBuilder.d.ts.map +1 -1
- package/dist/core/contractBuilder.js +11 -15
- package/dist/core/contractBuilder.js.map +1 -1
- package/dist/core/manifest.d.ts.map +1 -1
- package/dist/core/manifest.js +82 -4
- package/dist/core/manifest.js.map +1 -1
- package/dist/core/pack/loader.d.ts.map +1 -1
- package/dist/core/pack/loader.js +22 -2
- package/dist/core/pack/loader.js.map +1 -1
- package/dist/core/pack.d.ts.map +1 -1
- package/dist/core/pack.js +57 -1
- package/dist/core/pack.js.map +1 -1
- package/dist/core/styleExtractor/index.d.ts +1 -0
- package/dist/core/styleExtractor/index.d.ts.map +1 -1
- package/dist/core/styleExtractor/index.js +1 -0
- package/dist/core/styleExtractor/index.js.map +1 -1
- package/dist/core/styleExtractor/layout.d.ts +13 -2
- package/dist/core/styleExtractor/layout.d.ts.map +1 -1
- package/dist/core/styleExtractor/layout.js +135 -65
- package/dist/core/styleExtractor/layout.js.map +1 -1
- package/dist/core/styleExtractor/material.d.ts.map +1 -1
- package/dist/core/styleExtractor/material.js +291 -66
- package/dist/core/styleExtractor/material.js.map +1 -1
- package/dist/core/styleExtractor/motion.d.ts +2 -2
- package/dist/core/styleExtractor/motion.d.ts.map +1 -1
- package/dist/core/styleExtractor/motion.js +425 -56
- package/dist/core/styleExtractor/motion.js.map +1 -1
- package/dist/core/styleExtractor/radix.d.ts +29 -0
- package/dist/core/styleExtractor/radix.d.ts.map +1 -0
- package/dist/core/styleExtractor/radix.js +315 -0
- package/dist/core/styleExtractor/radix.js.map +1 -0
- package/dist/core/styleExtractor/scss.d.ts.map +1 -1
- package/dist/core/styleExtractor/scss.js +37 -23
- package/dist/core/styleExtractor/scss.js.map +1 -1
- package/dist/core/styleExtractor/shadcn.d.ts +20 -0
- package/dist/core/styleExtractor/shadcn.d.ts.map +1 -0
- package/dist/core/styleExtractor/shadcn.js +345 -0
- package/dist/core/styleExtractor/shadcn.js.map +1 -0
- package/dist/core/styleExtractor/styleExtractor.d.ts.map +1 -1
- package/dist/core/styleExtractor/styleExtractor.js +267 -89
- package/dist/core/styleExtractor/styleExtractor.js.map +1 -1
- package/dist/core/styleExtractor/styled.d.ts +1 -1
- package/dist/core/styleExtractor/styled.d.ts.map +1 -1
- package/dist/core/styleExtractor/styled.js +308 -23
- package/dist/core/styleExtractor/styled.js.map +1 -1
- package/dist/core/styleExtractor/tailwind.d.ts +21 -3
- package/dist/core/styleExtractor/tailwind.d.ts.map +1 -1
- package/dist/core/styleExtractor/tailwind.js +279 -46
- package/dist/core/styleExtractor/tailwind.js.map +1 -1
- package/dist/types/UIFContract.d.ts +34 -0
- package/dist/types/UIFContract.d.ts.map +1 -1
- package/dist/types/UIFContract.js.map +1 -1
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +41 -2
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/debug.d.ts +12 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/debug.js +16 -0
- package/dist/utils/debug.js.map +1 -0
- package/dist/utils/fsx.d.ts +2 -1
- package/dist/utils/fsx.d.ts.map +1 -1
- package/dist/utils/fsx.js +99 -28
- package/dist/utils/fsx.js.map +1 -1
- package/dist/utils/gitignore.d.ts.map +1 -1
- package/dist/utils/gitignore.js +28 -1
- package/dist/utils/gitignore.js.map +1 -1
- package/package.json +1 -1
- package/schema/logicstamp.context.schema.json +26 -1
|
@@ -1,73 +1,164 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Prop Extractor - Extracts component props from TypeScript interfaces/types
|
|
3
3
|
*/
|
|
4
|
+
import { debugError } from '../../../utils/debug.js';
|
|
4
5
|
/**
|
|
5
6
|
* Extract component props from TypeScript interfaces/types
|
|
6
7
|
*/
|
|
7
8
|
export function extractProps(source) {
|
|
8
9
|
const props = {};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const filePath = source.getFilePath?.() ?? 'unknown';
|
|
11
|
+
try {
|
|
12
|
+
// Look for interfaces ending with Props
|
|
13
|
+
try {
|
|
14
|
+
source.getInterfaces().forEach((iface) => {
|
|
15
|
+
try {
|
|
16
|
+
if (/Props$/i.test(iface.getName())) {
|
|
17
|
+
iface.getProperties().forEach((prop) => {
|
|
18
|
+
try {
|
|
19
|
+
const name = prop.getName();
|
|
20
|
+
const isOptional = prop.hasQuestionToken();
|
|
21
|
+
const type = prop.getType().getText();
|
|
22
|
+
props[name] = normalizePropType(type, isOptional);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
debugError('propExtractor', 'extractProps', {
|
|
26
|
+
filePath,
|
|
27
|
+
error: error instanceof Error ? error.message : String(error),
|
|
28
|
+
context: 'props-interface-property',
|
|
29
|
+
});
|
|
30
|
+
// Continue with next property
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
debugError('propExtractor', 'extractProps', {
|
|
37
|
+
filePath,
|
|
38
|
+
error: error instanceof Error ? error.message : String(error),
|
|
39
|
+
context: 'props-interface',
|
|
40
|
+
});
|
|
41
|
+
// Continue with next interface
|
|
42
|
+
}
|
|
17
43
|
});
|
|
18
44
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const properties = type.getProperties();
|
|
25
|
-
properties.forEach((prop) => {
|
|
26
|
-
const name = prop.getName();
|
|
27
|
-
const propType = prop.getTypeAtLocation(typeAlias).getText();
|
|
28
|
-
// Check if optional from declaration
|
|
29
|
-
const declarations = prop.getDeclarations();
|
|
30
|
-
const isOptional = declarations.some((decl) => decl.getText().includes('?:'));
|
|
31
|
-
props[name] = normalizePropType(propType, isOptional);
|
|
45
|
+
catch (error) {
|
|
46
|
+
debugError('propExtractor', 'extractProps', {
|
|
47
|
+
filePath,
|
|
48
|
+
error: error instanceof Error ? error.message : String(error),
|
|
49
|
+
context: 'props-interfaces-batch',
|
|
32
50
|
});
|
|
33
51
|
}
|
|
34
|
-
|
|
52
|
+
// Look for type aliases ending with Props
|
|
53
|
+
try {
|
|
54
|
+
source.getTypeAliases().forEach((typeAlias) => {
|
|
55
|
+
try {
|
|
56
|
+
if (/Props$/i.test(typeAlias.getName())) {
|
|
57
|
+
const type = typeAlias.getType();
|
|
58
|
+
const properties = type.getProperties();
|
|
59
|
+
properties.forEach((prop) => {
|
|
60
|
+
try {
|
|
61
|
+
const name = prop.getName();
|
|
62
|
+
const propType = prop.getTypeAtLocation(typeAlias).getText();
|
|
63
|
+
// Check if optional using fast methods
|
|
64
|
+
let isOptional = false;
|
|
65
|
+
// Method 1: If type includes undefined in union, it's optional
|
|
66
|
+
if (propType.includes('undefined')) {
|
|
67
|
+
isOptional = true;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Method 2: Check declarations for question token (faster than getText())
|
|
71
|
+
const declarations = prop.getDeclarations();
|
|
72
|
+
isOptional = declarations.some((decl) => {
|
|
73
|
+
// Use AST method to check for question token (faster than text parsing)
|
|
74
|
+
return decl.hasQuestionToken?.() === true;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
props[name] = normalizePropType(propType, isOptional);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
debugError('propExtractor', 'extractProps', {
|
|
81
|
+
filePath,
|
|
82
|
+
error: error instanceof Error ? error.message : String(error),
|
|
83
|
+
context: 'props-typealias-property',
|
|
84
|
+
});
|
|
85
|
+
// Continue with next property
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
debugError('propExtractor', 'extractProps', {
|
|
92
|
+
filePath,
|
|
93
|
+
error: error instanceof Error ? error.message : String(error),
|
|
94
|
+
context: 'props-typealias',
|
|
95
|
+
});
|
|
96
|
+
// Continue with next type alias
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
debugError('propExtractor', 'extractProps', {
|
|
102
|
+
filePath,
|
|
103
|
+
error: error instanceof Error ? error.message : String(error),
|
|
104
|
+
context: 'props-typealiases-batch',
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
debugError('propExtractor', 'extractProps', {
|
|
110
|
+
filePath,
|
|
111
|
+
error: error instanceof Error ? error.message : String(error),
|
|
112
|
+
});
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
35
115
|
return props;
|
|
36
116
|
}
|
|
37
117
|
/**
|
|
38
118
|
* Normalize a prop type into the rich PropType format
|
|
39
119
|
*/
|
|
40
120
|
export function normalizePropType(typeText, isOptional) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
121
|
+
try {
|
|
122
|
+
// Remove 'undefined' from unions if present
|
|
123
|
+
const cleanType = typeText.replace(/\s*\|\s*undefined/g, '').trim();
|
|
124
|
+
// Detect literal unions: "a" | "b" | "c"
|
|
125
|
+
const literalUnionMatch = cleanType.match(/^("[\w-]+"(\s*\|\s*"[\w-]+")+)$/);
|
|
126
|
+
if (literalUnionMatch) {
|
|
127
|
+
const literals = cleanType
|
|
128
|
+
.split('|')
|
|
129
|
+
.map(t => t.trim().replace(/^"|"$/g, ''));
|
|
130
|
+
return {
|
|
131
|
+
type: 'literal-union',
|
|
132
|
+
literals,
|
|
133
|
+
...(isOptional && { optional: true })
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// Detect function types: () => void, (x: string) => void
|
|
137
|
+
if (cleanType.includes('=>') || cleanType.startsWith('(') && cleanType.includes(')')) {
|
|
138
|
+
return {
|
|
139
|
+
type: 'function',
|
|
140
|
+
signature: cleanType,
|
|
141
|
+
...(isOptional && { optional: true })
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// Simple type with optionality
|
|
145
|
+
if (isOptional) {
|
|
146
|
+
// For all optional types, return object with optional flag to preserve the optional information
|
|
147
|
+
return {
|
|
148
|
+
type: cleanType,
|
|
149
|
+
optional: true
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
// Return simple string for common types (backward compat)
|
|
153
|
+
return cleanType;
|
|
62
154
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
155
|
+
catch (error) {
|
|
156
|
+
// Fallback to simple string type on error
|
|
157
|
+
debugError('propExtractor', 'normalizePropType', {
|
|
158
|
+
error: error instanceof Error ? error.message : String(error),
|
|
159
|
+
typeText,
|
|
160
|
+
});
|
|
161
|
+
return typeText;
|
|
69
162
|
}
|
|
70
|
-
// Return simple string for common types (backward compat)
|
|
71
|
-
return cleanType;
|
|
72
163
|
}
|
|
73
164
|
//# sourceMappingURL=propExtractor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propExtractor.js","sourceRoot":"","sources":["../../../../src/core/astParser/extractors/propExtractor.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"propExtractor.js","sourceRoot":"","sources":["../../../../src/core/astParser/extractors/propExtractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC7C,M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BACf,QAAQ,EAAE,IAAI;aACf,CAAC;QACJ,CAAC;QAED,0DAA0D;QAC1D,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,0CAA0C;QAC1C,UAAU,CAAC,eAAe,EAAE,mBAAmB,EAAE;YAC/C,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC7D,QAAQ;SACT,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateExtractor.d.ts","sourceRoot":"","sources":["../../../../src/core/astParser/extractors/stateExtractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"stateExtractor.d.ts","sourceRoot":"","sources":["../../../../src/core/astParser/extractors/stateExtractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAC;AAGlD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,EAAE,CA8B7D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoEvE"}
|
|
@@ -2,18 +2,39 @@
|
|
|
2
2
|
* State Extractor - Extracts component state and variable declarations from AST
|
|
3
3
|
*/
|
|
4
4
|
import { SyntaxKind } from 'ts-morph';
|
|
5
|
+
import { debugError } from '../../../utils/debug.js';
|
|
5
6
|
/**
|
|
6
7
|
* Extract all variable declarations (const, let, var)
|
|
7
8
|
*/
|
|
8
9
|
export function extractVariables(source) {
|
|
9
10
|
const variables = new Set();
|
|
10
|
-
source.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const filePath = source.getFilePath?.() ?? 'unknown';
|
|
12
|
+
try {
|
|
13
|
+
source.getVariableDeclarations().forEach((varDecl) => {
|
|
14
|
+
try {
|
|
15
|
+
const name = varDecl.getName();
|
|
16
|
+
// Skip destructured state setters (e.g., setCount from [count, setCount])
|
|
17
|
+
if (!name.startsWith('set') || !varDecl.getParent()?.getText().includes('useState')) {
|
|
18
|
+
variables.add(name);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
debugError('stateExtractor', 'extractVariables', {
|
|
23
|
+
filePath,
|
|
24
|
+
error: error instanceof Error ? error.message : String(error),
|
|
25
|
+
context: 'variables-iteration',
|
|
26
|
+
});
|
|
27
|
+
// Continue with next variable
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
debugError('stateExtractor', 'extractVariables', {
|
|
33
|
+
filePath,
|
|
34
|
+
error: error instanceof Error ? error.message : String(error),
|
|
35
|
+
});
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
17
38
|
return Array.from(variables).sort();
|
|
18
39
|
}
|
|
19
40
|
/**
|
|
@@ -21,46 +42,76 @@ export function extractVariables(source) {
|
|
|
21
42
|
*/
|
|
22
43
|
export function extractState(source) {
|
|
23
44
|
const state = {};
|
|
24
|
-
source.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
const filePath = source.getFilePath?.() ?? 'unknown';
|
|
46
|
+
try {
|
|
47
|
+
source.getDescendantsOfKind(SyntaxKind.VariableDeclaration).forEach((varDecl) => {
|
|
48
|
+
try {
|
|
49
|
+
const initializer = varDecl.getInitializer();
|
|
50
|
+
if (!initializer)
|
|
51
|
+
return;
|
|
52
|
+
const initText = initializer.getText();
|
|
53
|
+
if (initText.startsWith('useState(') || initText.startsWith('useState<')) {
|
|
54
|
+
const bindingName = varDecl.getName();
|
|
55
|
+
// Extract state variable name from array destructuring [value, setValue]
|
|
56
|
+
const match = bindingName.match(/\[([a-zA-Z0-9_]+)\s*,/);
|
|
57
|
+
if (match) {
|
|
58
|
+
const stateVar = match[1];
|
|
59
|
+
// Try to infer type from generic or initial value
|
|
60
|
+
let type = 'unknown';
|
|
61
|
+
try {
|
|
62
|
+
const genericMatch = initText.match(/useState<([^>]+)>/);
|
|
63
|
+
if (genericMatch) {
|
|
64
|
+
type = genericMatch[1];
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Infer from initial value
|
|
68
|
+
const valueMatch = initText.match(/useState\(([^)]+)\)/);
|
|
69
|
+
if (valueMatch) {
|
|
70
|
+
const value = valueMatch[1].trim();
|
|
71
|
+
if (value === 'true' || value === 'false')
|
|
72
|
+
type = 'boolean';
|
|
73
|
+
else if (/^\d+$/.test(value))
|
|
74
|
+
type = 'number';
|
|
75
|
+
else if (/^["']/.test(value))
|
|
76
|
+
type = 'string';
|
|
77
|
+
else if (value === 'null')
|
|
78
|
+
type = 'null';
|
|
79
|
+
else if (value === '[]')
|
|
80
|
+
type = 'array';
|
|
81
|
+
else if (value === '{}')
|
|
82
|
+
type = 'object';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
debugError('stateExtractor', 'extractState', {
|
|
88
|
+
filePath,
|
|
89
|
+
error: error instanceof Error ? error.message : String(error),
|
|
90
|
+
context: 'state-type-inference',
|
|
91
|
+
});
|
|
92
|
+
// Use 'unknown' as fallback
|
|
93
|
+
}
|
|
94
|
+
state[stateVar] = type;
|
|
58
95
|
}
|
|
59
96
|
}
|
|
60
|
-
state[stateVar] = type;
|
|
61
97
|
}
|
|
62
|
-
|
|
63
|
-
|
|
98
|
+
catch (error) {
|
|
99
|
+
debugError('stateExtractor', 'extractState', {
|
|
100
|
+
filePath,
|
|
101
|
+
error: error instanceof Error ? error.message : String(error),
|
|
102
|
+
context: 'state-iteration',
|
|
103
|
+
});
|
|
104
|
+
// Continue with next declaration
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
debugError('stateExtractor', 'extractState', {
|
|
110
|
+
filePath,
|
|
111
|
+
error: error instanceof Error ? error.message : String(error),
|
|
112
|
+
});
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
64
115
|
return state;
|
|
65
116
|
}
|
|
66
117
|
//# sourceMappingURL=stateExtractor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateExtractor.js","sourceRoot":"","sources":["../../../../src/core/astParser/extractors/stateExtractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"stateExtractor.js","sourceRoot":"","sources":["../../../../src/core/astParser/extractors/stateExtractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAkB;IACjD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IACpC,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,SAAS,CAAC;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,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/core/astParser.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* semantic: uif:7152990a34f9eda63e745359 (informational)
|
|
23
23
|
* file: uif:d25bdbc8e21386b1a5e907d7
|
|
24
24
|
*/
|
|
25
|
-
import type { LogicSignature, ContractKind, PropType, EventType, NextJSMetadata } from '../types/UIFContract.js';
|
|
25
|
+
import type { LogicSignature, ContractKind, PropType, EventType, NextJSMetadata, ExportMetadata } from '../types/UIFContract.js';
|
|
26
26
|
export interface AstExtract {
|
|
27
27
|
kind: ContractKind;
|
|
28
28
|
variables: string[];
|
|
@@ -35,9 +35,12 @@ export interface AstExtract {
|
|
|
35
35
|
imports: string[];
|
|
36
36
|
jsxRoutes: string[];
|
|
37
37
|
nextjs?: NextJSMetadata;
|
|
38
|
+
exports?: ExportMetadata;
|
|
39
|
+
exportedFunctions?: string[];
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* Extract all structural information from a TypeScript/React file
|
|
43
|
+
* Returns empty AST on parsing errors to prevent crashes
|
|
41
44
|
*/
|
|
42
45
|
export declare function extractFromFile(filePath: string): Promise<AstExtract>;
|
|
43
46
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astParser.d.ts","sourceRoot":"","sources":["../../src/core/astParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAQH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"astParser.d.ts","sourceRoot":"","sources":["../../src/core/astParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAQH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAQjI,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACjC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAuBD;;;GAGG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAgE3E;AAkKD;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,UAAU,GAAG,cAAc,CAM1E"}
|