tova 0.2.9 → 0.3.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/bin/tova.js +1404 -114
- package/package.json +3 -1
- package/src/analyzer/analyzer.js +882 -695
- package/src/analyzer/client-analyzer.js +191 -0
- package/src/analyzer/server-analyzer.js +467 -0
- package/src/analyzer/types.js +20 -4
- package/src/codegen/base-codegen.js +473 -111
- package/src/codegen/client-codegen.js +109 -46
- package/src/codegen/codegen.js +65 -5
- package/src/codegen/server-codegen.js +297 -38
- package/src/diagnostics/error-codes.js +255 -0
- package/src/diagnostics/formatter.js +150 -28
- package/src/docs/generator.js +390 -0
- package/src/lexer/lexer.js +306 -64
- package/src/lexer/tokens.js +19 -0
- package/src/lsp/server.js +935 -53
- package/src/parser/ast.js +81 -368
- package/src/parser/client-ast.js +138 -0
- package/src/parser/client-parser.js +504 -0
- package/src/parser/parser.js +492 -1056
- package/src/parser/server-ast.js +240 -0
- package/src/parser/server-parser.js +602 -0
- package/src/runtime/array-proto.js +32 -0
- package/src/runtime/embedded.js +1 -1
- package/src/runtime/reactivity.js +239 -42
- package/src/stdlib/advanced-collections.js +81 -0
- package/src/stdlib/inline.js +556 -13
- package/src/version.js +1 -1
package/src/analyzer/types.js
CHANGED
|
@@ -25,10 +25,10 @@ export class PrimitiveType extends Type {
|
|
|
25
25
|
if (target instanceof AnyType || target instanceof UnknownType) return true;
|
|
26
26
|
if (target instanceof PrimitiveType) {
|
|
27
27
|
if (this.name === target.name) return true;
|
|
28
|
-
// Int -> Float widening is always allowed
|
|
28
|
+
// Int -> Float widening is always allowed (safe)
|
|
29
29
|
if (this.name === 'Int' && target.name === 'Float') return true;
|
|
30
|
-
// Float -> Int:
|
|
31
|
-
|
|
30
|
+
// Float -> Int narrowing: NOT implicitly allowed at type level.
|
|
31
|
+
// The analyzer emits warning/error with conversion hint.
|
|
32
32
|
}
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
@@ -66,7 +66,15 @@ export class AnyType extends Type {
|
|
|
66
66
|
|
|
67
67
|
export class UnknownType extends Type {
|
|
68
68
|
equals(other) { return other instanceof UnknownType; }
|
|
69
|
-
isAssignableTo(
|
|
69
|
+
isAssignableTo(target) {
|
|
70
|
+
// In strict mode, unknown types are NOT assignable to concrete types
|
|
71
|
+
if (Type.strictMode) {
|
|
72
|
+
if (!target) return true;
|
|
73
|
+
if (target instanceof AnyType || target instanceof UnknownType) return true;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
70
78
|
toString() { return 'unknown'; }
|
|
71
79
|
}
|
|
72
80
|
|
|
@@ -322,6 +330,10 @@ export class UnionType extends Type {
|
|
|
322
330
|
}
|
|
323
331
|
}
|
|
324
332
|
|
|
333
|
+
// ─── Strict Mode Flag ────────────────────────────────────
|
|
334
|
+
|
|
335
|
+
Type.strictMode = false; // Set to true by analyzer in --strict mode
|
|
336
|
+
|
|
325
337
|
// ─── Singleton Caching ────────────────────────────────────
|
|
326
338
|
|
|
327
339
|
Type.INT = new PrimitiveType('Int');
|
|
@@ -369,6 +381,10 @@ export function typeAnnotationToType(ann) {
|
|
|
369
381
|
}
|
|
370
382
|
case 'FunctionTypeAnnotation':
|
|
371
383
|
return Type.FUNCTION;
|
|
384
|
+
case 'UnionTypeAnnotation': {
|
|
385
|
+
const members = ann.members.map(m => typeAnnotationToType(m) || Type.UNKNOWN);
|
|
386
|
+
return new UnionType(members);
|
|
387
|
+
}
|
|
372
388
|
default:
|
|
373
389
|
return null;
|
|
374
390
|
}
|