@holoscript/core 1.0.0-alpha.2 → 2.0.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.
Files changed (74) hide show
  1. package/package.json +2 -2
  2. package/src/HoloScript2DParser.js +227 -0
  3. package/src/HoloScript2DParser.ts +5 -0
  4. package/src/HoloScriptCodeParser.js +1102 -0
  5. package/src/HoloScriptCodeParser.ts +145 -20
  6. package/src/HoloScriptDebugger.js +458 -0
  7. package/src/HoloScriptParser.js +338 -0
  8. package/src/HoloScriptPlusParser.js +371 -0
  9. package/src/HoloScriptPlusParser.ts +543 -0
  10. package/src/HoloScriptRuntime.js +1399 -0
  11. package/src/HoloScriptRuntime.test.js +351 -0
  12. package/src/HoloScriptRuntime.ts +17 -3
  13. package/src/HoloScriptTypeChecker.js +356 -0
  14. package/src/__tests__/GraphicsServices.test.js +357 -0
  15. package/src/__tests__/GraphicsServices.test.ts +427 -0
  16. package/src/__tests__/HoloScriptPlusParser.test.js +317 -0
  17. package/src/__tests__/HoloScriptPlusParser.test.ts +392 -0
  18. package/src/__tests__/integration.test.js +336 -0
  19. package/src/__tests__/performance.bench.js +218 -0
  20. package/src/__tests__/type-checker.test.js +60 -0
  21. package/src/__tests__/type-checker.test.ts +73 -0
  22. package/src/index.js +217 -0
  23. package/src/index.ts +158 -18
  24. package/src/interop/Interoperability.js +413 -0
  25. package/src/interop/Interoperability.ts +494 -0
  26. package/src/logger.js +42 -0
  27. package/src/parser/EnhancedParser.js +205 -0
  28. package/src/parser/EnhancedParser.ts +251 -0
  29. package/src/parser/HoloScriptPlusParser.js +928 -0
  30. package/src/parser/HoloScriptPlusParser.ts +1089 -0
  31. package/src/runtime/HoloScriptPlusRuntime.js +674 -0
  32. package/src/runtime/HoloScriptPlusRuntime.ts +861 -0
  33. package/src/runtime/PerformanceTelemetry.js +323 -0
  34. package/src/runtime/PerformanceTelemetry.ts +467 -0
  35. package/src/runtime/RuntimeOptimization.js +361 -0
  36. package/src/runtime/RuntimeOptimization.ts +416 -0
  37. package/src/services/HololandGraphicsPipelineService.js +506 -0
  38. package/src/services/HololandGraphicsPipelineService.ts +662 -0
  39. package/src/services/PlatformPerformanceOptimizer.js +356 -0
  40. package/src/services/PlatformPerformanceOptimizer.ts +503 -0
  41. package/src/state/ReactiveState.js +427 -0
  42. package/src/state/ReactiveState.ts +572 -0
  43. package/src/tools/DeveloperExperience.js +376 -0
  44. package/src/tools/DeveloperExperience.ts +438 -0
  45. package/src/traits/AIDriverTrait.js +322 -0
  46. package/src/traits/AIDriverTrait.test.js +329 -0
  47. package/src/traits/AIDriverTrait.test.ts +357 -0
  48. package/src/traits/AIDriverTrait.ts +474 -0
  49. package/src/traits/LightingTrait.js +313 -0
  50. package/src/traits/LightingTrait.test.js +410 -0
  51. package/src/traits/LightingTrait.test.ts +462 -0
  52. package/src/traits/LightingTrait.ts +505 -0
  53. package/src/traits/MaterialTrait.js +194 -0
  54. package/src/traits/MaterialTrait.test.js +286 -0
  55. package/src/traits/MaterialTrait.test.ts +329 -0
  56. package/src/traits/MaterialTrait.ts +324 -0
  57. package/src/traits/RenderingTrait.js +356 -0
  58. package/src/traits/RenderingTrait.test.js +363 -0
  59. package/src/traits/RenderingTrait.test.ts +427 -0
  60. package/src/traits/RenderingTrait.ts +555 -0
  61. package/src/traits/VRTraitSystem.js +740 -0
  62. package/src/traits/VRTraitSystem.ts +1040 -0
  63. package/src/traits/VoiceInputTrait.js +284 -0
  64. package/src/traits/VoiceInputTrait.test.js +226 -0
  65. package/src/traits/VoiceInputTrait.test.ts +252 -0
  66. package/src/traits/VoiceInputTrait.ts +401 -0
  67. package/src/types/AdvancedTypeSystem.js +226 -0
  68. package/src/types/AdvancedTypeSystem.ts +494 -0
  69. package/src/types/HoloScriptPlus.d.ts +853 -0
  70. package/src/types.js +6 -0
  71. package/src/types.ts +96 -1
  72. package/tsconfig.json +1 -1
  73. package/tsup.config.d.ts +2 -0
  74. package/tsup.config.js +18 -0
