@holoscript/core 1.0.0-alpha.2 → 2.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.
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,392 @@
1
+ /**
2
+ * HoloScriptPlus Parser Tests
3
+ *
4
+ * Tests for trait annotation parsing and validation
5
+ */
6
+
7
+ import { describe, it, expect, beforeEach } from 'vitest';
8
+ import { HoloScriptPlusParser } from '../HoloScriptPlusParser';
9
+
10
+ describe('HoloScriptPlusParser', () => {
11
+ let parser: HoloScriptPlusParser;
12
+
13
+ beforeEach(() => {
14
+ parser = new HoloScriptPlusParser();
15
+ });
16
+
17
+ // ========================================================================
18
+ // Material Trait Tests
19
+ // ========================================================================
20
+
21
+ describe('Material Trait Annotations', () => {
22
+ it('should parse material trait annotation', () => {
23
+ const code = `
24
+ orb#sphere {
25
+ @material { type: pbr }
26
+ }
27
+ `;
28
+
29
+ const traits = parser.extractTraitAnnotations(code);
30
+ expect(traits).toHaveLength(1);
31
+ expect(traits[0].type).toBe('material');
32
+ });
33
+
34
+ it('should parse material with basic properties', () => {
35
+ const code = `@material { type: pbr }`;
36
+ const traits = parser.extractTraitAnnotations(code);
37
+
38
+ expect(traits[0].config.type).toBe('pbr');
39
+ });
40
+
41
+ it('should parse material with textures', () => {
42
+ const code = `@material { textures: [{ path: diffuse.jpg, channel: baseColor }] }`;
43
+ const traits = parser.extractTraitAnnotations(code);
44
+
45
+ expect(traits[0].config.textures).toBeDefined();
46
+ });
47
+
48
+ it('should parse material compression option', () => {
49
+ const code = `@material { compression: basis }`;
50
+ const traits = parser.extractTraitAnnotations(code);
51
+
52
+ expect(traits[0].config.compression).toBe('basis');
53
+ });
54
+
55
+ it('should validate material trait', () => {
56
+ const trait = {
57
+ type: 'material' as const,
58
+ config: { pbr: { metallic: 0.5, roughness: 0.3 } },
59
+ };
60
+
61
+ const validation = parser.validateTraitAnnotation(trait as any);
62
+ expect(validation.valid).toBe(true);
63
+ });
64
+
65
+ it('should reject invalid metallic value', () => {
66
+ const trait = {
67
+ type: 'material' as const,
68
+ config: { pbr: { metallic: 1.5 } },
69
+ };
70
+
71
+ const validation = parser.validateTraitAnnotation(trait as any);
72
+ expect(validation.valid).toBe(false);
73
+ expect(validation.errors.length).toBeGreaterThan(0);
74
+ });
75
+
76
+ it('should reject invalid compression format', () => {
77
+ const trait = {
78
+ type: 'material' as const,
79
+ config: { compression: 'invalid' },
80
+ };
81
+
82
+ const validation = parser.validateTraitAnnotation(trait as any);
83
+ expect(validation.valid).toBe(false);
84
+ });
85
+ });
86
+
87
+ // ========================================================================
88
+ // Lighting Trait Tests
89
+ // ========================================================================
90
+
91
+ describe('Lighting Trait Annotations', () => {
92
+ it('should parse lighting trait annotation', () => {
93
+ const code = `
94
+ @lighting { preset: studio, shadows: true }
95
+ `;
96
+
97
+ const traits = parser.extractTraitAnnotations(code);
98
+ expect(traits).toHaveLength(1);
99
+ expect(traits[0].type).toBe('lighting');
100
+ });
101
+
102
+ it('should parse lighting with preset', () => {
103
+ const code = `@lighting { preset: outdoor }`;
104
+ const traits = parser.extractTraitAnnotations(code);
105
+
106
+ expect(traits[0].config.preset).toBe('outdoor');
107
+ });
108
+
109
+ it('should parse lighting with lights', () => {
110
+ const code = `@lighting { lights: [{ type: directional, intensity: 1.2 }] }`;
111
+ const traits = parser.extractTraitAnnotations(code);
112
+
113
+ expect(traits[0].config.lights).toBeDefined();
114
+ });
115
+
116
+ it('should validate lighting trait', () => {
117
+ const trait = {
118
+ type: 'lighting' as const,
119
+ config: { preset: 'studio' },
120
+ };
121
+
122
+ const validation = parser.validateTraitAnnotation(trait as any);
123
+ expect(validation.valid).toBe(true);
124
+ });
125
+
126
+ it('should reject invalid preset', () => {
127
+ const trait = {
128
+ type: 'lighting' as const,
129
+ config: { preset: 'invalid' },
130
+ };
131
+
132
+ const validation = parser.validateTraitAnnotation(trait as any);
133
+ expect(validation.valid).toBe(false);
134
+ });
135
+
136
+ it('should reject light with negative intensity', () => {
137
+ const trait = {
138
+ type: 'lighting' as const,
139
+ config: { lights: [{ type: 'point', intensity: -0.5 }] },
140
+ };
141
+
142
+ const validation = parser.validateTraitAnnotation(trait as any);
143
+ expect(validation.valid).toBe(false);
144
+ });
145
+ });
146
+
147
+ // ========================================================================
148
+ // Rendering Trait Tests
149
+ // ========================================================================
150
+
151
+ describe('Rendering Trait Annotations', () => {
152
+ it('should parse rendering trait annotation', () => {
153
+ const code = `
154
+ @rendering { quality: high, lod: true, culling: true }
155
+ `;
156
+
157
+ const traits = parser.extractTraitAnnotations(code);
158
+ expect(traits).toHaveLength(1);
159
+ expect(traits[0].type).toBe('rendering');
160
+ });
161
+
162
+ it('should parse rendering with quality preset', () => {
163
+ const code = `@rendering { quality: ultra }`;
164
+ const traits = parser.extractTraitAnnotations(code);
165
+
166
+ expect(traits[0].config.quality).toBe('ultra');
167
+ });
168
+
169
+ it('should parse rendering with platform optimization', () => {
170
+ const code = `@rendering { platform: mobile, quality: low }`;
171
+ const traits = parser.extractTraitAnnotations(code);
172
+
173
+ expect(traits[0].config.platform).toBe('mobile');
174
+ });
175
+
176
+ it('should validate rendering trait', () => {
177
+ const trait = {
178
+ type: 'rendering' as const,
179
+ config: { quality: 'high', platform: 'desktop' },
180
+ };
181
+
182
+ const validation = parser.validateTraitAnnotation(trait as any);
183
+ expect(validation.valid).toBe(true);
184
+ });
185
+
186
+ it('should reject invalid quality preset', () => {
187
+ const trait = {
188
+ type: 'rendering' as const,
189
+ config: { quality: 'invalid' },
190
+ };
191
+
192
+ const validation = parser.validateTraitAnnotation(trait as any);
193
+ expect(validation.valid).toBe(false);
194
+ });
195
+
196
+ it('should reject invalid platform', () => {
197
+ const trait = {
198
+ type: 'rendering' as const,
199
+ config: { platform: 'console' },
200
+ };
201
+
202
+ const validation = parser.validateTraitAnnotation(trait as any);
203
+ expect(validation.valid).toBe(false);
204
+ });
205
+
206
+ it('should reject invalid FPS target', () => {
207
+ const trait = {
208
+ type: 'rendering' as const,
209
+ config: { targetFPS: 500 },
210
+ };
211
+
212
+ const validation = parser.validateTraitAnnotation(trait as any);
213
+ expect(validation.valid).toBe(false);
214
+ });
215
+ });
216
+
217
+ // ========================================================================
218
+ // Combined Trait Tests
219
+ // ========================================================================
220
+
221
+ describe('Combined Trait Annotations', () => {
222
+ it('should parse multiple traits on single orb', () => {
223
+ const code = `
224
+ orb#sphere {
225
+ @material { type: pbr, metallic: 0.5 }
226
+ @lighting { preset: studio }
227
+ @rendering { quality: high }
228
+ }
229
+ `;
230
+
231
+ const traits = parser.extractTraitAnnotations(code);
232
+ expect(traits).toHaveLength(3);
233
+ expect(traits.map((t) => t.type).sort()).toEqual(['lighting', 'material', 'rendering']);
234
+ });
235
+
236
+ it('should build graphics configuration from traits', () => {
237
+ const traits = [
238
+ {
239
+ type: 'material' as const,
240
+ config: { type: 'pbr', pbr: { metallic: 0.5 } },
241
+ },
242
+ {
243
+ type: 'lighting' as const,
244
+ config: { preset: 'studio' },
245
+ },
246
+ {
247
+ type: 'rendering' as const,
248
+ config: { quality: 'high' },
249
+ },
250
+ ];
251
+
252
+ const config = parser.buildGraphicsConfig(traits as any);
253
+
254
+ expect(config.material).toBeDefined();
255
+ expect(config.lighting).toBeDefined();
256
+ expect(config.rendering).toBeDefined();
257
+ });
258
+ });
259
+
260
+ // ========================================================================
261
+ // Object Literal Parsing Tests
262
+ // ========================================================================
263
+
264
+ describe('Object Literal Parsing', () => {
265
+ it.skip('should parse simple key-value pairs', () => {
266
+ const result = parser.parseObjectLiteral('type: pbr');
267
+ expect(result.type).toBe('pbr');
268
+ });
269
+
270
+ it.skip('should parse boolean values', () => {
271
+ const result = parser.parseObjectLiteral('shadows: true');
272
+ expect(result.shadows).toBe(true);
273
+ });
274
+
275
+ it.skip('should parse numeric values', () => {
276
+ const result = parser.parseObjectLiteral('targetFPS: 120');
277
+ expect(result.targetFPS).toBe(120);
278
+ });
279
+
280
+ it.skip('should parse string values', () => {
281
+ const result = parser.parseObjectLiteral('compression: basis');
282
+ expect(result.compression).toBe('basis');
283
+ });
284
+ });
285
+
286
+ // ========================================================================
287
+ // Value Parsing Tests
288
+ // ========================================================================
289
+
290
+ describe('Value Parsing', () => {
291
+ it('should parse boolean true', () => {
292
+ const value = parser.parseValue('true');
293
+ expect(value).toBe(true);
294
+ });
295
+
296
+ it('should parse boolean false', () => {
297
+ const value = parser.parseValue('false');
298
+ expect(value).toBe(false);
299
+ });
300
+
301
+ it('should parse positive integer', () => {
302
+ const value = parser.parseValue('120');
303
+ expect(value).toBe(120);
304
+ });
305
+
306
+ it('should parse decimal number', () => {
307
+ const value = parser.parseValue('0.5');
308
+ expect(value).toBe(0.5);
309
+ });
310
+
311
+ it('should parse negative number', () => {
312
+ const value = parser.parseValue('-5.5');
313
+ expect(value).toBe(-5.5);
314
+ });
315
+
316
+ it('should parse quoted string', () => {
317
+ const value = parser.parseValue('"pbr"');
318
+ expect(value).toBe('pbr');
319
+ });
320
+
321
+ it('should parse single-quoted string', () => {
322
+ const value = parser.parseValue("'studio'");
323
+ expect(value).toBe('studio');
324
+ });
325
+ });;
326
+
327
+ // ========================================================================
328
+ // Enhanced Orb Node Tests
329
+ // ========================================================================
330
+
331
+ describe('Enhanced OrbNode with Graphics Traits', () => {
332
+ it('should extract graphics traits from code', () => {
333
+ const code = `
334
+ orb#sphere {
335
+ @material { type: pbr, metallic: 0.5 }
336
+ @lighting { preset: studio }
337
+ }
338
+ `;
339
+
340
+ const traits = parser.extractTraitAnnotations(code);
341
+ expect(traits).toHaveLength(2);
342
+ expect(traits[0].type).toBe('material');
343
+ expect(traits[1].type).toBe('lighting');
344
+ });
345
+
346
+ it('should create material trait from config', () => {
347
+ const code = `@material { type: pbr, metallic: 0.5, compression: basis }`;
348
+
349
+ const traits = parser.extractTraitAnnotations(code);
350
+ expect(traits).toHaveLength(1);
351
+ expect(traits[0].config.type).toBe('pbr');
352
+ });
353
+ });
354
+
355
+ // ========================================================================
356
+ // Edge Cases and Error Handling
357
+ // ========================================================================
358
+
359
+ describe('Edge Cases and Error Handling', () => {
360
+ it('should handle empty trait annotation gracefully', () => {
361
+ const code = `@material {}`;
362
+ const traits = parser.extractTraitAnnotations(code);
363
+ expect(traits).toHaveLength(1);
364
+ expect(traits[0].config).toBeDefined();
365
+ });
366
+
367
+ it('should handle malformed JSON gracefully', () => {
368
+ const code = `@material { invalid json }`;
369
+ const traits = parser.extractTraitAnnotations(code);
370
+ // Parser should attempt to parse and return best effort result
371
+ expect(traits.length).toBeGreaterThanOrEqual(0);
372
+ });
373
+
374
+ it('should ignore invalid trait types', () => {
375
+ const code = `@invalid { type: something }`;
376
+ const traits = parser.extractTraitAnnotations(code);
377
+ // Should not include invalid trait type
378
+ expect(traits.every((t) => ['material', 'lighting', 'rendering'].includes(t.type))).toBe(true);
379
+ });
380
+
381
+ it('should handle multiple orbs with different traits', () => {
382
+ const code = `
383
+ orb#sphere1 { @material { metallic: 0.5 } }
384
+ orb#sphere2 { @lighting { preset: studio } }
385
+ orb#sphere3 { @rendering { quality: high } }
386
+ `;
387
+
388
+ const traits = parser.extractTraitAnnotations(code);
389
+ expect(traits).toHaveLength(3);
390
+ });
391
+ });
392
+ });