@tsonic/frontend 0.0.1
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/package.json +53 -0
- package/src/dependency-graph.ts +18 -0
- package/src/dotnet-metadata.ts +121 -0
- package/src/graph/builder.ts +81 -0
- package/src/graph/circular.ts +58 -0
- package/src/graph/extraction/exports.ts +55 -0
- package/src/graph/extraction/imports.ts +81 -0
- package/src/graph/extraction/index.ts +7 -0
- package/src/graph/extraction/orchestrator.ts +99 -0
- package/src/graph/extraction.ts +10 -0
- package/src/graph/helpers.ts +51 -0
- package/src/graph/index.ts +17 -0
- package/src/graph/types.ts +13 -0
- package/src/index.ts +80 -0
- package/src/ir/binding-resolution.test.ts +585 -0
- package/src/ir/builder/exports.ts +78 -0
- package/src/ir/builder/helpers.ts +27 -0
- package/src/ir/builder/imports.ts +153 -0
- package/src/ir/builder/index.ts +10 -0
- package/src/ir/builder/orchestrator.ts +178 -0
- package/src/ir/builder/statements.ts +55 -0
- package/src/ir/builder/types.ts +8 -0
- package/src/ir/builder/validation.ts +129 -0
- package/src/ir/builder.test.ts +581 -0
- package/src/ir/builder.ts +14 -0
- package/src/ir/converters/expressions/access.ts +99 -0
- package/src/ir/converters/expressions/calls.ts +137 -0
- package/src/ir/converters/expressions/collections.ts +84 -0
- package/src/ir/converters/expressions/functions.ts +62 -0
- package/src/ir/converters/expressions/helpers.ts +264 -0
- package/src/ir/converters/expressions/index.ts +43 -0
- package/src/ir/converters/expressions/literals.ts +22 -0
- package/src/ir/converters/expressions/operators.ts +147 -0
- package/src/ir/converters/expressions/other.ts +60 -0
- package/src/ir/converters/statements/control/blocks.ts +22 -0
- package/src/ir/converters/statements/control/conditionals.ts +67 -0
- package/src/ir/converters/statements/control/exceptions.ts +43 -0
- package/src/ir/converters/statements/control/index.ts +17 -0
- package/src/ir/converters/statements/control/loops.ts +99 -0
- package/src/ir/converters/statements/control.ts +17 -0
- package/src/ir/converters/statements/declarations/classes/constructors.ts +120 -0
- package/src/ir/converters/statements/declarations/classes/index.ts +12 -0
- package/src/ir/converters/statements/declarations/classes/methods.ts +61 -0
- package/src/ir/converters/statements/declarations/classes/orchestrator.ts +166 -0
- package/src/ir/converters/statements/declarations/classes/override-detection.ts +116 -0
- package/src/ir/converters/statements/declarations/classes/properties.ts +63 -0
- package/src/ir/converters/statements/declarations/classes.ts +6 -0
- package/src/ir/converters/statements/declarations/enums.ts +29 -0
- package/src/ir/converters/statements/declarations/functions.ts +39 -0
- package/src/ir/converters/statements/declarations/index.ts +14 -0
- package/src/ir/converters/statements/declarations/interfaces.ts +131 -0
- package/src/ir/converters/statements/declarations/registry.ts +45 -0
- package/src/ir/converters/statements/declarations/type-aliases.ts +25 -0
- package/src/ir/converters/statements/declarations/variables.ts +60 -0
- package/src/ir/converters/statements/declarations.ts +16 -0
- package/src/ir/converters/statements/helpers.ts +174 -0
- package/src/ir/converters/statements/index.ts +40 -0
- package/src/ir/expression-converter.ts +207 -0
- package/src/ir/generic-validator.ts +100 -0
- package/src/ir/hierarchical-bindings-e2e.test.ts +163 -0
- package/src/ir/index.ts +6 -0
- package/src/ir/statement-converter.ts +128 -0
- package/src/ir/type-converter/arrays.ts +20 -0
- package/src/ir/type-converter/converter.ts +10 -0
- package/src/ir/type-converter/functions.ts +22 -0
- package/src/ir/type-converter/index.ts +11 -0
- package/src/ir/type-converter/inference.ts +122 -0
- package/src/ir/type-converter/literals.ts +40 -0
- package/src/ir/type-converter/objects.ts +107 -0
- package/src/ir/type-converter/orchestrator.ts +85 -0
- package/src/ir/type-converter/patterns.ts +73 -0
- package/src/ir/type-converter/primitives.ts +57 -0
- package/src/ir/type-converter/references.ts +64 -0
- package/src/ir/type-converter/unions-intersections.ts +34 -0
- package/src/ir/type-converter.ts +13 -0
- package/src/ir/types/expressions.ts +215 -0
- package/src/ir/types/guards.ts +39 -0
- package/src/ir/types/helpers.ts +135 -0
- package/src/ir/types/index.ts +108 -0
- package/src/ir/types/ir-types.ts +96 -0
- package/src/ir/types/module.ts +57 -0
- package/src/ir/types/statements.ts +238 -0
- package/src/ir/types.ts +97 -0
- package/src/metadata/bindings-loader.test.ts +144 -0
- package/src/metadata/bindings-loader.ts +357 -0
- package/src/metadata/index.ts +15 -0
- package/src/metadata/library-loader.ts +153 -0
- package/src/metadata/loader.test.ts +156 -0
- package/src/metadata/loader.ts +382 -0
- package/src/program/bindings.test.ts +512 -0
- package/src/program/bindings.ts +253 -0
- package/src/program/config.ts +30 -0
- package/src/program/creation.ts +249 -0
- package/src/program/dependency-graph.ts +245 -0
- package/src/program/diagnostics.ts +103 -0
- package/src/program/index.ts +19 -0
- package/src/program/metadata.ts +68 -0
- package/src/program/queries.ts +18 -0
- package/src/program/types.ts +38 -0
- package/src/program.ts +13 -0
- package/src/resolver/dotnet-import-resolver.ts +226 -0
- package/src/resolver/import-resolution.ts +177 -0
- package/src/resolver/index.ts +18 -0
- package/src/resolver/namespace.test.ts +86 -0
- package/src/resolver/namespace.ts +42 -0
- package/src/resolver/naming.ts +38 -0
- package/src/resolver/path-resolution.ts +22 -0
- package/src/resolver/types.ts +15 -0
- package/src/resolver.test.ts +155 -0
- package/src/resolver.ts +14 -0
- package/src/symbol-table/builder.ts +114 -0
- package/src/symbol-table/creation.ts +42 -0
- package/src/symbol-table/helpers.ts +18 -0
- package/src/symbol-table/index.ts +13 -0
- package/src/symbol-table/queries.ts +42 -0
- package/src/symbol-table/types.ts +28 -0
- package/src/symbol-table.ts +14 -0
- package/src/types/bindings.ts +172 -0
- package/src/types/diagnostic.test.ts +164 -0
- package/src/types/diagnostic.ts +153 -0
- package/src/types/explicit-views.test.ts +113 -0
- package/src/types/explicit-views.ts +218 -0
- package/src/types/metadata.ts +229 -0
- package/src/types/module.ts +99 -0
- package/src/types/nested-types.test.ts +194 -0
- package/src/types/nested-types.ts +215 -0
- package/src/types/parameter-modifiers.ts +173 -0
- package/src/types/ref-parameters.test.ts +192 -0
- package/src/types/ref-parameters.ts +268 -0
- package/src/types/result.test.ts +157 -0
- package/src/types/result.ts +48 -0
- package/src/types/support-types.test.ts +81 -0
- package/src/types/support-types.ts +288 -0
- package/src/types/test-harness.ts +180 -0
- package/src/validation/exports.ts +98 -0
- package/src/validation/features.ts +89 -0
- package/src/validation/generics.ts +40 -0
- package/src/validation/helpers.ts +31 -0
- package/src/validation/imports.ts +97 -0
- package/src/validation/index.ts +11 -0
- package/src/validation/orchestrator.ts +51 -0
- package/src/validation/static-safety.ts +267 -0
- package/src/validator.test.ts +468 -0
- package/src/validator.ts +15 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supporting types (patterns, parameters, operators, accessibility, etc.)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { IrType } from "./ir-types.js";
|
|
6
|
+
import { IrExpression } from "./expressions.js";
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Patterns (for destructuring)
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
export type IrPattern = IrIdentifierPattern | IrArrayPattern | IrObjectPattern;
|
|
13
|
+
|
|
14
|
+
export type IrIdentifierPattern = {
|
|
15
|
+
readonly kind: "identifierPattern";
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly type?: IrType;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type IrArrayPattern = {
|
|
21
|
+
readonly kind: "arrayPattern";
|
|
22
|
+
readonly elements: readonly (IrPattern | undefined)[]; // undefined for holes
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type IrObjectPattern = {
|
|
26
|
+
readonly kind: "objectPattern";
|
|
27
|
+
readonly properties: readonly IrObjectPatternProperty[];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type IrObjectPatternProperty =
|
|
31
|
+
| {
|
|
32
|
+
readonly kind: "property";
|
|
33
|
+
readonly key: string;
|
|
34
|
+
readonly value: IrPattern;
|
|
35
|
+
readonly shorthand: boolean;
|
|
36
|
+
}
|
|
37
|
+
| { readonly kind: "rest"; readonly pattern: IrPattern };
|
|
38
|
+
|
|
39
|
+
// ============================================================================
|
|
40
|
+
// Type Parameters
|
|
41
|
+
// ============================================================================
|
|
42
|
+
|
|
43
|
+
export type IrTypeParameter = {
|
|
44
|
+
readonly kind: "typeParameter";
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly constraint?: IrType; // Can reference other type parameters (enables recursion)
|
|
47
|
+
readonly default?: IrType;
|
|
48
|
+
readonly variance?: "in" | "out"; // For covariance/contravariance
|
|
49
|
+
readonly isStructuralConstraint?: boolean; // Flag for { id: number } style constraints
|
|
50
|
+
readonly structuralMembers?: readonly IrInterfaceMember[]; // Properties for structural constraints
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// ============================================================================
|
|
54
|
+
// Parameters
|
|
55
|
+
// ============================================================================
|
|
56
|
+
|
|
57
|
+
export type IrParameter = {
|
|
58
|
+
readonly kind: "parameter";
|
|
59
|
+
readonly pattern: IrPattern;
|
|
60
|
+
readonly type?: IrType;
|
|
61
|
+
readonly initializer?: IrExpression;
|
|
62
|
+
readonly isOptional: boolean;
|
|
63
|
+
readonly isRest: boolean;
|
|
64
|
+
readonly passing: "value" | "ref" | "out" | "in"; // C# parameter passing mode
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// Interface Members (used by interfaces and object types)
|
|
69
|
+
// ============================================================================
|
|
70
|
+
|
|
71
|
+
export type IrInterfaceMember = IrPropertySignature | IrMethodSignature;
|
|
72
|
+
|
|
73
|
+
export type IrPropertySignature = {
|
|
74
|
+
readonly kind: "propertySignature";
|
|
75
|
+
readonly name: string;
|
|
76
|
+
readonly type: IrType;
|
|
77
|
+
readonly isOptional: boolean;
|
|
78
|
+
readonly isReadonly: boolean;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type IrMethodSignature = {
|
|
82
|
+
readonly kind: "methodSignature";
|
|
83
|
+
readonly name: string;
|
|
84
|
+
readonly typeParameters?: readonly IrTypeParameter[];
|
|
85
|
+
readonly parameters: readonly IrParameter[];
|
|
86
|
+
readonly returnType?: IrType;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// ============================================================================
|
|
90
|
+
// Accessibility and Operators
|
|
91
|
+
// ============================================================================
|
|
92
|
+
|
|
93
|
+
export type IrAccessibility = "public" | "private" | "protected";
|
|
94
|
+
|
|
95
|
+
export type IrBinaryOperator =
|
|
96
|
+
| "+"
|
|
97
|
+
| "-"
|
|
98
|
+
| "*"
|
|
99
|
+
| "/"
|
|
100
|
+
| "%"
|
|
101
|
+
| "**"
|
|
102
|
+
| "=="
|
|
103
|
+
| "!="
|
|
104
|
+
| "==="
|
|
105
|
+
| "!=="
|
|
106
|
+
| "<"
|
|
107
|
+
| ">"
|
|
108
|
+
| "<="
|
|
109
|
+
| ">="
|
|
110
|
+
| "<<"
|
|
111
|
+
| ">>"
|
|
112
|
+
| ">>>"
|
|
113
|
+
| "&"
|
|
114
|
+
| "|"
|
|
115
|
+
| "^"
|
|
116
|
+
| "in"
|
|
117
|
+
| "instanceof";
|
|
118
|
+
|
|
119
|
+
export type IrAssignmentOperator =
|
|
120
|
+
| "="
|
|
121
|
+
| "+="
|
|
122
|
+
| "-="
|
|
123
|
+
| "*="
|
|
124
|
+
| "/="
|
|
125
|
+
| "%="
|
|
126
|
+
| "**="
|
|
127
|
+
| "<<="
|
|
128
|
+
| ">>="
|
|
129
|
+
| ">>>="
|
|
130
|
+
| "&="
|
|
131
|
+
| "|="
|
|
132
|
+
| "^="
|
|
133
|
+
| "&&="
|
|
134
|
+
| "||="
|
|
135
|
+
| "??=";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IR types barrel exports
|
|
3
|
+
* Intermediate Representation (IR) types for Tsonic compiler
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Module types
|
|
7
|
+
export type {
|
|
8
|
+
IrModule,
|
|
9
|
+
IrImport,
|
|
10
|
+
IrImportSpecifier,
|
|
11
|
+
IrExport,
|
|
12
|
+
} from "./module.js";
|
|
13
|
+
|
|
14
|
+
// Statement types
|
|
15
|
+
export type {
|
|
16
|
+
IrStatement,
|
|
17
|
+
IrVariableDeclaration,
|
|
18
|
+
IrVariableDeclarator,
|
|
19
|
+
IrFunctionDeclaration,
|
|
20
|
+
IrClassDeclaration,
|
|
21
|
+
IrClassMember,
|
|
22
|
+
IrMethodDeclaration,
|
|
23
|
+
IrPropertyDeclaration,
|
|
24
|
+
IrConstructorDeclaration,
|
|
25
|
+
IrInterfaceDeclaration,
|
|
26
|
+
IrEnumDeclaration,
|
|
27
|
+
IrEnumMember,
|
|
28
|
+
IrTypeAliasDeclaration,
|
|
29
|
+
IrExpressionStatement,
|
|
30
|
+
IrReturnStatement,
|
|
31
|
+
IrIfStatement,
|
|
32
|
+
IrWhileStatement,
|
|
33
|
+
IrForStatement,
|
|
34
|
+
IrForOfStatement,
|
|
35
|
+
IrSwitchStatement,
|
|
36
|
+
IrSwitchCase,
|
|
37
|
+
IrThrowStatement,
|
|
38
|
+
IrTryStatement,
|
|
39
|
+
IrCatchClause,
|
|
40
|
+
IrBlockStatement,
|
|
41
|
+
IrBreakStatement,
|
|
42
|
+
IrContinueStatement,
|
|
43
|
+
IrEmptyStatement,
|
|
44
|
+
} from "./statements.js";
|
|
45
|
+
|
|
46
|
+
// Expression types
|
|
47
|
+
export type {
|
|
48
|
+
IrExpression,
|
|
49
|
+
IrLiteralExpression,
|
|
50
|
+
IrIdentifierExpression,
|
|
51
|
+
IrArrayExpression,
|
|
52
|
+
IrObjectExpression,
|
|
53
|
+
IrObjectProperty,
|
|
54
|
+
IrFunctionExpression,
|
|
55
|
+
IrArrowFunctionExpression,
|
|
56
|
+
IrMemberExpression,
|
|
57
|
+
IrCallExpression,
|
|
58
|
+
IrNewExpression,
|
|
59
|
+
IrThisExpression,
|
|
60
|
+
IrUpdateExpression,
|
|
61
|
+
IrUnaryExpression,
|
|
62
|
+
IrBinaryExpression,
|
|
63
|
+
IrLogicalExpression,
|
|
64
|
+
IrConditionalExpression,
|
|
65
|
+
IrAssignmentExpression,
|
|
66
|
+
IrTemplateLiteralExpression,
|
|
67
|
+
IrSpreadExpression,
|
|
68
|
+
IrAwaitExpression,
|
|
69
|
+
IrYieldExpression,
|
|
70
|
+
} from "./expressions.js";
|
|
71
|
+
|
|
72
|
+
// Type system types
|
|
73
|
+
export type {
|
|
74
|
+
IrType,
|
|
75
|
+
IrPrimitiveType,
|
|
76
|
+
IrReferenceType,
|
|
77
|
+
IrArrayType,
|
|
78
|
+
IrFunctionType,
|
|
79
|
+
IrObjectType,
|
|
80
|
+
IrDictionaryType,
|
|
81
|
+
IrUnionType,
|
|
82
|
+
IrIntersectionType,
|
|
83
|
+
IrLiteralType,
|
|
84
|
+
IrAnyType,
|
|
85
|
+
IrUnknownType,
|
|
86
|
+
IrVoidType,
|
|
87
|
+
IrNeverType,
|
|
88
|
+
} from "./ir-types.js";
|
|
89
|
+
|
|
90
|
+
// Helper types
|
|
91
|
+
export type {
|
|
92
|
+
IrPattern,
|
|
93
|
+
IrIdentifierPattern,
|
|
94
|
+
IrArrayPattern,
|
|
95
|
+
IrObjectPattern,
|
|
96
|
+
IrObjectPatternProperty,
|
|
97
|
+
IrTypeParameter,
|
|
98
|
+
IrParameter,
|
|
99
|
+
IrInterfaceMember,
|
|
100
|
+
IrPropertySignature,
|
|
101
|
+
IrMethodSignature,
|
|
102
|
+
IrAccessibility,
|
|
103
|
+
IrBinaryOperator,
|
|
104
|
+
IrAssignmentOperator,
|
|
105
|
+
} from "./helpers.js";
|
|
106
|
+
|
|
107
|
+
// Type guards
|
|
108
|
+
export { isStatement, isExpression } from "./guards.js";
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type system types for IR (IrType and its variants)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { IrParameter, IrInterfaceMember } from "./helpers.js";
|
|
6
|
+
|
|
7
|
+
export type IrType =
|
|
8
|
+
| IrPrimitiveType
|
|
9
|
+
| IrReferenceType
|
|
10
|
+
| IrArrayType
|
|
11
|
+
| IrFunctionType
|
|
12
|
+
| IrObjectType
|
|
13
|
+
| IrDictionaryType
|
|
14
|
+
| IrUnionType
|
|
15
|
+
| IrIntersectionType
|
|
16
|
+
| IrLiteralType
|
|
17
|
+
| IrAnyType
|
|
18
|
+
| IrUnknownType
|
|
19
|
+
| IrVoidType
|
|
20
|
+
| IrNeverType;
|
|
21
|
+
|
|
22
|
+
export type IrPrimitiveType = {
|
|
23
|
+
readonly kind: "primitiveType";
|
|
24
|
+
readonly name: "string" | "number" | "boolean" | "null" | "undefined";
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type IrReferenceType = {
|
|
28
|
+
readonly kind: "referenceType";
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly typeArguments?: readonly IrType[];
|
|
31
|
+
/** Fully-qualified CLR type for imported types (e.g., "MyApp.models.User") */
|
|
32
|
+
readonly resolvedClrType?: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type IrArrayType = {
|
|
36
|
+
readonly kind: "arrayType";
|
|
37
|
+
readonly elementType: IrType;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type IrFunctionType = {
|
|
41
|
+
readonly kind: "functionType";
|
|
42
|
+
readonly parameters: readonly IrParameter[];
|
|
43
|
+
readonly returnType: IrType;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type IrObjectType = {
|
|
47
|
+
readonly kind: "objectType";
|
|
48
|
+
readonly members: readonly IrInterfaceMember[];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Dictionary/map type for index signatures and Record<K, V>
|
|
53
|
+
*
|
|
54
|
+
* Examples:
|
|
55
|
+
* - `{ [k: string]: T }` → IrDictionaryType { keyType: string, valueType: T }
|
|
56
|
+
* - `Record<string, T>` → IrDictionaryType { keyType: string, valueType: T }
|
|
57
|
+
*
|
|
58
|
+
* Emits to C# Dictionary<TKey, TValue>.
|
|
59
|
+
* Access should be via indexer `d["key"]` (dot property access will fail in C#).
|
|
60
|
+
*/
|
|
61
|
+
export type IrDictionaryType = {
|
|
62
|
+
readonly kind: "dictionaryType";
|
|
63
|
+
readonly keyType: IrType;
|
|
64
|
+
readonly valueType: IrType;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type IrUnionType = {
|
|
68
|
+
readonly kind: "unionType";
|
|
69
|
+
readonly types: readonly IrType[];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type IrIntersectionType = {
|
|
73
|
+
readonly kind: "intersectionType";
|
|
74
|
+
readonly types: readonly IrType[];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type IrLiteralType = {
|
|
78
|
+
readonly kind: "literalType";
|
|
79
|
+
readonly value: string | number | boolean;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type IrAnyType = {
|
|
83
|
+
readonly kind: "anyType";
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type IrUnknownType = {
|
|
87
|
+
readonly kind: "unknownType";
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type IrVoidType = {
|
|
91
|
+
readonly kind: "voidType";
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type IrNeverType = {
|
|
95
|
+
readonly kind: "neverType";
|
|
96
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core IR module types (Module, Import, Export)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { IrStatement } from "./statements.js";
|
|
6
|
+
import { IrExpression } from "./expressions.js";
|
|
7
|
+
|
|
8
|
+
export type IrModule = {
|
|
9
|
+
readonly kind: "module";
|
|
10
|
+
readonly filePath: string;
|
|
11
|
+
readonly namespace: string;
|
|
12
|
+
readonly className: string; // File name becomes class name
|
|
13
|
+
readonly isStaticContainer: boolean; // True if module only has exports, no top-level code
|
|
14
|
+
readonly imports: readonly IrImport[];
|
|
15
|
+
readonly body: readonly IrStatement[];
|
|
16
|
+
readonly exports: readonly IrExport[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type IrImport = {
|
|
20
|
+
readonly kind: "import";
|
|
21
|
+
readonly source: string; // Import path
|
|
22
|
+
readonly isLocal: boolean;
|
|
23
|
+
readonly isDotNet: boolean;
|
|
24
|
+
readonly specifiers: readonly IrImportSpecifier[];
|
|
25
|
+
readonly resolvedNamespace?: string; // For .NET imports or local imports (e.g., "MultiFileCheck.utils")
|
|
26
|
+
// For module bindings (Node.js APIs mapped to CLR types)
|
|
27
|
+
readonly resolvedClrType?: string; // e.g., "Tsonic.NodeApi.fs"
|
|
28
|
+
readonly resolvedAssembly?: string; // e.g., "Tsonic.NodeApi"
|
|
29
|
+
// For local imports: the target module's container class name
|
|
30
|
+
readonly targetContainerName?: string; // e.g., "Math" for ./utils/Math.ts
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type IrImportSpecifier =
|
|
34
|
+
| { readonly kind: "default"; readonly localName: string }
|
|
35
|
+
| { readonly kind: "namespace"; readonly localName: string }
|
|
36
|
+
| {
|
|
37
|
+
readonly kind: "named";
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly localName: string;
|
|
40
|
+
/** Whether this import is a type (interface/class) - emitted at namespace level in C# */
|
|
41
|
+
readonly isType?: boolean;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type IrExport =
|
|
45
|
+
| {
|
|
46
|
+
readonly kind: "named";
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly localName: string;
|
|
49
|
+
}
|
|
50
|
+
| { readonly kind: "default"; readonly expression: IrExpression }
|
|
51
|
+
| { readonly kind: "declaration"; readonly declaration: IrStatement }
|
|
52
|
+
| {
|
|
53
|
+
readonly kind: "reexport";
|
|
54
|
+
readonly name: string; // Exported name
|
|
55
|
+
readonly originalName: string; // Name in source module (may differ if aliased)
|
|
56
|
+
readonly fromModule: string; // Source module path (e.g., "./math.ts")
|
|
57
|
+
};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Statement types for IR
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { IrType } from "./ir-types.js";
|
|
6
|
+
import {
|
|
7
|
+
IrPattern,
|
|
8
|
+
IrParameter,
|
|
9
|
+
IrTypeParameter,
|
|
10
|
+
IrAccessibility,
|
|
11
|
+
IrInterfaceMember,
|
|
12
|
+
} from "./helpers.js";
|
|
13
|
+
import { IrExpression } from "./expressions.js";
|
|
14
|
+
|
|
15
|
+
export type IrStatement =
|
|
16
|
+
| IrVariableDeclaration
|
|
17
|
+
| IrFunctionDeclaration
|
|
18
|
+
| IrClassDeclaration
|
|
19
|
+
| IrInterfaceDeclaration
|
|
20
|
+
| IrEnumDeclaration
|
|
21
|
+
| IrTypeAliasDeclaration
|
|
22
|
+
| IrExpressionStatement
|
|
23
|
+
| IrReturnStatement
|
|
24
|
+
| IrIfStatement
|
|
25
|
+
| IrWhileStatement
|
|
26
|
+
| IrForStatement
|
|
27
|
+
| IrForOfStatement
|
|
28
|
+
| IrSwitchStatement
|
|
29
|
+
| IrThrowStatement
|
|
30
|
+
| IrTryStatement
|
|
31
|
+
| IrBlockStatement
|
|
32
|
+
| IrBreakStatement
|
|
33
|
+
| IrContinueStatement
|
|
34
|
+
| IrEmptyStatement;
|
|
35
|
+
|
|
36
|
+
export type IrVariableDeclaration = {
|
|
37
|
+
readonly kind: "variableDeclaration";
|
|
38
|
+
readonly declarationKind: "const" | "let" | "var";
|
|
39
|
+
readonly declarations: readonly IrVariableDeclarator[];
|
|
40
|
+
readonly isExported: boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type IrVariableDeclarator = {
|
|
44
|
+
readonly kind: "variableDeclarator";
|
|
45
|
+
readonly name: IrPattern;
|
|
46
|
+
/** Type from annotation or inferred. Always set for module-level exports (C# requires explicit type). */
|
|
47
|
+
readonly type?: IrType;
|
|
48
|
+
readonly initializer?: IrExpression;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type IrFunctionDeclaration = {
|
|
52
|
+
readonly kind: "functionDeclaration";
|
|
53
|
+
readonly name: string;
|
|
54
|
+
readonly typeParameters?: readonly IrTypeParameter[];
|
|
55
|
+
readonly parameters: readonly IrParameter[];
|
|
56
|
+
readonly returnType?: IrType;
|
|
57
|
+
readonly body: IrBlockStatement;
|
|
58
|
+
readonly isAsync: boolean;
|
|
59
|
+
readonly isGenerator: boolean;
|
|
60
|
+
readonly isExported: boolean;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type IrClassDeclaration = {
|
|
64
|
+
readonly kind: "classDeclaration";
|
|
65
|
+
readonly name: string;
|
|
66
|
+
readonly typeParameters?: readonly IrTypeParameter[];
|
|
67
|
+
readonly superClass?: IrExpression;
|
|
68
|
+
readonly implements: readonly IrType[];
|
|
69
|
+
readonly members: readonly IrClassMember[];
|
|
70
|
+
readonly isExported: boolean;
|
|
71
|
+
/** True if this class should be emitted as a C# struct instead of a class */
|
|
72
|
+
readonly isStruct: boolean;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type IrClassMember =
|
|
76
|
+
| IrMethodDeclaration
|
|
77
|
+
| IrPropertyDeclaration
|
|
78
|
+
| IrConstructorDeclaration;
|
|
79
|
+
|
|
80
|
+
export type IrMethodDeclaration = {
|
|
81
|
+
readonly kind: "methodDeclaration";
|
|
82
|
+
readonly name: string;
|
|
83
|
+
readonly typeParameters?: readonly IrTypeParameter[];
|
|
84
|
+
readonly parameters: readonly IrParameter[];
|
|
85
|
+
readonly returnType?: IrType;
|
|
86
|
+
readonly body?: IrBlockStatement;
|
|
87
|
+
readonly isStatic: boolean;
|
|
88
|
+
readonly isAsync: boolean;
|
|
89
|
+
readonly isGenerator: boolean;
|
|
90
|
+
readonly accessibility: IrAccessibility;
|
|
91
|
+
/** True if this method overrides a virtual base class method (from metadata or TS base class) */
|
|
92
|
+
readonly isOverride?: boolean;
|
|
93
|
+
/** True if this method shadows a non-virtual base method (future: emit 'new' keyword) */
|
|
94
|
+
readonly isShadow?: boolean;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export type IrPropertyDeclaration = {
|
|
98
|
+
readonly kind: "propertyDeclaration";
|
|
99
|
+
readonly name: string;
|
|
100
|
+
/** Type from annotation or inferred. Always set for class fields (C# requires explicit type). */
|
|
101
|
+
readonly type?: IrType;
|
|
102
|
+
readonly initializer?: IrExpression;
|
|
103
|
+
readonly isStatic: boolean;
|
|
104
|
+
readonly isReadonly: boolean;
|
|
105
|
+
readonly accessibility: IrAccessibility;
|
|
106
|
+
/** True if this property overrides a virtual base class property (from metadata or TS base class) */
|
|
107
|
+
readonly isOverride?: boolean;
|
|
108
|
+
/** True if this property shadows a non-virtual base property (future: emit 'new' keyword) */
|
|
109
|
+
readonly isShadow?: boolean;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export type IrConstructorDeclaration = {
|
|
113
|
+
readonly kind: "constructorDeclaration";
|
|
114
|
+
readonly parameters: readonly IrParameter[];
|
|
115
|
+
readonly body?: IrBlockStatement;
|
|
116
|
+
readonly accessibility: IrAccessibility;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export type IrInterfaceDeclaration = {
|
|
120
|
+
readonly kind: "interfaceDeclaration";
|
|
121
|
+
readonly name: string;
|
|
122
|
+
readonly typeParameters?: readonly IrTypeParameter[];
|
|
123
|
+
readonly extends: readonly IrType[];
|
|
124
|
+
readonly members: readonly IrInterfaceMember[];
|
|
125
|
+
readonly isExported: boolean;
|
|
126
|
+
/** True if this interface should be emitted as a C# struct instead of a class */
|
|
127
|
+
readonly isStruct: boolean;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export type IrEnumDeclaration = {
|
|
131
|
+
readonly kind: "enumDeclaration";
|
|
132
|
+
readonly name: string;
|
|
133
|
+
readonly members: readonly IrEnumMember[];
|
|
134
|
+
readonly isExported: boolean;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type IrEnumMember = {
|
|
138
|
+
readonly kind: "enumMember";
|
|
139
|
+
readonly name: string;
|
|
140
|
+
readonly initializer?: IrExpression;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export type IrTypeAliasDeclaration = {
|
|
144
|
+
readonly kind: "typeAliasDeclaration";
|
|
145
|
+
readonly name: string;
|
|
146
|
+
readonly typeParameters?: readonly IrTypeParameter[];
|
|
147
|
+
readonly type: IrType;
|
|
148
|
+
readonly isExported: boolean;
|
|
149
|
+
/** True if this type alias should be emitted as a C# struct instead of a class */
|
|
150
|
+
readonly isStruct: boolean;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export type IrExpressionStatement = {
|
|
154
|
+
readonly kind: "expressionStatement";
|
|
155
|
+
readonly expression: IrExpression;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export type IrReturnStatement = {
|
|
159
|
+
readonly kind: "returnStatement";
|
|
160
|
+
readonly expression?: IrExpression;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export type IrIfStatement = {
|
|
164
|
+
readonly kind: "ifStatement";
|
|
165
|
+
readonly condition: IrExpression;
|
|
166
|
+
readonly thenStatement: IrStatement;
|
|
167
|
+
readonly elseStatement?: IrStatement;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export type IrWhileStatement = {
|
|
171
|
+
readonly kind: "whileStatement";
|
|
172
|
+
readonly condition: IrExpression;
|
|
173
|
+
readonly body: IrStatement;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export type IrForStatement = {
|
|
177
|
+
readonly kind: "forStatement";
|
|
178
|
+
readonly initializer?: IrVariableDeclaration | IrExpression;
|
|
179
|
+
readonly condition?: IrExpression;
|
|
180
|
+
readonly update?: IrExpression;
|
|
181
|
+
readonly body: IrStatement;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export type IrForOfStatement = {
|
|
185
|
+
readonly kind: "forOfStatement";
|
|
186
|
+
readonly variable: IrPattern;
|
|
187
|
+
readonly expression: IrExpression;
|
|
188
|
+
readonly body: IrStatement;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export type IrSwitchStatement = {
|
|
192
|
+
readonly kind: "switchStatement";
|
|
193
|
+
readonly expression: IrExpression;
|
|
194
|
+
readonly cases: readonly IrSwitchCase[];
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export type IrSwitchCase = {
|
|
198
|
+
readonly kind: "switchCase";
|
|
199
|
+
readonly test?: IrExpression; // undefined for default case
|
|
200
|
+
readonly statements: readonly IrStatement[];
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export type IrThrowStatement = {
|
|
204
|
+
readonly kind: "throwStatement";
|
|
205
|
+
readonly expression: IrExpression;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export type IrTryStatement = {
|
|
209
|
+
readonly kind: "tryStatement";
|
|
210
|
+
readonly tryBlock: IrBlockStatement;
|
|
211
|
+
readonly catchClause?: IrCatchClause;
|
|
212
|
+
readonly finallyBlock?: IrBlockStatement;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export type IrCatchClause = {
|
|
216
|
+
readonly kind: "catchClause";
|
|
217
|
+
readonly parameter?: IrPattern;
|
|
218
|
+
readonly body: IrBlockStatement;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export type IrBlockStatement = {
|
|
222
|
+
readonly kind: "blockStatement";
|
|
223
|
+
readonly statements: readonly IrStatement[];
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export type IrBreakStatement = {
|
|
227
|
+
readonly kind: "breakStatement";
|
|
228
|
+
readonly label?: string;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export type IrContinueStatement = {
|
|
232
|
+
readonly kind: "continueStatement";
|
|
233
|
+
readonly label?: string;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export type IrEmptyStatement = {
|
|
237
|
+
readonly kind: "emptyStatement";
|
|
238
|
+
};
|