@memberjunction/react-test-harness 2.120.0 → 2.122.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.
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Type Inference Engine - AST-based type inference for component linting
3
+ *
4
+ * This module analyzes JavaScript AST to infer and track types throughout
5
+ * component code. It integrates with TypeContext to provide comprehensive
6
+ * type information for validation rules.
7
+ */
8
+ import { NodePath } from '@babel/traverse';
9
+ import * as t from '@babel/types';
10
+ import { ComponentSpec } from '@memberjunction/interactive-component-types';
11
+ import { UserInfo } from '@memberjunction/core';
12
+ import { TypeContext, TypeInfo } from './type-context';
13
+ /**
14
+ * Result of type inference analysis
15
+ */
16
+ export interface TypeInferenceResult {
17
+ /** The type context with all inferred variable types */
18
+ typeContext: TypeContext;
19
+ /** Any type errors or warnings found during inference */
20
+ errors: TypeInferenceError[];
21
+ }
22
+ /**
23
+ * A type error or warning found during inference
24
+ */
25
+ export interface TypeInferenceError {
26
+ type: 'error' | 'warning';
27
+ message: string;
28
+ line: number;
29
+ column: number;
30
+ code?: string;
31
+ }
32
+ /**
33
+ * TypeInferenceEngine - Analyzes AST to infer and track types
34
+ */
35
+ export declare class TypeInferenceEngine {
36
+ private typeContext;
37
+ private errors;
38
+ private componentSpec?;
39
+ private contextUser?;
40
+ private functionReturnTypes;
41
+ constructor(componentSpec?: ComponentSpec, contextUser?: UserInfo);
42
+ /**
43
+ * Analyze an AST and build type context
44
+ */
45
+ analyze(ast: t.File): Promise<TypeInferenceResult>;
46
+ /**
47
+ * Get the type context after analysis
48
+ */
49
+ getTypeContext(): TypeContext;
50
+ /**
51
+ * First pass: collect variable types from declarations and assignments
52
+ */
53
+ private collectVariableTypes;
54
+ /**
55
+ * Infer type from a variable declarator
56
+ */
57
+ private inferDeclaratorType;
58
+ /**
59
+ * Infer type from an assignment expression
60
+ */
61
+ private inferAssignmentType;
62
+ /**
63
+ * Infer types for function parameters (component props)
64
+ */
65
+ private inferFunctionParameterTypes;
66
+ /**
67
+ * Infer types for arrow function parameters
68
+ */
69
+ private inferArrowFunctionParameterTypes;
70
+ /**
71
+ * Infer types for component props from destructuring pattern
72
+ */
73
+ private inferComponentPropsTypes;
74
+ /**
75
+ * Track function return type by analyzing its body
76
+ */
77
+ private trackFunctionReturnType;
78
+ /**
79
+ * Analyze common object-building patterns in function bodies
80
+ * Pattern: const obj = {}; forEach(...) { obj[key] = { prop: value } }; return obj;
81
+ */
82
+ private analyzeObjectBuildingPattern;
83
+ /**
84
+ * Map component spec type to JavaScript type
85
+ */
86
+ private mapSpecTypeToJSType;
87
+ /**
88
+ * Infer types from object destructuring
89
+ */
90
+ private inferDestructuringTypes;
91
+ /**
92
+ * Infer types from array destructuring
93
+ */
94
+ private inferArrayDestructuringTypes;
95
+ /**
96
+ * Infer the type of an expression
97
+ */
98
+ inferExpressionType(node: t.Expression | t.SpreadElement | t.JSXNamespacedName | t.ArgumentPlaceholder, path?: NodePath): TypeInfo;
99
+ /**
100
+ * Infer type for array expressions
101
+ */
102
+ private inferArrayType;
103
+ /**
104
+ * Infer type for object expressions
105
+ */
106
+ private inferObjectType;
107
+ /**
108
+ * Infer type for call expressions
109
+ */
110
+ private inferCallExpressionType;
111
+ /**
112
+ * Infer type for new expressions (constructor calls)
113
+ */
114
+ private inferNewExpressionType;
115
+ /**
116
+ * Infer type for RunView result
117
+ */
118
+ private inferRunViewResultType;
119
+ /**
120
+ * Infer type for RunQuery result
121
+ */
122
+ private inferRunQueryResultType;
123
+ /**
124
+ * Infer type for member expressions
125
+ */
126
+ private inferMemberExpressionType;
127
+ /**
128
+ * Infer type for binary expressions
129
+ */
130
+ private inferBinaryExpressionType;
131
+ /**
132
+ * Infer type for unary expressions
133
+ */
134
+ private inferUnaryExpressionType;
135
+ /**
136
+ * Get inferred type for a variable by name
137
+ */
138
+ getVariableType(name: string): TypeInfo | undefined;
139
+ /**
140
+ * Check if an expression is a specific type
141
+ */
142
+ isType(node: t.Expression, expectedType: string, path?: NodePath): boolean;
143
+ }
144
+ /**
145
+ * Convenience function to analyze an AST and return type context
146
+ */
147
+ export declare function analyzeTypes(ast: t.File, componentSpec?: ComponentSpec, contextUser?: UserInfo): Promise<TypeInferenceResult>;
148
+ //# sourceMappingURL=type-inference-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-inference-engine.d.ts","sourceRoot":"","sources":["../../src/lib/type-inference-engine.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAiB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EACL,WAAW,EACX,QAAQ,EAMT,MAAM,gBAAgB,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,wDAAwD;IACxD,WAAW,EAAE,WAAW,CAAC;IACzB,yDAAyD;IACzD,MAAM,EAAE,kBAAkB,EAAE,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,aAAa,CAAC,CAAgB;IACtC,OAAO,CAAC,WAAW,CAAC,CAAW;IAC/B,OAAO,CAAC,mBAAmB,CAAoC;gBAEnD,aAAa,CAAC,EAAE,aAAa,EAAE,WAAW,CAAC,EAAE,QAAQ;IAMjE;;OAEG;IACG,OAAO,CAAC,GAAG,EAAE,CA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