@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,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for module resolver
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it } from "mocha";
|
|
6
|
+
import { expect } from "chai";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import * as os from "node:os";
|
|
10
|
+
import {
|
|
11
|
+
resolveImport,
|
|
12
|
+
getNamespaceFromPath,
|
|
13
|
+
getClassNameFromPath,
|
|
14
|
+
} from "./resolver.js";
|
|
15
|
+
|
|
16
|
+
describe("Module Resolver", () => {
|
|
17
|
+
describe("resolveImport", () => {
|
|
18
|
+
const tempDir = path.join(os.tmpdir(), "tsonic-test");
|
|
19
|
+
const sourceRoot = tempDir;
|
|
20
|
+
|
|
21
|
+
before(() => {
|
|
22
|
+
// Create temp directory structure
|
|
23
|
+
fs.mkdirSync(path.join(tempDir, "src", "models"), { recursive: true });
|
|
24
|
+
fs.writeFileSync(
|
|
25
|
+
path.join(tempDir, "src", "models", "User.ts"),
|
|
26
|
+
"export class User {}"
|
|
27
|
+
);
|
|
28
|
+
fs.writeFileSync(path.join(tempDir, "src", "index.ts"), "");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
after(() => {
|
|
32
|
+
// Clean up
|
|
33
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should resolve local imports with .ts extension", () => {
|
|
37
|
+
const result = resolveImport(
|
|
38
|
+
"./models/User.ts",
|
|
39
|
+
path.join(tempDir, "src", "index.ts"),
|
|
40
|
+
sourceRoot
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
expect(result.ok).to.equal(true);
|
|
44
|
+
if (result.ok) {
|
|
45
|
+
expect(result.value.isLocal).to.equal(true);
|
|
46
|
+
expect(result.value.isDotNet).to.equal(false);
|
|
47
|
+
expect(result.value.resolvedPath).to.equal(
|
|
48
|
+
path.join(tempDir, "src", "models", "User.ts")
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should error on local imports without .ts extension", () => {
|
|
54
|
+
const result = resolveImport(
|
|
55
|
+
"./models/User",
|
|
56
|
+
path.join(tempDir, "src", "index.ts"),
|
|
57
|
+
sourceRoot
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
expect(result.ok).to.equal(false);
|
|
61
|
+
if (!result.ok) {
|
|
62
|
+
expect(result.error.code).to.equal("TSN1001");
|
|
63
|
+
expect(result.error.message).to.include("must have .ts extension");
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should not detect bare imports as .NET without resolver with bindings", () => {
|
|
68
|
+
// Import-driven resolution: bare imports like "System.IO" are only detected as .NET
|
|
69
|
+
// if a resolver is provided and the import resolves to a package with bindings.json.
|
|
70
|
+
// Without a resolver or package, bare imports are treated as unsupported node_modules.
|
|
71
|
+
const result = resolveImport(
|
|
72
|
+
"System.IO",
|
|
73
|
+
path.join(tempDir, "src", "index.ts"),
|
|
74
|
+
sourceRoot
|
|
75
|
+
// No dotnetResolver passed
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
expect(result.ok).to.equal(false);
|
|
79
|
+
if (!result.ok) {
|
|
80
|
+
expect(result.error.code).to.equal("TSN1004");
|
|
81
|
+
expect(result.error.message).to.include("Unsupported module import");
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("should reject node_modules imports", () => {
|
|
86
|
+
const result = resolveImport(
|
|
87
|
+
"express",
|
|
88
|
+
path.join(tempDir, "src", "index.ts"),
|
|
89
|
+
sourceRoot
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
expect(result.ok).to.equal(false);
|
|
93
|
+
if (!result.ok) {
|
|
94
|
+
expect(result.error.code).to.equal("TSN1004");
|
|
95
|
+
expect(result.error.message).to.include("Unsupported module import");
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("should error on non-existent local files", () => {
|
|
100
|
+
const result = resolveImport(
|
|
101
|
+
"./nonexistent.ts",
|
|
102
|
+
path.join(tempDir, "src", "index.ts"),
|
|
103
|
+
sourceRoot
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
expect(result.ok).to.equal(false);
|
|
107
|
+
if (!result.ok) {
|
|
108
|
+
expect(result.error.code).to.equal("TSN1004");
|
|
109
|
+
expect(result.error.message).to.include("Cannot find module");
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe("getNamespaceFromPath", () => {
|
|
115
|
+
it("should generate namespace from directory structure", () => {
|
|
116
|
+
const namespace = getNamespaceFromPath(
|
|
117
|
+
"/project/src/models/auth/User.ts",
|
|
118
|
+
"/project/src",
|
|
119
|
+
"MyApp"
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
expect(namespace).to.equal("MyApp.models.auth");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("should use root namespace for files in source root", () => {
|
|
126
|
+
const namespace = getNamespaceFromPath(
|
|
127
|
+
"/project/src/index.ts",
|
|
128
|
+
"/project/src",
|
|
129
|
+
"MyApp"
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
expect(namespace).to.equal("MyApp");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should preserve case in directory names", () => {
|
|
136
|
+
const namespace = getNamespaceFromPath(
|
|
137
|
+
"/project/src/Models/Auth/User.ts",
|
|
138
|
+
"/project/src",
|
|
139
|
+
"MyApp"
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(namespace).to.equal("MyApp.Models.Auth");
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("getClassNameFromPath", () => {
|
|
147
|
+
it("should extract class name from file name", () => {
|
|
148
|
+
expect(getClassNameFromPath("/src/User.ts")).to.equal("User");
|
|
149
|
+
expect(getClassNameFromPath("/src/models/UserProfile.ts")).to.equal(
|
|
150
|
+
"UserProfile"
|
|
151
|
+
);
|
|
152
|
+
expect(getClassNameFromPath("index.ts")).to.equal("index");
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
package/src/resolver.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module resolution with ESM rules enforcement
|
|
3
|
+
* Main dispatcher - re-exports from resolver/ subdirectory
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type { ResolvedModule, ResolvedDotNetImport } from "./resolver/index.js";
|
|
7
|
+
export {
|
|
8
|
+
resolveImport,
|
|
9
|
+
resolveModulePath,
|
|
10
|
+
getNamespaceFromPath,
|
|
11
|
+
getClassNameFromPath,
|
|
12
|
+
DotNetImportResolver,
|
|
13
|
+
createDotNetImportResolver,
|
|
14
|
+
} from "./resolver/index.js";
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol table builder from TypeScript AST
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as ts from "typescript";
|
|
6
|
+
import { Symbol } from "./types.js";
|
|
7
|
+
import { hasExportModifier } from "./helpers.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Build symbol table from a TypeScript source file
|
|
11
|
+
*/
|
|
12
|
+
export const buildSymbolTable = (
|
|
13
|
+
sourceFile: ts.SourceFile,
|
|
14
|
+
checker: ts.TypeChecker
|
|
15
|
+
): readonly Symbol[] => {
|
|
16
|
+
const symbols: Symbol[] = [];
|
|
17
|
+
const modulePath = sourceFile.fileName;
|
|
18
|
+
|
|
19
|
+
const visitor = (node: ts.Node): void => {
|
|
20
|
+
// Check for exported declarations
|
|
21
|
+
const isExported = hasExportModifier(node);
|
|
22
|
+
|
|
23
|
+
if (ts.isClassDeclaration(node) && node.name) {
|
|
24
|
+
symbols.push({
|
|
25
|
+
name: node.name.text,
|
|
26
|
+
kind: "class",
|
|
27
|
+
isExported,
|
|
28
|
+
module: modulePath,
|
|
29
|
+
tsSymbol: checker.getSymbolAtLocation(node.name),
|
|
30
|
+
});
|
|
31
|
+
} else if (ts.isInterfaceDeclaration(node)) {
|
|
32
|
+
symbols.push({
|
|
33
|
+
name: node.name.text,
|
|
34
|
+
kind: "interface",
|
|
35
|
+
isExported,
|
|
36
|
+
module: modulePath,
|
|
37
|
+
tsSymbol: checker.getSymbolAtLocation(node.name),
|
|
38
|
+
});
|
|
39
|
+
} else if (ts.isFunctionDeclaration(node) && node.name) {
|
|
40
|
+
symbols.push({
|
|
41
|
+
name: node.name.text,
|
|
42
|
+
kind: "function",
|
|
43
|
+
isExported,
|
|
44
|
+
module: modulePath,
|
|
45
|
+
tsSymbol: checker.getSymbolAtLocation(node.name),
|
|
46
|
+
});
|
|
47
|
+
} else if (ts.isVariableStatement(node)) {
|
|
48
|
+
node.declarationList.declarations.forEach((decl) => {
|
|
49
|
+
if (ts.isIdentifier(decl.name)) {
|
|
50
|
+
symbols.push({
|
|
51
|
+
name: decl.name.text,
|
|
52
|
+
kind: "variable",
|
|
53
|
+
isExported,
|
|
54
|
+
module: modulePath,
|
|
55
|
+
tsSymbol: checker.getSymbolAtLocation(decl.name),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
} else if (ts.isTypeAliasDeclaration(node)) {
|
|
60
|
+
symbols.push({
|
|
61
|
+
name: node.name.text,
|
|
62
|
+
kind: "type",
|
|
63
|
+
isExported,
|
|
64
|
+
module: modulePath,
|
|
65
|
+
tsSymbol: checker.getSymbolAtLocation(node.name),
|
|
66
|
+
});
|
|
67
|
+
} else if (ts.isEnumDeclaration(node)) {
|
|
68
|
+
symbols.push({
|
|
69
|
+
name: node.name.text,
|
|
70
|
+
kind: "enum",
|
|
71
|
+
isExported,
|
|
72
|
+
module: modulePath,
|
|
73
|
+
tsSymbol: checker.getSymbolAtLocation(node.name),
|
|
74
|
+
});
|
|
75
|
+
} else if (ts.isModuleDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
76
|
+
symbols.push({
|
|
77
|
+
name: node.name.text,
|
|
78
|
+
kind: "namespace",
|
|
79
|
+
isExported,
|
|
80
|
+
module: modulePath,
|
|
81
|
+
tsSymbol: checker.getSymbolAtLocation(node.name),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Check for export declarations
|
|
86
|
+
if (
|
|
87
|
+
ts.isExportDeclaration(node) &&
|
|
88
|
+
node.exportClause &&
|
|
89
|
+
ts.isNamedExports(node.exportClause)
|
|
90
|
+
) {
|
|
91
|
+
node.exportClause.elements.forEach((spec) => {
|
|
92
|
+
const originalName = spec.propertyName?.text ?? spec.name.text;
|
|
93
|
+
const exportedName = spec.name.text;
|
|
94
|
+
|
|
95
|
+
// Find the original symbol and mark it as exported
|
|
96
|
+
const originalSymbol = symbols.find(
|
|
97
|
+
(s) => s.name === originalName && !s.isExported
|
|
98
|
+
);
|
|
99
|
+
if (originalSymbol) {
|
|
100
|
+
symbols.push({
|
|
101
|
+
...originalSymbol,
|
|
102
|
+
name: exportedName,
|
|
103
|
+
isExported: true,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
ts.forEachChild(node, visitor);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
visitor(sourceFile);
|
|
113
|
+
return symbols;
|
|
114
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol table creation and modification
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Symbol, SymbolTable } from "./types.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create an empty symbol table
|
|
9
|
+
*/
|
|
10
|
+
export const createSymbolTable = (): SymbolTable => ({
|
|
11
|
+
symbols: new Map(),
|
|
12
|
+
moduleSymbols: new Map(),
|
|
13
|
+
exportedSymbols: new Map(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Add a symbol to the table (immutable)
|
|
18
|
+
*/
|
|
19
|
+
export const addSymbol = (table: SymbolTable, symbol: Symbol): SymbolTable => {
|
|
20
|
+
// Add to symbols map (by name)
|
|
21
|
+
const symbolsByName = table.symbols.get(symbol.name) ?? [];
|
|
22
|
+
const newSymbolsByName = new Map(table.symbols);
|
|
23
|
+
newSymbolsByName.set(symbol.name, [...symbolsByName, symbol]);
|
|
24
|
+
|
|
25
|
+
// Add to module symbols map
|
|
26
|
+
const moduleSymbols = table.moduleSymbols.get(symbol.module) ?? [];
|
|
27
|
+
const newModuleSymbols = new Map(table.moduleSymbols);
|
|
28
|
+
newModuleSymbols.set(symbol.module, [...moduleSymbols, symbol]);
|
|
29
|
+
|
|
30
|
+
// Add to exported symbols if exported
|
|
31
|
+
let newExportedSymbols = new Map(table.exportedSymbols);
|
|
32
|
+
if (symbol.isExported) {
|
|
33
|
+
const exportedSymbols = table.exportedSymbols.get(symbol.module) ?? [];
|
|
34
|
+
newExportedSymbols.set(symbol.module, [...exportedSymbols, symbol]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
symbols: newSymbolsByName,
|
|
39
|
+
moduleSymbols: newModuleSymbols,
|
|
40
|
+
exportedSymbols: newExportedSymbols,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol table helper functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as ts from "typescript";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Check if a node has an export modifier
|
|
9
|
+
*/
|
|
10
|
+
export const hasExportModifier = (node: ts.Node): boolean => {
|
|
11
|
+
if (!ts.canHaveModifiers(node)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const modifiers = ts.getModifiers(node);
|
|
15
|
+
return (
|
|
16
|
+
modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) ?? false
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol table - Public API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export type { SymbolKind, Symbol, SymbolTable } from "./types.js";
|
|
6
|
+
export { createSymbolTable, addSymbol } from "./creation.js";
|
|
7
|
+
export { buildSymbolTable } from "./builder.js";
|
|
8
|
+
export {
|
|
9
|
+
findSymbol,
|
|
10
|
+
getExportedSymbols,
|
|
11
|
+
hasExportedSymbol,
|
|
12
|
+
} from "./queries.js";
|
|
13
|
+
export { hasExportModifier } from "./helpers.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol table query functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Symbol, SymbolTable } from "./types.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Find symbols by name, optionally filtered by module
|
|
9
|
+
*/
|
|
10
|
+
export const findSymbol = (
|
|
11
|
+
table: SymbolTable,
|
|
12
|
+
name: string,
|
|
13
|
+
module?: string
|
|
14
|
+
): readonly Symbol[] => {
|
|
15
|
+
if (module) {
|
|
16
|
+
const moduleSymbols = table.moduleSymbols.get(module) ?? [];
|
|
17
|
+
return moduleSymbols.filter((s) => s.name === name);
|
|
18
|
+
}
|
|
19
|
+
return table.symbols.get(name) ?? [];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get all exported symbols from a module
|
|
24
|
+
*/
|
|
25
|
+
export const getExportedSymbols = (
|
|
26
|
+
table: SymbolTable,
|
|
27
|
+
module: string
|
|
28
|
+
): readonly Symbol[] => {
|
|
29
|
+
return table.exportedSymbols.get(module) ?? [];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Check if a module exports a symbol with the given name
|
|
34
|
+
*/
|
|
35
|
+
export const hasExportedSymbol = (
|
|
36
|
+
table: SymbolTable,
|
|
37
|
+
module: string,
|
|
38
|
+
name: string
|
|
39
|
+
): boolean => {
|
|
40
|
+
const exported = getExportedSymbols(table, module);
|
|
41
|
+
return exported.some((s) => s.name === name);
|
|
42
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol table type definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as ts from "typescript";
|
|
6
|
+
|
|
7
|
+
export type SymbolKind =
|
|
8
|
+
| "class"
|
|
9
|
+
| "interface"
|
|
10
|
+
| "function"
|
|
11
|
+
| "variable"
|
|
12
|
+
| "type"
|
|
13
|
+
| "enum"
|
|
14
|
+
| "namespace";
|
|
15
|
+
|
|
16
|
+
export type Symbol = {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly kind: SymbolKind;
|
|
19
|
+
readonly isExported: boolean;
|
|
20
|
+
readonly module: string; // File path
|
|
21
|
+
readonly tsSymbol?: ts.Symbol; // Optional reference to TypeScript symbol
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type SymbolTable = {
|
|
25
|
+
readonly symbols: ReadonlyMap<string, readonly Symbol[]>; // Name to symbols
|
|
26
|
+
readonly moduleSymbols: ReadonlyMap<string, readonly Symbol[]>; // Module path to symbols
|
|
27
|
+
readonly exportedSymbols: ReadonlyMap<string, readonly Symbol[]>; // Module path to exported symbols
|
|
28
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol table for tracking cross-module references
|
|
3
|
+
* Main dispatcher - re-exports from symbol-table/ subdirectory
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type { SymbolKind, Symbol, SymbolTable } from "./symbol-table/index.js";
|
|
7
|
+
export {
|
|
8
|
+
createSymbolTable,
|
|
9
|
+
addSymbol,
|
|
10
|
+
buildSymbolTable,
|
|
11
|
+
findSymbol,
|
|
12
|
+
getExportedSymbols,
|
|
13
|
+
hasExportedSymbol,
|
|
14
|
+
} from "./symbol-table/index.js";
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for .NET bindings.json files generated by tsbindgen.
|
|
3
|
+
*
|
|
4
|
+
* These types represent runtime binding information used for reflection-based dispatch.
|
|
5
|
+
* All property names use camelCase (JavaScript convention).
|
|
6
|
+
*
|
|
7
|
+
* The bindings format uses a dual-version structure:
|
|
8
|
+
* - V1 Definitions: Full method signatures for reference
|
|
9
|
+
* - V2 Exposures: Lightweight binding info for runtime dispatch
|
|
10
|
+
*
|
|
11
|
+
* @see spec/bindings.md for complete schema documentation
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Root bindings file structure.
|
|
16
|
+
* Represents a single namespace with all its type bindings.
|
|
17
|
+
*/
|
|
18
|
+
export type BindingsFile = {
|
|
19
|
+
readonly namespace: string;
|
|
20
|
+
readonly types: TypeBinding[];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Complete binding information for a CLR type.
|
|
25
|
+
* Includes both V1 definitions and V2 exposures.
|
|
26
|
+
*/
|
|
27
|
+
export type TypeBinding = {
|
|
28
|
+
readonly clrName: string;
|
|
29
|
+
readonly tsEmitName: string;
|
|
30
|
+
readonly assemblyName: string;
|
|
31
|
+
readonly metadataToken: number;
|
|
32
|
+
readonly methods?: MethodBinding[]; // V1: Full signatures
|
|
33
|
+
readonly properties?: PropertyBinding[]; // V1: Property info
|
|
34
|
+
readonly fields?: FieldBinding[]; // V1: Field info
|
|
35
|
+
readonly events?: EventBinding[]; // V1: Event info
|
|
36
|
+
readonly exposedMethods?: ExposedMethodBinding[]; // V2: Runtime dispatch
|
|
37
|
+
readonly exposedProperties?: ExposedPropertyBinding[]; // V2: Runtime access
|
|
38
|
+
readonly exposedFields?: ExposedFieldBinding[]; // V2: Runtime access
|
|
39
|
+
readonly exposedEvents?: ExposedEventBinding[]; // V2: Runtime access
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* V1 Definition: Complete method signature.
|
|
44
|
+
* Used for type checking and reference.
|
|
45
|
+
*/
|
|
46
|
+
export type MethodBinding = {
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly clrName: string;
|
|
49
|
+
readonly tsEmitName: string;
|
|
50
|
+
readonly isStatic: boolean;
|
|
51
|
+
readonly arity: number;
|
|
52
|
+
readonly parameters: ParameterBinding[];
|
|
53
|
+
readonly returnType: string;
|
|
54
|
+
readonly metadataToken: number;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* V1 Definition: Property information.
|
|
59
|
+
*/
|
|
60
|
+
export type PropertyBinding = {
|
|
61
|
+
readonly name: string;
|
|
62
|
+
readonly clrName: string;
|
|
63
|
+
readonly tsEmitName: string;
|
|
64
|
+
readonly isStatic: boolean;
|
|
65
|
+
readonly type: string;
|
|
66
|
+
readonly hasGetter: boolean;
|
|
67
|
+
readonly hasSetter: boolean;
|
|
68
|
+
readonly getterToken?: number;
|
|
69
|
+
readonly setterToken?: number;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* V1 Definition: Field information.
|
|
74
|
+
*/
|
|
75
|
+
export type FieldBinding = {
|
|
76
|
+
readonly name: string;
|
|
77
|
+
readonly clrName: string;
|
|
78
|
+
readonly tsEmitName: string;
|
|
79
|
+
readonly isStatic: boolean;
|
|
80
|
+
readonly type: string;
|
|
81
|
+
readonly metadataToken: number;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* V1 Definition: Event information.
|
|
86
|
+
*/
|
|
87
|
+
export type EventBinding = {
|
|
88
|
+
readonly name: string;
|
|
89
|
+
readonly clrName: string;
|
|
90
|
+
readonly tsEmitName: string;
|
|
91
|
+
readonly isStatic: boolean;
|
|
92
|
+
readonly type: string;
|
|
93
|
+
readonly adderToken: number;
|
|
94
|
+
readonly removerToken: number;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Parameter binding information.
|
|
99
|
+
*/
|
|
100
|
+
export type ParameterBinding = {
|
|
101
|
+
readonly name: string;
|
|
102
|
+
readonly type: string;
|
|
103
|
+
readonly isRef: boolean;
|
|
104
|
+
readonly isOut: boolean;
|
|
105
|
+
readonly isIn?: boolean;
|
|
106
|
+
readonly isParams: boolean;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* V2 Exposure: Lightweight method binding for runtime dispatch.
|
|
111
|
+
* Optimized format with minimal data for fast lookups.
|
|
112
|
+
*/
|
|
113
|
+
export type ExposedMethodBinding = {
|
|
114
|
+
readonly tsEmitName: string;
|
|
115
|
+
readonly isStatic: boolean;
|
|
116
|
+
readonly arity: number;
|
|
117
|
+
readonly overloads: MethodOverloadBinding[];
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Method overload binding.
|
|
122
|
+
* One entry per unique parameter count.
|
|
123
|
+
*/
|
|
124
|
+
export type MethodOverloadBinding = {
|
|
125
|
+
readonly parameterCount: number;
|
|
126
|
+
readonly metadataToken: number;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* V2 Exposure: Lightweight property binding for runtime access.
|
|
131
|
+
*/
|
|
132
|
+
export type ExposedPropertyBinding = {
|
|
133
|
+
readonly tsEmitName: string;
|
|
134
|
+
readonly isStatic: boolean;
|
|
135
|
+
readonly getterToken?: number;
|
|
136
|
+
readonly setterToken?: number;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* V2 Exposure: Lightweight field binding for runtime access.
|
|
141
|
+
*/
|
|
142
|
+
export type ExposedFieldBinding = {
|
|
143
|
+
readonly tsEmitName: string;
|
|
144
|
+
readonly isStatic: boolean;
|
|
145
|
+
readonly metadataToken: number;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* V2 Exposure: Lightweight event binding for runtime access.
|
|
150
|
+
*/
|
|
151
|
+
export type ExposedEventBinding = {
|
|
152
|
+
readonly tsEmitName: string;
|
|
153
|
+
readonly isStatic: boolean;
|
|
154
|
+
readonly adderToken: number;
|
|
155
|
+
readonly removerToken: number;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Helper type: Extract V1 definitions from a type binding.
|
|
160
|
+
*/
|
|
161
|
+
export type V1Definitions = Pick<
|
|
162
|
+
TypeBinding,
|
|
163
|
+
"methods" | "properties" | "fields" | "events"
|
|
164
|
+
>;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Helper type: Extract V2 exposures from a type binding.
|
|
168
|
+
*/
|
|
169
|
+
export type V2Exposures = Pick<
|
|
170
|
+
TypeBinding,
|
|
171
|
+
"exposedMethods" | "exposedProperties" | "exposedFields" | "exposedEvents"
|
|
172
|
+
>;
|