diff --git a/AGENTS.md b/AGENTS.md
index da6cf6eb..1047f8de 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -22,8 +22,8 @@ make setup # once: the switch solidtype, all dependencies, and
# Bun's
make test # the ppx's lowering, the plugin's rewrite, the
# libraries' tests and the example's
-make lint # formatting, the plugin's and the generators' types, the
- # release build, and the generated bindings
+make lint # formatting, the plugin's and the generators' types,
+ # litany, the release build, and the generated bindings
make fmt # format in place
make example # the board, built by Vite into _build/example-dist, and
# its Astro page, into _build/example-astro
@@ -34,7 +34,7 @@ make docs # the documentation site, odoc's reference copied into
# as .github/workflows/docs.yml publishes it from main
make docs-serve # the documentation site built, served on DOCS_PORT with
# search
-make release VERSION=1.2.3 # once CHANGES.md names it: tag and release with open-opam
+make release VERSION=1.2.3 # tag and release
```
The plugin and the example run on Bun 1.3 or later: JavaScript here only
@@ -282,9 +282,6 @@ test/does_not_compile.t
installed library, with the error a user reads
```
-Each module's contract is its `.mli`. Read the `.mli` before changing a
-module.
-
## The pipeline
MLX parses `.mlx` into OCaml with each element marked `[@JSX]`.
@@ -689,12 +686,6 @@ break.
a test in TypeScript would reach a component through the names Melange
emits. Symptom: a `.test.ts` or `.test.tsx` that imports an OCaml
module.
-- **The opens are the ppx's `Ppxlib`**, which every ppxlib rewriter opens
- to build the AST it writes, and its `Result.Syntax`, whose `let*` chains
- the results it builds, **and a test library's `Syntax`**
- (`Testing.Syntax`, `Harness.Syntax`), whose `let*` awaits a promise as
- `MELANGE.md` lets a test. Symptom: `rg -n '^\s*open ' src ppx example
- test | rg -v 'open (Ppxlib|Syntax|\w+\.Syntax)$'` finds any other.
## Changes and releases
diff --git a/CHANGES.md b/CHANGES.md
index cf82aa15..d56b0075 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,13 @@
# Changes
+## 0.11.1 (2026-11-16)
+
+- The code `ppx_solidtype` writes around a component's tag, the `if false`
+ that holds its props to `Props.check`, is at a ghost location, so a linter
+ reading the typed tree no longer reports a literal condition at every tag.
+- `Theme`'s storage catches the browser's throw alone, `Js.Exn.Error`, and
+ no longer an OCaml exception raised beside it.
+
## 0.11.0 (2026-11-15)
- In JSX a value is written as itself, and Solid keeps it current, as its
diff --git a/Makefile b/Makefile
index 38928e50..b515656a 100644
--- a/Makefile
+++ b/Makefile
@@ -31,9 +31,10 @@ test: build node_modules ## run the tests
$(OPAM) bun run test
# Release is the profile opam installs with.
-lint: node_modules ## check formatting, types, the release build and bindings
+lint: node_modules ## check formatting, types, litany, the release build and bindings
$(OPAM) dune build @all @fmt
$(OPAM) dune build --profile release @all
+ $(OPAM) litany check
bun run tsc -p vite-plugin
bun run tsc -p generate
$(OPAM) bun generate/html.ts --check
diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx
index 27e711f8..54742bd5 100644
--- a/docs/src/content/docs/index.mdx
+++ b/docs/src/content/docs/index.mdx
@@ -65,7 +65,7 @@ GitHub release:
"solid-js": "~1.9.17",
"vite": "^8.3.0",
"vite-plugin-solid": "^2.11.14",
- "vite-plugin-solidtype": "https://github.com/hyphatech/solidtype/releases/download/0.11.0/vite-plugin-solidtype-0.11.0.tgz"
+ "vite-plugin-solidtype": "https://github.com/hyphatech/solidtype/releases/download/0.11.1/vite-plugin-solidtype-0.11.1.tgz"
}
}
```
diff --git a/dune-project b/dune-project
index 6f133fa1..d4f6b5c6 100644
--- a/dune-project
+++ b/dune-project
@@ -123,7 +123,12 @@
(ocamlformat-mlx
(and
:with-dev-setup
- (= 0.29.0.1)))))
+ (= 0.29.0.1)))
+ (hypha-litany
+ (and
+ :with-dev-setup
+ (>= 1.2.2)
+ (< 2.0.0)))))
(package
(name solidtype-kobalte)
diff --git a/generate/binding.ts b/generate/binding.ts
index ae60af59..03c01da4 100644
--- a/generate/binding.ts
+++ b/generate/binding.ts
@@ -23,8 +23,8 @@ export type Library = {
// already an optional prop's absence; undefined for any other, which the
// core maps by its rules.
ported?: (symbol: ts.Symbol, args: Type[], absent: boolean) => Type | undefined;
- // Whether a number is a small whole one where it is met, by where: an int,
- // as MELANGE.md lets a binding that knows it; a float anywhere else.
+ // Whether a number is a small whole one where it is met, by where: an int
+ // where the binding knows it fits 32 bits; a float anywhere else.
whole?: (where: string) => boolean;
// The classes whose values are one type of Types, Value, a kind each, and
// the structural interfaces they satisfy: a union of the classes, or one of
diff --git a/heroui/autocomplete.mlx b/heroui/autocomplete.mlx
index 4661d36d..0a6d28c5 100644
--- a/heroui/autocomplete.mlx
+++ b/heroui/autocomplete.mlx
@@ -829,7 +829,7 @@ let%component make ?(placeholder : string = "Select an item")
Aria's does; an autocomplete opens with no option at all only by
[allows_empty_collection]. *)
let open_refused o =
- o && (not (S.get allows_empty_collection)) && List.length (options ()) = 0
+ o && (not (S.get allows_empty_collection)) && List.is_empty (options ())
in
match mode with
| `single ->
diff --git a/heroui/theme.ml b/heroui/theme.ml
index 1d71d6d9..4d157057 100644
--- a/heroui/theme.ml
+++ b/heroui/theme.ml
@@ -37,10 +37,12 @@ external set_attribute : Dom.element -> string -> string -> unit
let stored () =
match get_item storage_key with
| value -> Js.Null.toOption value
- | exception _ -> None
+ | exception Js.Exn.Error _ -> None
let store theme =
- match set_item storage_key theme with () -> () | exception _ -> ()
+ match set_item storage_key theme with
+ | () -> ()
+ | exception Js.Exn.Error _ -> ()
type t = {
theme : string S.accessor;
diff --git a/litany b/litany
new file mode 100644
index 00000000..6be4be17
--- /dev/null
+++ b/litany
@@ -0,0 +1,8 @@
+(lint
+ (select default)
+ (extend open-of-ordinary-module))
+
+(per-path
+ (paths heroui/toggle_button_group.mlx)
+ (ignore suspicious-physical-equality)
+ (reason "a button leaving the group removes its own accessor: identity is the point"))
diff --git a/ppx/ppx_solidtype.ml b/ppx/ppx_solidtype.ml
index 716d3cdf..4234b71a 100644
--- a/ppx/ppx_solidtype.ml
+++ b/ppx/ppx_solidtype.ml
@@ -1,14 +1,14 @@
-open Ppxlib
open Result.Syntax
-module B = Ast_builder.Default
+module P = Ppxlib
+module B = P.Ast_builder.Default
-let attribute ~loc ?(payload = PStr []) name =
+let attribute ~loc ?(payload = P.PStr []) name =
B.attribute ~loc ~name:{ txt = name; loc } ~payload
(* MLX marks every element it parses with this attribute. *)
-let is_jsx (e : expression) =
+let is_jsx (e : P.expression) =
List.exists
- (fun (a : attribute) -> String.equal a.attr_name.txt "JSX")
+ (fun (a : P.attribute) -> String.equal a.attr_name.txt "JSX")
e.pexp_attributes
(* A spread is the attribute [props=p], as MLX has no syntax for one, so
@@ -73,7 +73,7 @@ let js_name label =
also reads escapes in {js|...|js}, where [s] is already the string's
value, so each backslash is doubled to reach the page as one. A string
written {js|...|js} is JavaScript's already, its escapes meant. *)
-let js_string (e : expression) =
+let js_string (e : P.expression) =
match e.pexp_desc with
| Pexp_constant (Pconst_string (_, _, Some "js")) -> e
| Pexp_constant (Pconst_string (s, loc, _)) ->
@@ -81,17 +81,17 @@ let js_string (e : expression) =
{ e with pexp_desc = Pexp_constant (Pconst_string (s, loc, Some "js")) }
| _ -> e
-let last = function Ldot (_, name) | Lident name -> name | Lapply _ -> ""
+let last = function P.Ldot (_, name) | Lident name -> name | Lapply _ -> ""
let is_handler label =
String.length label > 3 && starts_with ~prefix:"on_" label
-let is_unit (p : pattern) =
+let is_unit (p : P.pattern) =
match p.ppat_desc with
| Ppat_construct ({ txt = Lident "()"; _ }, None) -> true
| _ -> false
-let is_thunk (e : expression) =
+let is_thunk (e : P.expression) =
match e.pexp_desc with
| Pexp_function ({ pparam_desc = Pparam_val (Nolabel, None, p); _ } :: _, _, _)
->
@@ -105,21 +105,22 @@ let is_thunk (e : expression) =
let render = "render"
let named_render = "solidtype.render"
-let is_named_render (e : expression) =
+let is_named_render (e : P.expression) =
List.exists
- (fun (a : attribute) -> String.equal a.attr_name.txt named_render)
+ (fun (a : P.attribute) -> String.equal a.attr_name.txt named_render)
e.pexp_attributes
-let unmark (e : expression) =
+let unmark (e : P.expression) =
{
e with
pexp_attributes =
List.filter
- (fun (a : attribute) -> not (String.equal a.attr_name.txt named_render))
+ (fun (a : P.attribute) ->
+ not (String.equal a.attr_name.txt named_render))
e.pexp_attributes;
}
-let is_function (e : expression) =
+let is_function (e : P.expression) =
is_named_render e
|| match e.pexp_desc with Pexp_function _ -> true | _ -> false
@@ -133,7 +134,7 @@ let is_function (e : expression) =
belongs. *)
type kind = Literal | Element | Function | Thunk
-let kind_of ~handler (e : expression) =
+let kind_of ~handler (e : P.expression) =
match e.pexp_desc with
| Pexp_constant _ | Pexp_construct (_, None) | Pexp_variant (_, None) ->
Literal
@@ -147,14 +148,14 @@ let kind_of ~handler (e : expression) =
element it is written in, outside a branch Solid has not yet drawn, unless
it is in a thunk, which Melange never moves out of and the plugin unwraps.
A name or a function literal makes nothing. *)
-let is_made (e : expression) =
+let is_made (e : P.expression) =
match e.pexp_desc with Pexp_ident _ | Pexp_function _ -> false | _ -> true
(* Solid calls what it is handed with no argument, so each thunk the ppx
hands it is a JavaScript function of none, which Melange writes whole for an
uncurried [fun]: a curried [fun () -> fun x -> e] would be one function of
two, run at once by a call of none. *)
-let uncurried ~loc (e : expression) =
+let uncurried ~loc (e : P.expression) =
(* A thunk's result type, [fun () : t -> e] or [fun () :> t -> e], as MLX
may read [fun () -> (e :> t)], is written on its body instead: an
uncurried function's result constraint is typed as an exact match on
@@ -171,10 +172,10 @@ let uncurried ~loc (e : expression) =
{ e with pexp_desc = Pexp_function (params, None, Pfunction_body body) }
| _ -> e
in
- let marked (e : expression) =
+ let marked (e : P.expression) =
if
List.exists
- (fun (a : attribute) -> String.equal a.attr_name.txt "u")
+ (fun (a : P.attribute) -> String.equal a.attr_name.txt "u")
e.pexp_attributes
then e
else { e with pexp_attributes = attribute ~loc "u" :: e.pexp_attributes }
@@ -216,9 +217,9 @@ let uncurried ~loc (e : expression) =
}
| _ -> marked e
-let thunk ~loc (e : expression) = uncurried ~loc [%expr fun () -> [%e e]]
+let thunk ~loc (e : P.expression) = uncurried ~loc [%expr fun () -> [%e e]]
-let call ~loc (f : expression) =
+let call ~loc (f : P.expression) =
let apply f =
{
(B.pexp_apply ~loc f [ (Nolabel, [%expr ()]) ]) with
@@ -227,7 +228,7 @@ let call ~loc (f : expression) =
in
(* A thunk called where it is written is its body, which Melange would
otherwise write as a function made and called at once. *)
- let rec body (f : expression) =
+ let rec body (f : P.expression) =
match f.pexp_desc with
| Pexp_function
( [ { pparam_desc = Pparam_val (Nolabel, None, p); _ } ],
@@ -248,14 +249,14 @@ let call ~loc (f : expression) =
[%e apply [%expr solidtype__f]]]
let error ~loc message =
- B.pexp_extension ~loc (Location.error_extensionf ~loc "%s" message)
+ B.pexp_extension ~loc (P.Location.error_extensionf ~loc "%s" message)
let rec all = function
| [] -> Ok []
| Ok x :: rest -> Result.map (fun xs -> x :: xs) (all rest)
| (Error _ as e) :: _ -> e
-let rec list_items (e : expression) =
+let rec list_items (e : P.expression) =
match e.pexp_desc with
| Pexp_construct ({ txt = Lident "[]"; _ }, None) -> Ok []
| Pexp_construct
@@ -268,9 +269,9 @@ let rec list_items (e : expression) =
let split args =
let children, props =
List.partition_map
- (fun (label, (value : expression)) ->
+ (fun (label, (value : P.expression)) ->
match (label, value.pexp_desc) with
- | Labelled "children", _ -> Left value
+ | P.Labelled "children", _ -> Left value
| Nolabel, Pexp_construct ({ txt = Lident "()"; _ }, None) -> Right None
| _ -> Right (Some (label, value)))
args
@@ -279,7 +280,7 @@ let split args =
let given, props =
List.partition
(fun (label, _) ->
- match label with Labelled l -> String.equal l render | _ -> false)
+ match label with P.Labelled l -> String.equal l render | _ -> false)
props
in
let* cs =
@@ -295,7 +296,7 @@ let split args =
( f.pexp_loc,
"a function written in place is the component's child, (fun \
...); render=f gives one by its name" )
- | [ (_, (f : expression)) ], [] ->
+ | [ (_, (f : P.expression)) ], [] ->
let loc = f.pexp_loc in
Ok
( props,
@@ -305,11 +306,11 @@ let split args =
pexp_attributes = attribute ~loc named_render :: f.pexp_attributes;
};
] )
- | (_, (f : expression)) :: _, _ ->
+ | (_, (f : P.expression)) :: _, _ ->
Error (f.pexp_loc, "render=f is a component's only child")
let labelled ~loc = function
- | Labelled label -> Ok label
+ | P.Labelled label -> Ok label
| Optional label ->
Error (loc, Printf.sprintf "?%s is not supported: pass ~%s" label label)
| Nolabel -> Error (loc, "a JSX prop is labelled")
@@ -318,7 +319,7 @@ let labelled ~loc = function
is, whose [None] Solid and Kobalte are given as [undefined], absent.
OCaml's own [?name:] in the check refuses it where the prop is not
optional. *)
-let optional ~loc label (value : expression) =
+let optional ~loc label (value : P.expression) =
if starts_with ~prefix:"data_" label || String.equal label spread then
Error (loc, Printf.sprintf "?%s is not optional: pass %s=" label label)
else
@@ -330,7 +331,7 @@ let absent_or ~loc read =
(* A child is told apart before it is lowered, while an element still carries
MLX's attribute. *)
-let child map (e : expression) =
+let child map (e : P.expression) =
let loc = e.pexp_loc in
match e.pexp_desc with
| Pexp_constant (Pconst_string _) ->
@@ -354,12 +355,12 @@ let child map (e : expression) =
type namespace = Native | Capture | Prop | Attr | Bool
type wrapped =
- | Namespaced of namespace * expression
- | Listen of string * expression (** [on=(Jsx.listen "myEvent" f)] *)
- | Named of string * expression (** [attr=(Jsx.named "data-x" s)] *)
+ | Namespaced of namespace * P.expression
+ | Listen of string * P.expression (** [on=(Jsx.listen "myEvent" f)] *)
+ | Named of string * P.expression (** [attr=(Jsx.named "data-x" s)] *)
-let wrapped (e : expression) =
- let string_literal (e : expression) =
+let wrapped (e : P.expression) =
+ let string_literal (e : P.expression) =
match e.pexp_desc with
| Pexp_constant (Pconst_string (s, _, _)) -> Some s
| _ -> None
@@ -390,7 +391,7 @@ let wrapped (e : expression) =
(* An element's attribute, from its OCaml label and its value: its
JavaScript name, its type -- the element's own in [Solidtype.Html], or the
namespace's -- and the value the wrapper held. *)
-let dom_attribute ~loc ~tag label (value : expression) =
+let dom_attribute ~loc ~tag label (value : P.expression) =
let html =
B.ptyp_constr ~loc
{
@@ -442,7 +443,7 @@ let dom_attribute ~loc ~tag label (value : expression) =
of a component: present, or absent while a flag is down, so the
attribute is Solid's to write on the server as in the browser. A string
literal, the common case, is written as [Jsx.data] for it. *)
-let data ~loc label (value : expression) =
+let data ~loc label (value : P.expression) =
let name = B.estring ~loc (js_name label) in
match (value.pexp_desc, kind_of ~handler:false value) with
| Pexp_constant (Pconst_string _), _ ->
@@ -459,7 +460,7 @@ let data ~loc label (value : expression) =
element unchecked, as a data- attribute: [attr:], [bool:], and a name the
spelling rule cannot keep. A handler's and a property's are an element's
alone, since a component's props name its own. *)
-let passed_on ~loc label (value : expression) =
+let passed_on ~loc label (value : P.expression) =
match wrapped value with
| Some (Ok (Namespaced (Attr, v))) ->
Ok ("attr:" ^ js_name label, [%type: string], v)
@@ -484,12 +485,12 @@ let element map ~loc name args =
fall back on while hydrating, so it throws on an element only the browser
draws, where given a function it only calls it. *)
let drawn_as, args =
- List.partition (function Optional "as_", _ -> true | _ -> false) args
+ List.partition (function P.Optional "as_", _ -> true | _ -> false) args
in
- let prop (label, (value : expression)) =
+ let prop (label, (value : P.expression)) =
let loc = value.pexp_loc in
match label with
- | Labelled l when String.equal l spread ->
+ | P.Labelled l when String.equal l spread ->
Ok [%expr Solidtype.Jsx.spread [%e thunk ~loc (map value)]]
| Labelled l
when starts_with ~prefix:"data_" l && Option.is_none (wrapped value) ->
@@ -556,9 +557,11 @@ let element map ~loc name args =
let drawn ~given args =
let rest =
match
- ( List.find_opt (function Labelled "ref", _ -> true | _ -> false) args,
+ ( List.find_opt
+ (function P.Labelled "ref", _ -> true | _ -> false)
+ args,
List.find_opt
- (function Labelled l, _ -> String.equal l spread | _ -> false)
+ (function P.Labelled l, _ -> String.equal l spread | _ -> false)
args )
with
| Some (_, written), Some (_, given) -> Some (written, given)
@@ -571,7 +574,7 @@ let element map ~loc name args =
let rest = [%expr solidtype__rest ()] in
List.concat_map
(function
- | Labelled "ref", _ -> []
+ | P.Labelled "ref", _ -> []
| (Labelled l as label), _ when String.equal l spread ->
[
(label, rest);
@@ -622,6 +625,8 @@ let element map ~loc name args =
|]
[| Solidtype.Jsx.node [%e drawn ~given args] |]]
+let ghost loc = { loc with P.loc_ghost = true }
+
(* A component's element also applies the component's [Props.check] to its
props under [if false]: the compiler checks the application and Melange
drops it. A prop that can hold JSX is bound once and named in both, since a
@@ -629,16 +634,16 @@ let element map ~loc name args =
Vite plugin puts each one back where it is used. *)
let component map ~loc path args =
let bound label = "solidtype__" ^ label in
- let prop (label, (value : expression)) =
+ let prop (label, (value : P.expression)) =
let loc = value.pexp_loc in
match label with
- | Labelled l when String.equal l spread ->
+ | P.Labelled l when String.equal l spread ->
let x = B.evar ~loc (bound spread) in
Ok
( Some
( bound spread,
(Some [%type: (unit -> _[@u])], thunk ~loc (map value)) ),
- Some (Labelled spread, call ~loc x),
+ Some (P.Labelled spread, call ~loc x),
[%expr Solidtype.Jsx.spread [%e x]] )
| Optional l when Option.is_some (wrapped value) ->
let* js, t, v = passed_on ~loc l value in
@@ -672,7 +677,7 @@ let component map ~loc path args =
let+ value = optional ~loc l value in
let x = B.evar ~loc (bound l) in
( Some (bound l, (Some [%type: (unit -> _ option[@u])], map value)),
- Some (Optional l, [%expr Solidtype.Check.optional [%e x]]),
+ Some (P.Optional l, [%expr Solidtype.Check.optional [%e x]]),
[%expr
Solidtype.Jsx.d
[%e B.estring ~loc (js_name l)]
@@ -685,7 +690,7 @@ let component map ~loc path args =
| Literal ->
let value = js_string value in
( None,
- Some (Labelled label, [%expr Solidtype.Check.literal [%e value]]),
+ Some (P.Labelled label, [%expr Solidtype.Check.literal [%e value]]),
[%expr Solidtype.Jsx.s [%e name] [%e value]] )
| Element ->
( None,
@@ -720,9 +725,9 @@ let component map ~loc path args =
in
Ok
( Some (bound "children", (None, map (unmark f))),
- Some (Labelled "children", check),
+ Some (P.Labelled "children", check),
[ [%expr Solidtype.Jsx.render [%e x]] ] )
- | (first : expression) :: rest as written ->
+ | (first : P.expression) :: rest as written ->
(* A component that takes only a function refuses these children
where they are written, a function's name among them. *)
let loc =
@@ -730,14 +735,14 @@ let component map ~loc path args =
first.pexp_loc with
loc_end =
List.fold_left
- (fun _ (c : expression) -> c.pexp_loc.loc_end)
+ (fun _ (c : P.expression) -> c.pexp_loc.loc_end)
first.pexp_loc.loc_end rest;
}
in
Result.map
(fun cs ->
( None,
- Some (Labelled "children", [%expr Solidtype.Check.elements ()]),
+ Some (P.Labelled "children", [%expr Solidtype.Check.elements ()]),
cs ))
(all (List.map (child map) written))
in
@@ -765,6 +770,7 @@ let component map ~loc path args =
@ [ (Nolabel, [%expr ()]) ])
in
let make =
+ let loc = ghost loc in
[%expr
if false then [%e check];
Solidtype.Jsx.c
@@ -789,7 +795,7 @@ let component map ~loc path args =
in
B.pexp_fun ~loc Nolabel None pat body)
bindings make)
- (List.map (fun (_, (_, expr)) -> (Nolabel, expr)) bindings))
+ (List.map (fun (_, (_, expr)) -> (P.Nolabel, expr)) bindings))
(* A [Switch] whose only child is a [match]: each case becomes a
[Match], a case with variables a [Match.Keyed] given them, so the case's
@@ -797,13 +803,13 @@ let component map ~loc path args =
let with_last path name =
match path with
- | Ldot (p, _) -> Ldot (p, name)
+ | P.Ldot (p, _) -> P.Ldot (p, name)
| Lident _ | Lapply _ -> Lident name
-let variables (p : pattern) =
+let variables (p : P.pattern) =
let collect =
object
- inherit [string list] Ast_traverse.fold as super
+ inherit [string list] P.Ast_traverse.fold as super
method! pattern p acc =
match p.ppat_desc with
@@ -818,12 +824,12 @@ let jsx ~loc path args =
{
(B.pexp_apply ~loc
(B.pexp_ident ~loc { txt = Ldot (path, "createElement"); loc })
- (args @ [ (Nolabel, [%expr ()]) ]))
+ (args @ [ (P.Nolabel, [%expr ()]) ]))
with
pexp_attributes = [ attribute ~loc "JSX" ];
}
-let quiet ~loc warnings (e : expression) =
+let quiet ~loc warnings (e : P.expression) =
{
e with
pexp_attributes =
@@ -833,7 +839,7 @@ let quiet ~loc warnings (e : expression) =
}
let switch_cases path args =
- let of_match (e : expression) =
+ let of_match (e : P.expression) =
match e.pexp_desc with
| Pexp_match (scrutinee, cases) -> Some (scrutinee, cases)
| _ -> None
@@ -846,7 +852,7 @@ let switch_cases path args =
| None -> None
| Some (scrutinee, cases) ->
let match_path = with_last path "Match" in
- let case (c : case) =
+ let case (c : P.case) =
let loc = c.pc_lhs.ppat_loc in
let test yes no =
quiet ~loc "-11"
@@ -889,7 +895,7 @@ let switch_cases path args =
quiet ~loc "-26-27"
(B.pexp_match ~loc scrutinee
(List.map
- (fun (c : case) ->
+ (fun (c : P.case) ->
B.case ~lhs:c.pc_lhs ~guard:c.pc_guard ~rhs:[%expr ()])
cases))
in
@@ -901,7 +907,7 @@ let switch_cases path args =
Some (exhaustive, props @ [ (Labelled "children", children) ]))
| _ -> None
-let lower map (e : expression) args =
+let lower map (e : P.expression) args =
let loc = e.pexp_loc in
match e.pexp_desc with
| Pexp_apply ({ pexp_desc = Pexp_ident { txt = Lident name; _ }; _ }, _) ->
@@ -911,44 +917,46 @@ let lower map (e : expression) args =
_ ) -> (
match switch_cases path args with
| Some (exhaustive, args) ->
+ let made = component map ~loc path args in
+ let loc = ghost loc in
[%expr
if false then [%e exhaustive];
- [%e component map ~loc path args]]
+ [%e made]]
| None -> component map ~loc path args)
| _ -> error ~loc "a JSX tag is a lowercase element or a component module"
(* let%component: a component's props are its labelled parameters, each with
its type. *)
-type presence = Required | Optional | Default of expression
+type presence = Required | Optional | Default of P.expression
type prop = {
label : string;
var : string;
(** What the body names it: the label, or [given] of [?ref:(given : t)].
*)
- typ : core_type; (** Without the [option] of an optional prop. *)
+ typ : P.core_type; (** Without the [option] of an optional prop. *)
presence : presence;
arity : int; (** How many arguments a function prop takes; 0 for a value. *)
}
-let rec arity (t : core_type) =
+let rec arity (t : P.core_type) =
match t.ptyp_desc with
| Ptyp_arrow (Nolabel, _, rest) -> Result.map succ (arity rest)
| Ptyp_arrow (_, _, _) ->
Error (t.ptyp_loc, "a function prop's arguments are not labelled")
| _ -> Ok 0
-let rec type_vars (t : core_type) =
+let rec type_vars (t : P.core_type) =
match t.ptyp_desc with
| Ptyp_var v -> [ v ]
| Ptyp_arrow (_, a, b) -> type_vars a @ type_vars b
| Ptyp_constr (_, ts) | Ptyp_tuple ts -> List.concat_map type_vars ts
| _ -> []
-let prop_of (p : function_param) =
+let prop_of (p : P.function_param) =
let loc = p.pparam_loc in
- let prop label (var : string loc) typ presence =
+ let prop label (var : string P.loc) typ presence =
if String.equal label spread then
Error
( var.loc,
@@ -1002,7 +1010,7 @@ let prop_of (p : function_param) =
(* [loc] is the component's, where a parameter missing is reported. *)
let rec props_of ~loc = function
- | [ { pparam_desc = Pparam_val (Nolabel, None, p); _ } ] when is_unit p ->
+ | [ { P.pparam_desc = Pparam_val (Nolabel, None, p); _ } ] when is_unit p ->
Ok []
| p :: rest ->
let* p = prop_of p in
@@ -1051,7 +1059,7 @@ let props_module ~loc ~element ~drawn props =
B.type_declaration ~loc ~name:{ txt = "t"; loc }
~params:
(List.map
- (fun v -> (B.ptyp_var ~loc v, (NoVariance, NoInjectivity)))
+ (fun v -> (B.ptyp_var ~loc v, (P.NoVariance, P.NoInjectivity)))
vars)
~cstrs:[] ~kind:Ptype_abstract ~private_:Public ~manifest:None;
]
@@ -1096,7 +1104,7 @@ let props_module ~loc ~element ~drawn props =
}
in
match p.presence with
- | Required -> (Labelled p.label, typ)
+ | Required -> (P.Labelled p.label, typ)
| Optional | Default _ -> (Optional p.label, typ)
in
let type_ =
@@ -1290,18 +1298,18 @@ let value_read ~loc p =
[Solidtype.Solid]; a read through another alias calls the accessor, which
reads the same. A name the body binds again is its own. *)
let is_solid_get = function
- | Ldot ((Lident ("S" | "Solid") | Ldot (Lident "Solidtype", "Solid")), "get")
+ | P.Ldot ((Lident ("S" | "Solid") | Ldot (Lident "Solidtype", "Solid")), "get")
->
true
| _ -> false
-let rec inline_reads reads (e : expression) =
+let rec inline_reads reads (e : P.expression) =
let without names =
List.filter (fun (v, _) -> not (List.mem v names)) reads
in
let map =
object
- inherit Ast_traverse.map as super
+ inherit P.Ast_traverse.map as super
method! expression e =
match e.pexp_desc with
@@ -1315,19 +1323,21 @@ let rec inline_reads reads (e : expression) =
let (_ : _ Solidtype.Solid.accessor -> _) = [%e get] in
[%e List.assoc v reads loc]]
| Pexp_let (rec_flag, vbs, body) ->
- let bound = List.concat_map (fun vb -> variables vb.pvb_pat) vbs in
+ let bound =
+ List.concat_map (fun vb -> variables vb.P.pvb_pat) vbs
+ in
let inner = without bound in
let vbs =
List.map
(fun vb ->
{
vb with
- pvb_expr =
+ P.pvb_expr =
inline_reads
(match rec_flag with
| Recursive -> inner
| Nonrecursive -> reads)
- vb.pvb_expr;
+ vb.P.pvb_expr;
})
vbs
in
@@ -1338,7 +1348,7 @@ let rec inline_reads reads (e : expression) =
| Pexp_function (params, constraint_, body) ->
let bound =
List.concat_map
- (fun (p : function_param) ->
+ (fun (p : P.function_param) ->
match p.pparam_desc with
| Pparam_val (_, _, pat) -> variables pat
| Pparam_newtype _ -> [])
@@ -1347,7 +1357,7 @@ let rec inline_reads reads (e : expression) =
let inner = without bound in
let body =
match body with
- | Pfunction_body b -> Pfunction_body (inline_reads inner b)
+ | Pfunction_body b -> P.Pfunction_body (inline_reads inner b)
| Pfunction_cases (cs, l, a) ->
Pfunction_cases (List.map (case inner) cs, l, a)
in
@@ -1370,7 +1380,7 @@ let rec inline_reads reads (e : expression) =
in
if List.is_empty reads then e else map#expression e
-and case reads (c : case) =
+and case reads (c : P.case) =
let inner =
List.filter (fun (v, _) -> not (List.mem v (variables c.pc_lhs))) reads
in
@@ -1407,7 +1417,7 @@ let reader ~loc p =
let arg x = if of_unit then [%expr ()] else B.evar ~loc x in
let call f =
{
- (B.pexp_apply ~loc f (List.map (fun x -> (Nolabel, arg x)) xs)) with
+ (B.pexp_apply ~loc f (List.map (fun x -> (P.Nolabel, arg x)) xs)) with
pexp_attributes = [ attribute ~loc "u" ];
}
in
@@ -1430,7 +1440,7 @@ let reader ~loc p =
| None ->
[%e
B.pexp_apply ~loc default
- (List.map (fun x -> (Nolabel, arg x)) xs)]]
+ (List.map (fun x -> (P.Nolabel, arg x)) xs)]]
in
List.fold_right
(fun x body -> [%expr fun [%p B.pvar ~loc x] -> [%e body]])
@@ -1458,10 +1468,10 @@ let reader ~loc p =
(* [[@@element button]]: the element a component draws and passes the rest of
its props to, whose check its own then ends in: its [Solidtype.Html]
module, which the compiler finds or reports unbound. *)
-let element_of (vb : value_binding) =
+let element_of (vb : P.value_binding) =
match
List.filter
- (fun (a : attribute) -> String.equal a.attr_name.txt "element")
+ (fun (a : P.attribute) -> String.equal a.attr_name.txt "element")
vb.pvb_attributes
with
| [] -> Ok None
@@ -1482,7 +1492,8 @@ let element_of (vb : value_binding) =
] ->
Ok
(Some
- (Ldot (Ldot (Lident "Solidtype", "Html"), String.capitalize_ascii tag)))
+ (P.Ldot
+ (Ldot (Lident "Solidtype", "Html"), String.capitalize_ascii tag)))
| a :: _ ->
Error
( a.attr_loc,
@@ -1492,7 +1503,7 @@ let element_of (vb : value_binding) =
part draws, so it draws what [as_] draws in its place. *)
let draw_by_as =
object
- inherit Ast_traverse.map as super
+ inherit P.Ast_traverse.map as super
method! expression e =
let e = super#expression e in
@@ -1502,9 +1513,9 @@ let draw_by_as =
when is_jsx e
&& List.exists
(function
- | ( Labelled "props",
+ | ( P.Labelled "props",
{
- pexp_desc =
+ P.pexp_desc =
Pexp_apply
( {
pexp_desc =
@@ -1525,8 +1536,8 @@ let draw_by_as =
let args =
List.map
(function
- | Labelled "props", _ ->
- (Labelled "props", [%expr Props.drawn_others props])
+ | P.Labelled "props", _ ->
+ (P.Labelled "props", [%expr Props.drawn_others props])
| a -> a)
args
in
@@ -1539,7 +1550,7 @@ let draw_by_as =
| _ -> e
end
-let component_of (vb : value_binding) =
+let component_of (vb : P.value_binding) =
let loc = vb.pvb_loc in
match (vb.pvb_pat.ppat_desc, vb.pvb_expr.pexp_desc) with
| ( Ppat_var { txt = "make"; _ },
@@ -1621,7 +1632,7 @@ let component_of (vb : value_binding) =
names it, and the external is named beside it, so another [accessor] does
not compile. *)
let is_solid_accessor = function
- | Ldot
+ | P.Ldot
((Lident ("S" | "Solid") | Ldot (Lident "Solidtype", "Solid")), "accessor")
->
true
@@ -1629,7 +1640,7 @@ let is_solid_accessor = function
let mapper =
object (self)
- inherit Ast_traverse.map as super
+ inherit P.Ast_traverse.map as super
method! expression e =
match e.pexp_desc with
@@ -1655,14 +1666,14 @@ let mapper =
_ ) -> (
let drawn =
List.exists
- (fun (a : attribute) -> String.equal a.attr_name.txt "element")
+ (fun (a : P.attribute) -> String.equal a.attr_name.txt "element")
vb.pvb_attributes
&&
match vb.pvb_expr.pexp_desc with
| Pexp_function (params, _, _) ->
not
(List.exists
- (fun (p : function_param) ->
+ (fun (p : P.function_param) ->
match p.pparam_desc with
| Pparam_val ((Labelled "as_" | Optional "as_"), _, _) ->
true
@@ -1676,7 +1687,8 @@ let mapper =
match component_of { vb with pvb_expr = self#expression body } with
| Ok item -> item
| Error (loc, m) ->
- B.pstr_extension ~loc (Location.error_extensionf ~loc "%s" m) [])
+ B.pstr_extension ~loc (P.Location.error_extensionf ~loc "%s" m) []
+ )
| _ -> super#structure_item item
end
@@ -1686,7 +1698,7 @@ let internal = ref false
let unqualify =
object
- inherit Ast_traverse.map as super
+ inherit P.Ast_traverse.map as super
method! longident =
function
@@ -1695,8 +1707,8 @@ let unqualify =
end
let () =
- Driver.add_arg "-internal" (Arg.Set internal)
+ P.Driver.add_arg "-internal" (Arg.Set internal)
~doc:" lower JSX inside solidtype itself";
- Driver.register_transformation "solidtype" ~impl:(fun s ->
+ P.Driver.register_transformation "solidtype" ~impl:(fun s ->
let s = mapper#structure s in
if !internal then unqualify#structure s else s)
diff --git a/prds/heroui.md b/prds/heroui.md
index 013f4597..319d648c 100644
--- a/prds/heroui.md
+++ b/prds/heroui.md
@@ -264,8 +264,8 @@ on `generate/binding.ts`'s core, and every date port takes its values:
- **DateField, Calendar, RangeCalendar, DatePicker, DateRangePicker**,
group 7, are built on the same values and on the library's calendars, so
a calendar other than the Gregorian is theirs too.
-- **The wire** stays a `Js.Date.t`, an instant, as `MELANGE.md` and
- wiretype's codecs read one: `Types.ZonedDateTime.to_date` and
+- **The wire** stays a `Js.Date.t`, an instant, as wiretype's codecs read
+ one: `Types.ZonedDateTime.to_date` and
`from_date` with a zone cross between them, at the boundary.
The binding, as it landed: the four value classes are each a kind of one
diff --git a/solidtype.opam b/solidtype.opam
index fe18e282..4c32b29d 100644
--- a/solidtype.opam
+++ b/solidtype.opam
@@ -31,6 +31,7 @@ depends: [
"ocaml-lsp-server" {with-dev-setup & >= "1.25.0"}
"ocamlformat" {with-dev-setup & = "0.29.0"}
"ocamlformat-mlx" {with-dev-setup & = "0.29.0.1"}
+ "hypha-litany" {with-dev-setup & >= "1.2.2" & < "2.0.0"}
"odoc" {with-doc}
]
build: [
diff --git a/test/browser/flow_test.mlx b/test/browser/flow_test.mlx
index 77e57f96..f7ff50d9 100644
--- a/test/browser/flow_test.mlx
+++ b/test/browser/flow_test.mlx
@@ -59,7 +59,7 @@ module Greeting = struct
end
module Fails = struct
- let%component make () = if true then raise Broken else
"fine"
+ let%component make () = raise Broken
end
let () =
diff --git a/test/ppx/dune b/test/ppx/dune
index 12a98e66..3ffc0c2c 100644
--- a/test/ppx/dune
+++ b/test/ppx/dune
@@ -1,8 +1,9 @@
; What ppx_solidtype writes for each JSX form, from MLX's own parse: a change
; to the lowering is a diff here, taken with `dune promote`.
-(executable
- (name pp)
+(executables
+ (names pp ghost)
+ (modules pp ghost)
(libraries ppx_solidtype ppxlib))
(rule
@@ -19,3 +20,13 @@
(alias runtest)
(action
(diff lowered.expected lowered.ml)))
+
+(rule
+ (with-stdout-to
+ lowered.bin
+ (run ./pp.exe --impl %{dep:forms.ast} --dump-ast)))
+
+(rule
+ (alias runtest)
+ (action
+ (run ./ghost.exe %{dep:lowered.bin})))
diff --git a/test/ppx/ghost.ml b/test/ppx/ghost.ml
new file mode 100644
index 00000000..eed2bd80
--- /dev/null
+++ b/test/ppx/ghost.ml
@@ -0,0 +1,42 @@
+module P = Ppxlib
+
+let () =
+ match P.Ast_io.read_binary Sys.argv.(1) with
+ | Error e ->
+ prerr_endline e;
+ exit 2
+ | Ok bin -> (
+ match P.Ast_io.get_ast bin with
+ | Intf _ ->
+ prerr_endline "an interface, where the lowering is an implementation";
+ exit 2
+ | Impl structure -> (
+ let unmarked = ref [] in
+ let iter =
+ object
+ inherit P.Ast_traverse.iter as super
+
+ method! expression e =
+ (match e.pexp_desc with
+ | Pexp_ifthenelse
+ ( ({
+ pexp_desc =
+ Pexp_construct ({ txt = Lident "false"; _ }, None);
+ _;
+ } as condition),
+ _,
+ _ )
+ when not (e.pexp_loc.loc_ghost && condition.pexp_loc.loc_ghost)
+ ->
+ unmarked := e.pexp_loc :: !unmarked
+ | _ -> ());
+ super#expression e
+ end
+ in
+ iter#structure structure;
+ List.iter
+ (fun (loc : P.location) ->
+ Printf.printf "line %d: an if false not at a ghost location\n"
+ loc.loc_start.pos_lnum)
+ (List.rev !unmarked);
+ match !unmarked with [] -> () | _ :: _ -> exit 1))