@native-sdk/cli 0.5.4 → 0.6.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/build/app.zig +50 -1
- package/build.zig +588 -32
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +3 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +280 -8
- package/packages/core/sdk/core.ts +481 -2
- package/packages/core/sdk/events.ts +17 -8
- package/packages/core/src/checker.ts +305 -2
- package/packages/core/src/diagnostics.ts +12 -0
- package/packages/core/src/emitter.ts +599 -3
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +39 -2
- package/skill-data/ts-core/SKILL.md +4 -2
- package/src/app_runner/root.zig +32 -10
- package/src/automation/layout_fingerprint.zig +160 -0
- package/src/automation/protocol.zig +82 -33
- package/src/automation/root.zig +1 -0
- package/src/automation/server.zig +1 -1
- package/src/automation/snapshot.zig +68 -9
- package/src/automation/watcher.zig +1 -1
- package/src/embed/host.zig +5 -0
- package/src/embed/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +527 -13
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +280 -7
- package/src/platform/macos/appkit_host.h +104 -6
- package/src/platform/macos/appkit_host.m +1368 -74
- package/src/platform/macos/cef_host.mm +110 -1
- package/src/platform/macos/root.zig +287 -7
- package/src/platform/null_platform.zig +398 -4
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +386 -14
- package/src/platform/windows/root.zig +298 -9
- package/src/platform/windows/webview2_host.cpp +330 -5
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/canvas/a11y_audit.zig +33 -11
- package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
- package/src/primitives/canvas/drawing.zig +25 -0
- package/src/primitives/canvas/equality.zig +8 -0
- package/src/primitives/canvas/events.zig +103 -16
- package/src/primitives/canvas/frame.zig +125 -1
- package/src/primitives/canvas/layout_audit.zig +22 -5
- package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
- package/src/primitives/canvas/render_tests.zig +13 -10
- package/src/primitives/canvas/root.zig +48 -0
- package/src/primitives/canvas/terminal_box.zig +471 -0
- package/src/primitives/canvas/terminal_grid.zig +978 -0
- package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +524 -5
- package/src/primitives/canvas/ui_markup.zig +195 -2
- package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
- package/src/primitives/canvas/ui_markup_contract.zig +88 -5
- package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
- package/src/primitives/canvas/ui_markup_tests.zig +149 -0
- package/src/primitives/canvas/ui_markup_view.zig +191 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
- package/src/primitives/canvas/ui_schema.zig +97 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -11
- package/src/primitives/canvas/ui_tests.zig +141 -9
- package/src/primitives/canvas/widget_access.zig +28 -2
- package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
- package/src/primitives/canvas/widget_invalidation.zig +81 -1
- package/src/primitives/canvas/widget_layout.zig +59 -11
- package/src/primitives/canvas/widget_layout_tests.zig +125 -4
- package/src/primitives/canvas/widget_render.zig +272 -18
- package/src/primitives/canvas/widget_render_scroll.zig +108 -27
- package/src/primitives/canvas/widget_routing.zig +59 -7
- package/src/primitives/canvas/widget_runtime.zig +23 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
- package/src/primitives/canvas/widget_semantics.zig +119 -11
- package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
- package/src/primitives/canvas/widget_tree.zig +17 -0
- package/src/primitives/canvas/widgets.zig +132 -0
- package/src/root.zig +16 -0
- package/src/runtime/api.zig +76 -6
- package/src/runtime/automation_commands.zig +20 -1
- package/src/runtime/automation_snapshot.zig +25 -1
- package/src/runtime/automation_widget_dispatch.zig +73 -8
- package/src/runtime/bridge_payload.zig +1 -0
- package/src/runtime/canvas_frame.zig +62 -7
- package/src/runtime/canvas_frame_animation_tests.zig +5 -4
- package/src/runtime/canvas_frame_helpers.zig +190 -1
- package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
- package/src/runtime/canvas_frame_patch_tests.zig +161 -10
- package/src/runtime/canvas_frame_retained_tests.zig +5 -2
- package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
- package/src/runtime/canvas_widget_context_menu.zig +269 -32
- package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
- package/src/runtime/canvas_widget_display.zig +1 -1
- package/src/runtime/canvas_widget_event_tests.zig +1823 -0
- package/src/runtime/canvas_widget_events.zig +268 -26
- package/src/runtime/canvas_widget_runtime.zig +213 -29
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
- package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
- package/src/runtime/canvas_widget_state.zig +6 -0
- package/src/runtime/canvas_widget_text_tests.zig +1 -1
- package/src/runtime/core.zig +73 -2
- package/src/runtime/effects.zig +6389 -54
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +14 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +25 -4
- package/src/runtime/gpu_surface_events.zig +475 -15
- package/src/runtime/media_surface.zig +116 -11
- package/src/runtime/media_surface_tests.zig +61 -0
- package/src/runtime/pty.zig +1252 -0
- package/src/runtime/pty_windows.zig +1780 -0
- package/src/runtime/root.zig +25 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_journal.zig +367 -61
- package/src/runtime/session_record.zig +16 -0
- package/src/runtime/session_replay.zig +395 -11
- package/src/runtime/session_tests.zig +114 -19
- package/src/runtime/terminal_session.zig +1569 -0
- package/src/runtime/terminal_session_tests.zig +450 -0
- package/src/runtime/terminal_vt_ghostty.zig +15 -0
- package/src/runtime/terminal_vt_stub.zig +13 -0
- package/src/runtime/tests.zig +6 -0
- package/src/runtime/ts_core_host.zig +980 -140
- package/src/runtime/ts_core_host_tests.zig +1059 -1
- package/src/runtime/ts_ui_app.zig +16 -5
- package/src/runtime/ui_app.zig +2338 -67
- package/src/runtime/ui_app_tests.zig +3171 -744
- package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
- package/src/runtime/ui_app_window_tests.zig +268 -0
- package/src/runtime/view.zig +190 -2
- package/src/runtime/view_widget_scroll.zig +218 -68
- package/src/runtime/view_widget_text.zig +11 -2
- package/src/runtime/view_widget_tree.zig +111 -3
- package/src/runtime/window_storage.zig +45 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +1 -0
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/templates.zig +25 -7
|
@@ -465,6 +465,8 @@ export class SubsetChecker {
|
|
|
465
465
|
this.checkSubPurity();
|
|
466
466
|
this.checkModelBindingSurface();
|
|
467
467
|
this.checkViewUnbound();
|
|
468
|
+
this.checkReservedContractConsts();
|
|
469
|
+
this.checkValueRecordAliases();
|
|
468
470
|
for (const file of this.files) this.walk(file);
|
|
469
471
|
this.checkExceptions();
|
|
470
472
|
return {
|
|
@@ -694,6 +696,300 @@ export class SubsetChecker {
|
|
|
694
696
|
}
|
|
695
697
|
}
|
|
696
698
|
|
|
699
|
+
/// The unbound-list consts (viewUnbound and the split
|
|
700
|
+
/// modelUnbound/msgUnbound pair) are contract vocabulary the build
|
|
701
|
+
/// reads and never emits, so a reference to one in program code would
|
|
702
|
+
/// name a declaration the generated module does not carry. Refuse the
|
|
703
|
+
/// reference where it stands instead of shipping an unresolved
|
|
704
|
+
/// identifier.
|
|
705
|
+
private checkReservedContractConsts(): void {
|
|
706
|
+
const reserved = new Set(["viewUnbound", "modelUnbound", "msgUnbound"]);
|
|
707
|
+
const declaresReserved = (decl: ts.Declaration | undefined): decl is ts.VariableDeclaration =>
|
|
708
|
+
decl !== undefined &&
|
|
709
|
+
ts.isVariableDeclaration(decl) &&
|
|
710
|
+
ts.isIdentifier(decl.name) &&
|
|
711
|
+
reserved.has(decl.name.text) &&
|
|
712
|
+
ts.isVariableDeclarationList(decl.parent) &&
|
|
713
|
+
ts.isVariableStatement(decl.parent.parent) &&
|
|
714
|
+
ts.isSourceFile(decl.parent.parent.parent);
|
|
715
|
+
const reportReserved = (decl: ts.VariableDeclaration, at: ts.Node): void => {
|
|
716
|
+
this.report(
|
|
717
|
+
"NS1032",
|
|
718
|
+
`\`${(decl.name as ts.Identifier).text}\` is the contract's unbound-list vocabulary the build reads without emitting — it cannot be referenced as module data; rename the constant to use it as data.`,
|
|
719
|
+
at,
|
|
720
|
+
);
|
|
721
|
+
};
|
|
722
|
+
// The lists are entry-module configuration: a declaration in an
|
|
723
|
+
// imported module is inert whether exported or not (the build reads
|
|
724
|
+
// the entry's declarations only), so it refuses like the exported
|
|
725
|
+
// form instead of silently configuring nothing.
|
|
726
|
+
for (const file of this.files) {
|
|
727
|
+
if (file === this.entry) continue;
|
|
728
|
+
for (const stmt of file.statements) {
|
|
729
|
+
if (!ts.isVariableStatement(stmt)) continue;
|
|
730
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
731
|
+
if (ts.isIdentifier(decl.name) && reserved.has(decl.name.text)) {
|
|
732
|
+
this.report("NS1014", `\`${decl.name.text}\` is declared in an imported module.`, decl.name);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
for (const file of this.files) {
|
|
738
|
+
const visit = (node: ts.Node): void => {
|
|
739
|
+
// The value side of a shorthand (`{ modelUnbound }`) reads the
|
|
740
|
+
// binding through the property symbol; resolve it explicitly.
|
|
741
|
+
if (ts.isShorthandPropertyAssignment(node)) {
|
|
742
|
+
const decl = this.tast.shorthandValueDeclaration(node);
|
|
743
|
+
if (declaresReserved(decl)) reportReserved(decl, node);
|
|
744
|
+
} else if (
|
|
745
|
+
ts.isIdentifier(node) &&
|
|
746
|
+
!(ts.isVariableDeclaration(node.parent) && node.parent.name === node) &&
|
|
747
|
+
!(ts.isPropertyAccessExpression(node.parent) && node.parent.name === node) &&
|
|
748
|
+
!(ts.isPropertyAssignment(node.parent) && node.parent.name === node) &&
|
|
749
|
+
!ts.isPropertySignature(node.parent) &&
|
|
750
|
+
!(ts.isExportSpecifier(node.parent) || ts.isImportSpecifier(node.parent)) &&
|
|
751
|
+
!ts.isShorthandPropertyAssignment(node.parent)
|
|
752
|
+
) {
|
|
753
|
+
// Resolve through import aliases so a renamed binding
|
|
754
|
+
// (`import { modelUnbound as names }`) is caught by what it
|
|
755
|
+
// DECLARES, never by its spelling.
|
|
756
|
+
const decl = this.tast.declarationOf(node);
|
|
757
|
+
if (declaresReserved(decl)) reportReserved(decl, node);
|
|
758
|
+
}
|
|
759
|
+
ts.forEachChild(node, visit);
|
|
760
|
+
};
|
|
761
|
+
visit(file);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
/// Object-literal aliases pin VALUE storage (the contract projection's
|
|
766
|
+
/// value-record spelling), which the model's commit machinery carries
|
|
767
|
+
/// only for scalar-shallow records — so the shapes value storage
|
|
768
|
+
/// cannot honor refuse HERE with the teaching, never downstream as an
|
|
769
|
+
/// internal emit failure or a silent dangling slice:
|
|
770
|
+
/// the model root itself (the commit walkers need the reference
|
|
771
|
+
/// root), model-kept aliases with heap-backed fields, model arrays of
|
|
772
|
+
/// alias records (no by-value slice commit walk), identity comparison
|
|
773
|
+
/// over value records, and alias self-reference (no finite by-value
|
|
774
|
+
/// layout).
|
|
775
|
+
private checkValueRecordAliases(): void {
|
|
776
|
+
const aliasStruct = (name: string): ts.TypeAliasDeclaration | null => {
|
|
777
|
+
const info = this.table.structs.get(name);
|
|
778
|
+
return info && ts.isTypeAliasDeclaration(info.decl) ? info.decl : null;
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
const modelAlias = aliasStruct("Model");
|
|
782
|
+
if (modelAlias) {
|
|
783
|
+
this.report("NS1061", "`Model` is declared as an object-literal alias — the model root is reference storage by contract; declare it as an interface.", modelAlias.name);
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// The entry roots keep their contract shapes whatever declaration
|
|
787
|
+
// form produced them: a `Model` that classified as anything but a
|
|
788
|
+
// record (a singleton tagged alias becomes a union, for one) has no
|
|
789
|
+
// commit path, and a `Msg` that classified as anything but a
|
|
790
|
+
// kind-tagged union (a plain object alias or an interface becomes a
|
|
791
|
+
// struct) has no dispatch path.
|
|
792
|
+
for (const file of this.files) {
|
|
793
|
+
for (const stmt of file.statements) {
|
|
794
|
+
if (!ts.isInterfaceDeclaration(stmt) && !ts.isTypeAliasDeclaration(stmt) && !(ts.isClassDeclaration(stmt) && stmt.name)) continue;
|
|
795
|
+
const rootName = stmt.name!.text;
|
|
796
|
+
if (rootName === "Model" && (ts.isClassDeclaration(stmt) || !this.table.structs.has("Model"))) {
|
|
797
|
+
this.report("NS1062", "`Model` does not declare a record — the model root is a reference-stored record; declare it as an interface.", stmt.name!);
|
|
798
|
+
}
|
|
799
|
+
if (rootName === "Msg" && !this.table.unions.has("Msg")) {
|
|
800
|
+
this.report("NS1062", "`Msg` does not declare a kind-tagged union — dispatch routes by the declaration-order kind tags; declare it as a union of `{ kind: \"...\" }` arms.", stmt.name!);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// The model-reachable record set, walked over the type table.
|
|
806
|
+
const reachable = new Set<string>();
|
|
807
|
+
const visit = (t: import("./types.ts").ZType, holder: ts.Node): void => {
|
|
808
|
+
switch (t.k) {
|
|
809
|
+
case "struct": {
|
|
810
|
+
if (reachable.has(t.name)) return;
|
|
811
|
+
reachable.add(t.name);
|
|
812
|
+
const info = this.table.structs.get(t.name);
|
|
813
|
+
if (info) for (const f of info.fields) visit(f.type, f.decl);
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
case "union": {
|
|
817
|
+
const info = this.table.unions.get(t.name);
|
|
818
|
+
if (info && !reachable.has(t.name)) {
|
|
819
|
+
reachable.add(t.name);
|
|
820
|
+
for (const arm of info.arms) for (const f of arm.fields) visit(f.type, f.decl);
|
|
821
|
+
}
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
case "slice": {
|
|
825
|
+
const elem = t.elem.k === "optional" ? t.elem.inner : t.elem;
|
|
826
|
+
if (elem.k === "struct") {
|
|
827
|
+
const alias = aliasStruct(elem.name);
|
|
828
|
+
if (alias) {
|
|
829
|
+
this.report("NS1061", `A model array holds \`${elem.name}\`, a value-record alias — arrays the model keeps carry reference-stored records; declare \`${elem.name}\` as an interface.`, holder);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return visit(t.elem, holder);
|
|
833
|
+
}
|
|
834
|
+
case "optional":
|
|
835
|
+
return visit(t.inner, holder);
|
|
836
|
+
default:
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
if (this.table.structs.has("Model")) visit({ k: "struct", name: "Model" }, this.table.structs.get("Model")!.decl);
|
|
841
|
+
|
|
842
|
+
const scalar = (k: string): boolean => k === "number" || k === "i64" || k === "f64" || k === "bool" || k === "enum" || k === "numAlias";
|
|
843
|
+
for (const name of reachable) {
|
|
844
|
+
const alias = aliasStruct(name);
|
|
845
|
+
if (!alias) continue;
|
|
846
|
+
const info = this.table.structs.get(name)!;
|
|
847
|
+
for (const f of info.fields) {
|
|
848
|
+
if (!scalar(f.type.k)) {
|
|
849
|
+
this.report(
|
|
850
|
+
"NS1061",
|
|
851
|
+
`\`${name}\` is a value-record alias the model keeps, but field \`${f.tsName}\` is not a scalar — value records commit shallowly, so heap-backed fields would dangle across frames; declare \`${name}\` as an interface.`,
|
|
852
|
+
f.decl,
|
|
853
|
+
);
|
|
854
|
+
break;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// By-value self-reference has no finite layout (a slice breaks the
|
|
860
|
+
// cycle by indirection; struct, union, and optional fields do not).
|
|
861
|
+
// The walk covers every by-value node — value-stored records AND
|
|
862
|
+
// tagged unions, whose arms live inline — so recursion through a
|
|
863
|
+
// singleton union refuses the same way as through a record.
|
|
864
|
+
const cycleEdge = (t: import("./types.ts").ZType): string | null => {
|
|
865
|
+
const inner = t.k === "optional" ? t.inner : t;
|
|
866
|
+
if (inner.k === "struct") return this.table.isPointerStruct(inner.name) ? null : inner.name;
|
|
867
|
+
if (inner.k === "union") return inner.name;
|
|
868
|
+
return null;
|
|
869
|
+
};
|
|
870
|
+
const byValueEdges = (name: string): string[] => {
|
|
871
|
+
const edges: string[] = [];
|
|
872
|
+
const struct = this.table.structs.get(name);
|
|
873
|
+
if (struct && !this.table.isPointerStruct(name)) {
|
|
874
|
+
for (const f of struct.fields) {
|
|
875
|
+
const edge = cycleEdge(f.type);
|
|
876
|
+
if (edge !== null) edges.push(edge);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
const union = this.table.unions.get(name);
|
|
880
|
+
if (union) {
|
|
881
|
+
for (const arm of union.arms) {
|
|
882
|
+
for (const f of arm.fields) {
|
|
883
|
+
const edge = cycleEdge(f.type);
|
|
884
|
+
if (edge !== null) edges.push(edge);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return edges;
|
|
889
|
+
};
|
|
890
|
+
const cyclic = new Set<string>();
|
|
891
|
+
for (const name of [...this.table.structs.keys(), ...this.table.unions.keys()]) {
|
|
892
|
+
if (this.table.structs.has(name) && this.table.isPointerStruct(name)) continue;
|
|
893
|
+
const seen = new Set<string>([name]);
|
|
894
|
+
const stack = byValueEdges(name);
|
|
895
|
+
while (stack.length > 0) {
|
|
896
|
+
const next = stack.pop()!;
|
|
897
|
+
if (next === name) {
|
|
898
|
+
cyclic.add(name);
|
|
899
|
+
break;
|
|
900
|
+
}
|
|
901
|
+
if (seen.has(next)) continue;
|
|
902
|
+
seen.add(next);
|
|
903
|
+
stack.push(...byValueEdges(next));
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
for (const name of cyclic) {
|
|
907
|
+
const decl = this.table.structs.get(name)?.decl ?? this.table.unions.get(name)?.decl;
|
|
908
|
+
if (decl === undefined) continue;
|
|
909
|
+
const declName = (decl as ts.InterfaceDeclaration | ts.TypeAliasDeclaration | ts.ClassDeclaration).name ?? decl;
|
|
910
|
+
this.report("NS1061", `\`${name}\` reaches itself by value — a by-value layout has no finite size when it contains itself; break the cycle with an array, or store the record in the model (reference storage).`, declName);
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// Identity comparison over a value record compares nothing the
|
|
914
|
+
// storage carries. Union operand types (`Pos | null`) check every
|
|
915
|
+
// constituent, and plain type aliases resolve to their targets, so
|
|
916
|
+
// a wrapped spelling cannot slip a value record past the guard.
|
|
917
|
+
const aliasStructNamed = (spelling: string): string | null => {
|
|
918
|
+
let named = spelling;
|
|
919
|
+
const seen = new Set<string>();
|
|
920
|
+
while (!seen.has(named)) {
|
|
921
|
+
seen.add(named);
|
|
922
|
+
const target = this.table.plainAliases.get(named);
|
|
923
|
+
if (target === undefined) break;
|
|
924
|
+
named = target;
|
|
925
|
+
}
|
|
926
|
+
return aliasStruct(named) !== null ? named : null;
|
|
927
|
+
};
|
|
928
|
+
const aliasStructOfType = (t: ts.Type): string | null => {
|
|
929
|
+
if (t.isUnion()) {
|
|
930
|
+
for (const constituent of t.types) {
|
|
931
|
+
const named = aliasStructOfType(constituent);
|
|
932
|
+
if (named !== null) return named;
|
|
933
|
+
}
|
|
934
|
+
return null;
|
|
935
|
+
}
|
|
936
|
+
const named = t.aliasSymbol?.name ?? t.symbol?.name;
|
|
937
|
+
if (!named) return null;
|
|
938
|
+
return aliasStructNamed(named);
|
|
939
|
+
};
|
|
940
|
+
for (const file of this.files) {
|
|
941
|
+
const walkEq = (node: ts.Node): void => {
|
|
942
|
+
if (
|
|
943
|
+
ts.isBinaryExpression(node) &&
|
|
944
|
+
(node.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
945
|
+
node.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsEqualsToken)
|
|
946
|
+
) {
|
|
947
|
+
// Identity is only in question when BOTH sides can be
|
|
948
|
+
// records at once: a presence check against null (or any
|
|
949
|
+
// never-a-record operand) compares the option, not the
|
|
950
|
+
// record, and stays exact. Operands are typed with their
|
|
951
|
+
// assertions PEELED — an `as` erases at emission, so the
|
|
952
|
+
// compared value is the underlying expression's, and a
|
|
953
|
+
// structural respelling cannot shed the record's name. The
|
|
954
|
+
// record test on the OTHER side is structural for the same
|
|
955
|
+
// reason.
|
|
956
|
+
const peel = (e: ts.Expression): ts.Expression => {
|
|
957
|
+
let cur = e;
|
|
958
|
+
while (ts.isParenthesizedExpression(cur) || ts.isAsExpression(cur) || ts.isSatisfiesExpression(cur) || ts.isNonNullExpression(cur)) {
|
|
959
|
+
cur = cur.expression;
|
|
960
|
+
}
|
|
961
|
+
return cur;
|
|
962
|
+
};
|
|
963
|
+
const canBeRecord = (t: ts.Type): boolean => {
|
|
964
|
+
if (t.isUnion()) return t.types.some(canBeRecord);
|
|
965
|
+
return (t.flags & ts.TypeFlags.Object) !== 0;
|
|
966
|
+
};
|
|
967
|
+
// Each operand is read through BOTH views — the peeled
|
|
968
|
+
// expression (assertions erase at emission) and the spelled
|
|
969
|
+
// one (an assertion may be what NAMES the record) — so
|
|
970
|
+
// neither adding nor shedding a spelling moves a comparison
|
|
971
|
+
// past the guard.
|
|
972
|
+
const sideView = (e: ts.Expression): { named: string | null; record: boolean } => {
|
|
973
|
+
const peeled = this.tast.typeOf(peel(e));
|
|
974
|
+
const spelled = this.tast.typeOf(e);
|
|
975
|
+
return {
|
|
976
|
+
named: aliasStructOfType(peeled) ?? aliasStructOfType(spelled),
|
|
977
|
+
record: canBeRecord(peeled) || canBeRecord(spelled),
|
|
978
|
+
};
|
|
979
|
+
};
|
|
980
|
+
const left = sideView(node.left);
|
|
981
|
+
const right = sideView(node.right);
|
|
982
|
+
const named = left.named ?? right.named;
|
|
983
|
+
if (named !== null && (left.named === null ? left.record : right.record)) {
|
|
984
|
+
this.report("NS1061", `\`${named}\` values compare by content, not identity — a value-record alias has no reference to compare; compare its fields, or declare \`${named}\` as an interface for identity.`, node);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
ts.forEachChild(node, walkEq);
|
|
988
|
+
};
|
|
989
|
+
walkEq(file);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
697
993
|
// --------------------------------------------------------- module surface
|
|
698
994
|
|
|
699
995
|
private checkModuleShape(file: ts.SourceFile): void {
|
|
@@ -780,7 +1076,7 @@ export class SubsetChecker {
|
|
|
780
1076
|
continue;
|
|
781
1077
|
}
|
|
782
1078
|
const targetName = ts.isFunctionDeclaration(target) || ts.isVariableDeclaration(target) ? target.name?.getText() : undefined;
|
|
783
|
-
if (b.renamed && (targetName === "viewUnbound" || targetName === "envMsgs")) {
|
|
1079
|
+
if (b.renamed && (targetName === "viewUnbound" || targetName === "envMsgs" || targetName === "modelUnbound" || targetName === "msgUnbound")) {
|
|
784
1080
|
this.report(
|
|
785
1081
|
"NS1047",
|
|
786
1082
|
`\`${b.exportedName}\` renames \`${targetName}\`, which is wiring config the build reads by its own name, not an emitted value.`,
|
|
@@ -796,7 +1092,7 @@ export class SubsetChecker {
|
|
|
796
1092
|
private static readonly entryOnlyExports = new Set([
|
|
797
1093
|
"update", "initialModel", "subscriptions",
|
|
798
1094
|
"commandMsg", "keyMsg", "frameMsg", "pinchMsg", "appearanceMsg", "chromeMsg", "envMsgs",
|
|
799
|
-
"viewUnbound",
|
|
1095
|
+
"viewUnbound", "modelUnbound", "msgUnbound",
|
|
800
1096
|
]);
|
|
801
1097
|
|
|
802
1098
|
private checkEntryContract(): void {
|
|
@@ -1845,6 +2141,13 @@ export class SubsetChecker {
|
|
|
1845
2141
|
if (propDecl && ts.isPropertyDeclaration(propDecl)) {
|
|
1846
2142
|
this.checkInstanceMutation(fieldWrite.expression, node, what);
|
|
1847
2143
|
}
|
|
2144
|
+
// Record fields (interface or object-alias members) have no
|
|
2145
|
+
// in-place write in the emitted layout — records update by
|
|
2146
|
+
// reconstruction. tsc already fences `readonly` spellings;
|
|
2147
|
+
// this closes the mutable-declared ones the same way.
|
|
2148
|
+
if (propDecl && ts.isPropertySignature(propDecl)) {
|
|
2149
|
+
this.report("NS1001", `${what} mutates a record in place — records update by reconstruction (\`{ ...value, ${fieldWrite.name.text}: v }\`).`, node);
|
|
2150
|
+
}
|
|
1848
2151
|
}
|
|
1849
2152
|
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
|
|
1850
2153
|
const recv = node.expression.expression;
|
|
@@ -382,6 +382,18 @@ export const rules = {
|
|
|
382
382
|
fix: "Use the byte surface: case with `.toUpperCase()`/`.toLowerCase()` (Unicode simple case mapping, locale-free), search with `.includes`/`.indexOf`/`.lastIndexOf`/`.startsWith`/`.endsWith` (bytes needles), measure and pad in bytes (`.length`, `.padStart`), read bytes with `b[i]`/`.at(i)`, and rebuild text with `.split`, slices, and a push-builder.",
|
|
383
383
|
why: "Core text is UTF-8 bytes with exactly one representation under node and native; UTF-16 code-unit reads and Unicode normalization would reintroduce the encoding seam the bytes model exists to close, so their spellings teach the byte-honest form instead.",
|
|
384
384
|
},
|
|
385
|
+
NS1061: {
|
|
386
|
+
id: "NS1061",
|
|
387
|
+
title: "value records stay scalar where the model keeps them",
|
|
388
|
+
fix: "Declare the record as an interface (reference storage) to hold heap-backed fields, sit in a model array, carry identity under `===`, or reference itself; an object-literal alias (value storage) in the model tree carries scalar fields only (numbers, booleans, literal-union tags).",
|
|
389
|
+
why: "An object-literal alias pins by-value storage — the contract projection's value-record spelling. The model's commit machinery copies by-value records shallowly, so heap-backed fields would dangle across frames, arrays of them have no commit walk, equality has no identity to compare, and a self-reference has no finite layout; each of those needs reference storage, which the interface form declares.",
|
|
390
|
+
},
|
|
391
|
+
NS1062: {
|
|
392
|
+
id: "NS1062",
|
|
393
|
+
title: "the entry roots keep their contract shapes",
|
|
394
|
+
fix: "Declare `Model` as an interface record (`export interface Model { ... }`) and `Msg` as a kind-tagged union (`export type Msg = { kind: \"...\" } | ...`).",
|
|
395
|
+
why: "The generated wiring commits `Model` as the reference-stored record root and dispatches `Msg` by its declaration-order kind tags; any other shape under those names has no dispatch or commit path and would fail deep inside the emitted module instead of teaching here.",
|
|
396
|
+
},
|
|
385
397
|
// NS9xxx: internal emit-time verification. A checker gap becomes a loud
|
|
386
398
|
// internal error naming the construct, never silent misbehavior.
|
|
387
399
|
NS9001: {
|