@@ -0,0 +1,336 @@
1
+ /**
2
+ * HoloScript Integration Tests
3
+ *
4
+ * End-to-end tests that verify the complete pipeline:
5
+ * Parser -> Runtime -> Type Checker -> Debugger
6
+ */
7
+ import { describe, it, expect, beforeEach } from 'vitest';
8
+ import { HoloScriptCodeParser } from '../HoloScriptCodeParser';
9
+ import { HoloScriptRuntime } from '../HoloScriptRuntime';
10
+ import { HoloScriptTypeChecker } from '../HoloScriptTypeChecker';
11
+ import { HoloScriptDebugger } from '../HoloScriptDebugger';
12
+ describe('HoloScript Integration Tests', () => {
13
+ let parser;
14
+ let runtime;
15
+ let typeChecker;
16
+ beforeEach(() => {
17
+ parser = new HoloScriptCodeParser();
18
+ runtime = new HoloScriptRuntime();
19
+ typeChecker = new HoloScriptTypeChecker();
20
+ });
21
+ describe('Parser -> Runtime Pipeline', () => {
22
+ it('should parse and execute a simple orb declaration', async () => {
23
+ const code = `
24
+ orb myOrb {
25
+ name: "TestOrb"
26
+ color: "#ff0000"
27
+ glow: true
28
+ }
29
+ `;
30
+ const parseResult = parser.parse(code);
31
+ expect(parseResult.success).toBe(true);
32
+ expect(parseResult.ast.length).toBeGreaterThan(0);
33
+ const results = await runtime.executeProgram(parseResult.ast);
34
+ expect(results.length).toBeGreaterThan(0);
35
+ expect(results[0].success).toBe(true);
36
+ });
37
+ it('should parse and execute a function definition', async () => {
38
+ const code = `
39
+ function greet(name: string): string {
40
+ return "Hello, " + name
41
+ }
42
+ `;
43
+ const parseResult = parser.parse(code);
44
+ expect(parseResult.success).toBe(true);
45
+ const results = await runtime.executeProgram(parseResult.ast);
46
+ expect(results[0].success).toBe(true);
47
+ // Call the function
48
+ const callResult = await runtime.callFunction('greet', ['World']);
49
+ expect(callResult.success).toBe(true);
50
+ });
51
+ it('should parse and execute connections between orbs', async () => {
52
+ const code = `
53
+ orb source {
54
+ name: "Source"
55
+ }
56
+ orb target {
57
+ name: "Target"
58
+ }
59
+ connect source to target as "data"
60
+ `;
61
+ const parseResult = parser.parse(code);
62
+ expect(parseResult.success).toBe(true);
63
+ expect(parseResult.ast.length).toBe(3);
64
+ const results = await runtime.executeProgram(parseResult.ast);
65
+ expect(results.every(r => r.success)).toBe(true);
66
+ });
67
+ it('should handle program with multiple orbs', async () => {
68
+ const code = `
69
+ orb dataOrb {
70
+ value: 42
71
+ name: "DataOrb"
72
+ }
73
+
74
+ orb outputOrb {
75
+ name: "OutputOrb"
76
+ }
77
+ `;
78
+ const parseResult = parser.parse(code);
79
+ expect(parseResult.success).toBe(true);
80
+ expect(parseResult.ast.length).toBeGreaterThanOrEqual(2);
81
+ const results = await runtime.executeProgram(parseResult.ast);
82
+ expect(results.length).toBeGreaterThanOrEqual(2);
83
+ });
84
+ });
85
+ describe('Parser -> Type Checker Pipeline', () => {
86
+ it('should type check orb declarations', () => {
87
+ const code = `
88
+ orb typedOrb {
89
+ count: 10
90
+ name: "TypedOrb"
91
+ active: true
92
+ }
93
+ `;
94
+ const parseResult = parser.parse(code);
95
+ expect(parseResult.success).toBe(true);
96
+ const typeResult = typeChecker.check(parseResult.ast);
97
+ expect(typeResult.valid).toBe(true);
98
+ expect(typeResult.diagnostics.length).toBe(0);
99
+ });
100
+ it('should type check function signatures', () => {
101
+ const code = `
102
+ function add(a: number, b: number): number {
103
+ return a + b
104
+ }
105
+ `;
106
+ const parseResult = parser.parse(code);
107
+ expect(parseResult.success).toBe(true);
108
+ const typeResult = typeChecker.check(parseResult.ast);
109
+ expect(typeResult.valid).toBe(true);
110
+ });
111
+ it('should detect type information', () => {
112
+ const code = `
113
+ const MAX_VALUE = 100
114
+ let counter = 0
115
+
116
+ orb configOrb {
117
+ limit: MAX_VALUE
118
+ }
119
+ `;
120
+ const parseResult = parser.parse(code);
121
+ expect(parseResult.success).toBe(true);
122
+ const typeResult = typeChecker.check(parseResult.ast);
123
+ expect(typeResult.typeMap.size).toBeGreaterThan(0);
124
+ });
125
+ });
126
+ describe('Full Pipeline: Parse -> Type Check -> Execute', () => {
127
+ it('should process a complete program through all stages', async () => {
128
+ const code = `
129
+ orb sensorOrb {
130
+ reading: 75
131
+ name: "Sensor"
132
+ }
133
+
134
+ function checkReading(value: number): boolean {
135
+ return value > 50
136
+ }
137
+ `;
138
+ // Stage 1: Parse
139
+ const parseResult = parser.parse(code);
140
+ expect(parseResult.success).toBe(true);
141
+ expect(parseResult.errors.length).toBe(0);
142
+ // Stage 2: Type Check
143
+ const typeResult = typeChecker.check(parseResult.ast);
144
+ expect(typeResult.valid).toBe(true);
145
+ // Stage 3: Execute
146
+ const execResults = await runtime.executeProgram(parseResult.ast);
147
+ expect(execResults.every(r => r.success)).toBe(true);
148
+ });
149
+ });
150
+ describe('Debugger Integration', () => {
151
+ it('should load source and set breakpoints', () => {
152
+ const debugger_ = new HoloScriptDebugger(runtime);
153
+ const code = `
154
+ orb debugOrb {
155
+ name: "DebugOrb"
156
+ }
157
+
158
+ function test() {
159
+ show debugOrb
160
+ }
161
+ `;
162
+ const loadResult = debugger_.loadSource(code);
163
+ expect(loadResult.success).toBe(true);
164
+ const bp = debugger_.setBreakpoint(2);
165
+ expect(bp.id).toBeDefined();
166
+ expect(bp.line).toBe(2);
167
+ expect(bp.enabled).toBe(true);
168
+ const breakpoints = debugger_.getBreakpoints();
169
+ expect(breakpoints.length).toBe(1);
170
+ });
171
+ it('should step through execution', async () => {
172
+ const debugger_ = new HoloScriptDebugger(runtime);
173
+ const code = `
174
+ orb stepOrb {
175
+ name: "StepOrb"
176
+ }
177
+ `;
178
+ debugger_.loadSource(code);
179
+ // Start and immediately pause
180
+ await debugger_.start();
181
+ const state = debugger_.getState();
182
+ expect(state.status).toBeDefined();
183
+ });
184
+ it('should evaluate expressions in debug context', async () => {
185
+ const debugger_ = new HoloScriptDebugger(runtime);
186
+ const code = `
187
+ orb evalOrb {
188
+ value: 42
189
+ }
190
+ `;
191
+ debugger_.loadSource(code);
192
+ await debugger_.start();
193
+ // Wait for execution to complete
194
+ const result = await debugger_.evaluate('evalOrb');
195
+ expect(result).toBeDefined();
196
+ });
197
+ it('should handle breakpoint events', async () => {
198
+ const debugger_ = new HoloScriptDebugger(runtime);
199
+ const events = [];
200
+ debugger_.on('breakpoint-hit', () => events.push('breakpoint'));
201
+ debugger_.on('state-change', () => events.push('state'));
202
+ const code = `
203
+ orb eventOrb {
204
+ name: "EventOrb"
205
+ }
206
+ `;
207
+ debugger_.loadSource(code);
208
+ debugger_.setBreakpoint(2);
209
+ await debugger_.start();
210
+ // Events should have been captured
211
+ expect(events.length).toBeGreaterThanOrEqual(0);
212
+ });
213
+ });
214
+ describe('Error Handling', () => {
215
+ it('should handle parse errors gracefully', () => {
216
+ const code = `
217
+ orb { invalid syntax here
218
+ `;
219
+ const parseResult = parser.parse(code);
220
+ expect(parseResult.success).toBe(false);
221
+ expect(parseResult.errors.length).toBeGreaterThan(0);
222
+ });
223
+ it('should handle runtime errors gracefully', async () => {
224
+ const code = `
225
+ function errorFunc() {
226
+ throw "Error"
227
+ }
228
+ `;
229
+ const parseResult = parser.parse(code);
230
+ expect(parseResult.success).toBe(true);
231
+ const results = await runtime.executeProgram(parseResult.ast);
232
+ // Function definition should succeed
233
+ expect(results[0].success).toBe(true);
234
+ });
235
+ it('should handle debugger errors gracefully', async () => {
236
+ const debugger_ = new HoloScriptDebugger(runtime);
237
+ // Completely invalid syntax that parser will reject
238
+ const loadResult = debugger_.loadSource('{{{{{{');
239
+ // Parser may or may not reject this depending on implementation
240
+ // Just verify we get a result without crashing
241
+ expect(loadResult).toBeDefined();
242
+ });
243
+ });
244
+ describe('Loop Constructs', () => {
245
+ it('should parse for loops', () => {
246
+ const code = `
247
+ for (i = 0; i < 10; i++) {
248
+ show i
249
+ }
250
+ `;
251
+ const parseResult = parser.parse(code);
252
+ expect(parseResult.success).toBe(true);
253
+ expect(parseResult.ast[0].type).toBe('for-loop');
254
+ });
255
+ it.todo('should parse while loops - needs parser enhancement');
256
+ it.todo('should parse forEach loops - needs parser enhancement');
257
+ });
258
+ describe('Module System', () => {
259
+ it.todo('should parse import statements - needs parser enhancement');
260
+ it('should parse export statements', () => {
261
+ const code = `
262
+ export function helper() {
263
+ return 42
264
+ }
265
+ `;
266
+ const parseResult = parser.parse(code);
267
+ expect(parseResult.success).toBe(true);
268
+ expect(parseResult.ast[0].type).toBe('export');
269
+ });
270
+ it('should parse variable declarations', () => {
271
+ const code = `
272
+ const MAX = 100
273
+ let count = 0
274
+ var legacy = true
275
+ `;
276
+ const parseResult = parser.parse(code);
277
+ expect(parseResult.success).toBe(true);
278
+ expect(parseResult.ast.length).toBe(3);
279
+ expect(parseResult.ast[0].type).toBe('variable-declaration');
280
+ });
281
+ });
282
+ describe('Runtime Context', () => {
283
+ it('should maintain variable state across executions', async () => {
284
+ const code1 = `
285
+ orb stateOrb {
286
+ counter: 0
287
+ }
288
+ `;
289
+ const parseResult1 = parser.parse(code1);
290
+ await runtime.executeProgram(parseResult1.ast);
291
+ // Context should exist after execution
292
+ const context = runtime.getContext();
293
+ expect(context).toBeDefined();
294
+ expect(context.variables).toBeDefined();
295
+ });
296
+ it('should support function calls with arguments', async () => {
297
+ const code = `
298
+ function multiply(a: number, b: number): number {
299
+ return a * b
300
+ }
301
+ `;
302
+ const parseResult = parser.parse(code);
303
+ await runtime.executeProgram(parseResult.ast);
304
+ const result = await runtime.callFunction('multiply', [5, 3]);
305
+ expect(result.success).toBe(true);
306
+ });
307
+ it('should reset context on runtime reset', async () => {
308
+ const code = `
309
+ orb tempOrb {
310
+ name: "Temporary"
311
+ }
312
+ `;
313
+ const parseResult = parser.parse(code);
314
+ await runtime.executeProgram(parseResult.ast);
315
+ const contextBefore = runtime.getContext();
316
+ expect(contextBefore).toBeDefined();
317
+ runtime.reset();
318
+ const contextAfter = runtime.getContext();
319
+ // After reset, variables should be empty
320
+ expect(contextAfter.variables.size).toBe(0);
321
+ });
322
+ });
323
+ });
324
+ describe('HoloScript Bridge Integration', () => {
325
+ // These tests would require the Hololand bridge
326
+ // Stubbed for now - would need mock world interface
327
+ it.skip('should sync orbs to world objects', async () => {
328
+ // Would test HoloScriptBridge.loadScript -> world.createObject
329
+ });
330
+ it.skip('should handle world events', async () => {
331
+ // Would test world.emit -> bridge event handling
332
+ });
333
+ it.skip('should sync runtime state to world', async () => {
334
+ // Would test bridge.sync() updating world objects
335
+ });
336
+ });
@@ -0,0 +1,218 @@
1
+ /**
2
+ * HoloScript Performance Benchmarks
3
+ *
4
+ * Measures parsing, execution, and type checking performance.
5
+ * Run with: npx vitest bench
6
+ */
7
+ import { describe, bench, beforeAll } from 'vitest';
8
+ import { HoloScriptCodeParser } from '../HoloScriptCodeParser';
9
+ import { HoloScriptRuntime } from '../HoloScriptRuntime';
10
+ import { HoloScriptTypeChecker } from '../HoloScriptTypeChecker';
11
+ // Test data
12
+ const SIMPLE_ORB = `
13
+ orb testOrb {
14
+ name: "TestOrb"
15
+ color: "#ff0000"
16
+ glow: true
17
+ }
18
+ `;
19
+ const MULTIPLE_ORBS = Array.from({ length: 10 }, (_, i) => `
20
+ orb orb${i} {
21
+ name: "Orb${i}"
22
+ color: "#${i.toString(16).padStart(6, '0')}"
23
+ value: ${i * 10}
24
+ }
25
+ `).join('\n');
26
+ const COMPLEX_PROGRAM = `
27
+ orb dataSource {
28
+ name: "DataSource"
29
+ rate: 100
30
+ }
31
+
32
+ orb processor {
33
+ name: "Processor"
34
+ capacity: 1000
35
+ }
36
+
37
+ orb output {
38
+ name: "Output"
39
+ format: "json"
40
+ }
41
+
42
+ function processData(input: number): number {
43
+ return input * 2
44
+ }
45
+
46
+ function validateInput(data: object): boolean {
47
+ return true
48
+ }
49
+
50
+ connect dataSource to processor as "raw"
51
+ connect processor to output as "processed"
52
+ `;
53
+ const FUNCTIONS_PROGRAM = Array.from({ length: 20 }, (_, i) => `
54
+ function func${i}(x: number): number {
55
+ return x + ${i}
56
+ }
57
+ `).join('\n');
58
+ describe('Parser Performance', () => {
59
+ let parser;
60
+ beforeAll(() => {
61
+ parser = new HoloScriptCodeParser();
62
+ });
63
+ bench('parse simple orb', () => {
64
+ parser.parse(SIMPLE_ORB);
65
+ });
66
+ bench('parse 10 orbs', () => {
67
+ parser.parse(MULTIPLE_ORBS);
68
+ });
69
+ bench('parse complex program', () => {
70
+ parser.parse(COMPLEX_PROGRAM);
71
+ });
72
+ bench('parse 20 functions', () => {
73
+ parser.parse(FUNCTIONS_PROGRAM);
74
+ });
75
+ bench('tokenize simple orb', () => {
76
+ // @ts-expect-error - accessing private method for benchmark
77
+ parser.tokenize(SIMPLE_ORB);
78
+ });
79
+ bench('tokenize complex program', () => {
80
+ // @ts-expect-error - accessing private method for benchmark
81
+ parser.tokenize(COMPLEX_PROGRAM);
82
+ });
83
+ });
84
+ describe('Runtime Performance', () => {
85
+ let parser;
86
+ let runtime;
87
+ let simpleAST;
88
+ let complexAST;
89
+ beforeAll(() => {
90
+ parser = new HoloScriptCodeParser();
91
+ runtime = new HoloScriptRuntime();
92
+ const simpleResult = parser.parse(SIMPLE_ORB);
93
+ simpleAST = simpleResult.ast;
94
+ const complexResult = parser.parse(COMPLEX_PROGRAM);
95
+ complexAST = complexResult.ast;
96
+ });
97
+ bench('execute simple orb', async () => {
98
+ runtime.reset();
99
+ await runtime.executeProgram(simpleAST);
100
+ });
101
+ bench('execute complex program', async () => {
102
+ runtime.reset();
103
+ await runtime.executeProgram(complexAST);
104
+ });
105
+ bench('execute single node', async () => {
106
+ if (simpleAST.length > 0) {
107
+ await runtime.executeNode(simpleAST[0]);
108
+ }
109
+ });
110
+ bench('runtime reset', () => {
111
+ runtime.reset();
112
+ });
113
+ bench('get context', () => {
114
+ runtime.getContext();
115
+ });
116
+ bench('set/get variable', () => {
117
+ runtime.setVariable('benchVar', 42);
118
+ runtime.getVariable('benchVar');
119
+ });
120
+ });
121
+ describe('Type Checker Performance', () => {
122
+ let parser;
123
+ let typeChecker;
124
+ let simpleAST;
125
+ let complexAST;
126
+ let functionsAST;
127
+ beforeAll(() => {
128
+ parser = new HoloScriptCodeParser();
129
+ typeChecker = new HoloScriptTypeChecker();
130
+ const simpleResult = parser.parse(SIMPLE_ORB);
131
+ simpleAST = simpleResult.ast;
132
+ const complexResult = parser.parse(COMPLEX_PROGRAM);
133
+ complexAST = complexResult.ast;
134
+ const functionsResult = parser.parse(FUNCTIONS_PROGRAM);
135
+ functionsAST = functionsResult.ast;
136
+ });
137
+ bench('type check simple orb', () => {
138
+ typeChecker.check(simpleAST);
139
+ });
140
+ bench('type check complex program', () => {
141
+ typeChecker.check(complexAST);
142
+ });
143
+ bench('type check 20 functions', () => {
144
+ typeChecker.check(functionsAST);
145
+ });
146
+ bench('get all types', () => {
147
+ typeChecker.check(complexAST);
148
+ typeChecker.getAllTypes();
149
+ });
150
+ });
151
+ describe('Full Pipeline Performance', () => {
152
+ let parser;
153
+ let runtime;
154
+ let typeChecker;
155
+ beforeAll(() => {
156
+ parser = new HoloScriptCodeParser();
157
+ runtime = new HoloScriptRuntime();
158
+ typeChecker = new HoloScriptTypeChecker();
159
+ });
160
+ bench('full pipeline: parse -> type check -> execute (simple)', async () => {
161
+ const parseResult = parser.parse(SIMPLE_ORB);
162
+ typeChecker.check(parseResult.ast);
163
+ runtime.reset();
164
+ await runtime.executeProgram(parseResult.ast);
165
+ });
166
+ bench('full pipeline: parse -> type check -> execute (complex)', async () => {
167
+ const parseResult = parser.parse(COMPLEX_PROGRAM);
168
+ typeChecker.check(parseResult.ast);
169
+ runtime.reset();
170
+ await runtime.executeProgram(parseResult.ast);
171
+ });
172
+ bench('parse only (no execution)', () => {
173
+ parser.parse(COMPLEX_PROGRAM);
174
+ });
175
+ });
176
+ describe('Memory and Scalability', () => {
177
+ let parser;
178
+ let runtime;
179
+ beforeAll(() => {
180
+ parser = new HoloScriptCodeParser();
181
+ runtime = new HoloScriptRuntime();
182
+ });
183
+ bench('parse 100 orbs', () => {
184
+ const largeProgram = Array.from({ length: 100 }, (_, i) => `
185
+ orb orb${i} {
186
+ name: "Orb${i}"
187
+ value: ${i}
188
+ }
189
+ `).join('\n');
190
+ parser.parse(largeProgram);
191
+ });
192
+ bench('execute 50 orbs', async () => {
193
+ const program = Array.from({ length: 50 }, (_, i) => `
194
+ orb orb${i} {
195
+ name: "Orb${i}"
196
+ }
197
+ `).join('\n');
198
+ const result = parser.parse(program);
199
+ runtime.reset();
200
+ await runtime.executeProgram(result.ast);
201
+ });
202
+ bench('many connections', () => {
203
+ const program = `
204
+ orb source { name: "Source" }
205
+ orb a { name: "A" }
206
+ orb b { name: "B" }
207
+ orb c { name: "C" }
208
+ orb d { name: "D" }
209
+ orb target { name: "Target" }
210
+ connect source to a as "data"
211
+ connect a to b as "data"
212
+ connect b to c as "data"
213
+ connect c to d as "data"
214
+ connect d to target as "data"
215
+ `;
216
+ parser.parse(program);
217
+ });
218
+ });
@@ -0,0 +1,60 @@
1
+ /**
2
+ * HoloScriptTypeChecker Tests - Simplified
3
+ *
4
+ * Tests for type checking system
5
+ */
6
+ import { describe, it, expect, beforeEach } from 'vitest';
7
+ import { HoloScriptTypeChecker } from '../HoloScriptTypeChecker';
8
+ describe('HoloScriptTypeChecker', () => {
9
+ let typeChecker;
10
+ beforeEach(() => {
11
+ typeChecker = new HoloScriptTypeChecker();
12
+ });
13
+ describe('Type Inference', () => {
14
+ it('should initialize type checker', () => {
15
+ expect(typeChecker).toBeDefined();
16
+ });
17
+ it('should infer number type', () => {
18
+ const result = typeChecker.inferType(42);
19
+ expect(result.type).toBe('number');
20
+ });
21
+ it('should infer string type', () => {
22
+ const result = typeChecker.inferType('hello');
23
+ expect(result.type).toBe('string');
24
+ });
25
+ it('should infer boolean type', () => {
26
+ const result = typeChecker.inferType(true);
27
+ expect(result.type).toBe('boolean');
28
+ });
29
+ it('should infer array type', () => {
30
+ const result = typeChecker.inferType([1, 2, 3]);
31
+ expect(result.type).toBe('array');
32
+ expect(result.elementType).toBe('number');
33
+ });
34
+ it('should infer object type', () => {
35
+ const result = typeChecker.inferType({ x: 1 });
36
+ expect(result.type).toBe('object');
37
+ expect(result.properties?.size).toBeGreaterThan(0);
38
+ });
39
+ it('should infer null/undefined as any with nullable', () => {
40
+ const result = typeChecker.inferType(null);
41
+ expect(result.type).toBe('any');
42
+ expect(result.nullable).toBe(true);
43
+ });
44
+ });
45
+ describe('Type Checking', () => {
46
+ it('should check AST nodes', () => {
47
+ const ast = [];
48
+ const result = typeChecker.check(ast);
49
+ expect(result.valid).toBeDefined();
50
+ expect(result.diagnostics).toBeDefined();
51
+ expect(result.typeMap).toBeDefined();
52
+ });
53
+ it('should return valid result for empty AST', () => {
54
+ const ast = [];
55
+ const result = typeChecker.check(ast);
56
+ expect(result.valid).toBe(true);
57
+ expect(result.diagnostics.length).toBe(0);
58
+ });
59
+ });
60
+ });
@@ -0,0 +1,73 @@
1
+ /**
2
+ * HoloScriptTypeChecker Tests - Simplified
3
+ *
4
+ * Tests for type checking system
5
+ */
6
+
7
+ import { describe, it, expect, beforeEach } from 'vitest';
8
+ import { HoloScriptTypeChecker } from '../HoloScriptTypeChecker';
9
+
10
+ describe('HoloScriptTypeChecker', () => {
11
+ let typeChecker: HoloScriptTypeChecker;
12
+
13
+ beforeEach(() => {
14
+ typeChecker = new HoloScriptTypeChecker();
15
+ });
16
+
17
+ describe('Type Inference', () => {
18
+ it('should initialize type checker', () => {
19
+ expect(typeChecker).toBeDefined();
20
+ });
21
+
22
+ it('should infer number type', () => {
23
+ const result = typeChecker.inferType(42);
24
+ expect(result.type).toBe('number');
25
+ });
26
+
27
+ it('should infer string type', () => {
28
+ const result = typeChecker.inferType('hello');
29
+ expect(result.type).toBe('string');
30
+ });
31
+
32
+ it('should infer boolean type', () => {
33
+ const result = typeChecker.inferType(true);
34
+ expect(result.type).toBe('boolean');
35
+ });
36
+
37
+ it('should infer array type', () => {
38
+ const result = typeChecker.inferType([1, 2, 3]);
39
+ expect(result.type).toBe('array');
40
+ expect(result.elementType).toBe('number');
41
+ });
42
+
43
+ it('should infer object type', () => {
44
+ const result = typeChecker.inferType({ x: 1 });
45
+ expect(result.type).toBe('object');
46
+ expect(result.properties?.size).toBeGreaterThan(0);
47
+ });
48
+
49
+ it('should infer null/undefined as any with nullable', () => {
50
+ const result = typeChecker.inferType(null);
51
+ expect(result.type).toBe('any');
52
+ expect(result.nullable).toBe(true);
53
+ });
54
+ });
55
+
56
+ describe('Type Checking', () => {
57
+ it('should check AST nodes', () => {
58
+ const ast: any[] = [];
59
+ const result = typeChecker.check(ast);
60
+ expect(result.valid).toBeDefined();
61
+ expect(result.diagnostics).toBeDefined();
62
+ expect(result.typeMap).toBeDefined();
63
+ });
64
+
65
+ it('should return valid result for empty AST', () => {
66
+ const ast: any[] = [];
67
+ const result = typeChecker.check(ast);
68
+ expect(result.valid).toBe(true);
69
+ expect(result.diagnostics.length).toBe(0);
70
+ });
71
+ });
72
+ });
73
+