ferrovue 0.3.0 → 0.5.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.
- package/README.md +225 -42
- package/dist/attrs.d.ts +3 -53
- package/dist/attrs.js +41 -469
- package/dist/calls.d.ts +4 -0
- package/dist/calls.js +221 -0
- package/dist/children.d.ts +16 -0
- package/dist/children.js +286 -0
- package/dist/classes.d.ts +13 -0
- package/dist/classes.js +176 -0
- package/dist/cli.js +31 -22
- package/dist/client.d.ts +35 -2
- package/dist/client.js +77 -14
- package/dist/compiler.d.ts +1 -1
- package/dist/compiler.js +31 -92
- package/dist/component.d.ts +3 -1
- package/dist/component.js +123 -104
- package/dist/constants.d.ts +42 -0
- package/dist/constants.js +292 -0
- package/dist/context.d.ts +29 -67
- package/dist/context.js +13 -38
- package/dist/diagnostics.d.ts +23 -0
- package/dist/diagnostics.js +30 -0
- package/dist/diff.d.ts +0 -3
- package/dist/diff.js +0 -9
- package/dist/emitter.d.ts +0 -8
- package/dist/emitter.js +0 -12
- package/dist/errors.d.ts +867 -0
- package/dist/errors.js +330 -0
- package/dist/expr.d.ts +1 -70
- package/dist/expr.js +142 -934
- package/dist/fallthrough.d.ts +9 -0
- package/dist/fallthrough.js +78 -0
- package/dist/fixture.d.ts +4 -10
- package/dist/fixture.js +38 -27
- package/dist/hydration.d.ts +15 -0
- package/dist/hydration.js +80 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/islands.d.ts +1 -0
- package/dist/islands.js +1 -0
- package/dist/link-router.d.ts +24 -0
- package/dist/link-router.js +36 -0
- package/dist/lists.d.ts +0 -11
- package/dist/lists.js +34 -60
- package/dist/loops.d.ts +3 -0
- package/dist/loops.js +168 -0
- package/dist/model.d.ts +46 -144
- package/dist/model.js +150 -18
- package/dist/narrowing.d.ts +27 -0
- package/dist/narrowing.js +157 -0
- package/dist/numbers.d.ts +8 -0
- package/dist/numbers.js +73 -0
- package/dist/parens.d.ts +0 -27
- package/dist/parens.js +0 -44
- package/dist/plugin.d.ts +84 -0
- package/dist/plugin.js +26 -0
- package/dist/plugins/client-only.d.ts +8 -0
- package/dist/plugins/client-only.js +107 -0
- package/dist/plugins/i18n.d.ts +23 -0
- package/dist/{i18n.js → plugins/i18n.js} +88 -31
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +10 -0
- package/dist/plugins/router-link.d.ts +8 -0
- package/dist/{router.js → plugins/router-link.js} +52 -91
- package/dist/plugins/router.d.ts +42 -0
- package/dist/plugins/router.js +256 -0
- package/dist/plugins/scoped.d.ts +12 -0
- package/dist/plugins/scoped.js +125 -0
- package/dist/plugins/shared-types.d.ts +2 -0
- package/dist/plugins/shared-types.js +7 -0
- package/dist/plugins/stores.d.ts +37 -0
- package/dist/plugins/stores.js +379 -0
- package/dist/plugins/teleport.d.ts +5 -0
- package/dist/plugins/teleport.js +55 -0
- package/dist/plugins/twins.d.ts +10 -0
- package/dist/plugins/twins.js +164 -0
- package/dist/routes.d.ts +10 -0
- package/dist/routes.js +6 -0
- package/dist/rust.d.ts +1 -7
- package/dist/rust.js +56 -174
- package/dist/script.d.ts +3 -6
- package/dist/script.js +127 -140
- package/dist/settle.d.ts +6 -0
- package/dist/settle.js +34 -0
- package/dist/slots.d.ts +13 -0
- package/dist/slots.js +160 -0
- package/dist/strings.d.ts +13 -0
- package/dist/strings.js +208 -0
- package/dist/styles.d.ts +14 -0
- package/dist/styles.js +181 -0
- package/dist/template.d.ts +1 -42
- package/dist/template.js +25 -749
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +4 -10
- package/dist/types.d.ts +2 -0
- package/dist/typescript.d.ts +2 -14
- package/dist/typescript.js +53 -59
- package/dist/vite.d.ts +2 -1
- package/dist/vite.js +11 -32
- package/package.json +15 -6
- package/dist/i18n.d.ts +0 -27
- package/dist/router.d.ts +0 -17
- package/dist/scoped.d.ts +0 -24
- package/dist/scoped.js +0 -177
- package/dist/stores.d.ts +0 -6
- package/dist/stores.js +0 -229
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { blankComponent, camelize, fail, GenError, snake } from "../model.js";
|
|
2
|
+
import { CONFIG_FILE, tyOfName } from "../context.js";
|
|
3
|
+
import { coerce, expr, holdsNothing } from "../expr.js";
|
|
4
|
+
import { bare, strArg } from "../parens.js";
|
|
5
|
+
import { header } from "../rust.js";
|
|
6
|
+
import { callWith, fieldInit, renderChild } from "../children.js";
|
|
7
|
+
import { runOf, scopeOf } from "../plugin.js";
|
|
8
|
+
function hyphenate(name) {
|
|
9
|
+
return name.replace(/\B([A-Z])/g, "-$1").toLowerCase();
|
|
10
|
+
}
|
|
11
|
+
function readTwins(specs) {
|
|
12
|
+
const twins = new Map();
|
|
13
|
+
for (const [name, spec] of Object.entries(specs)) {
|
|
14
|
+
const where = `\`twins.${name}\` in ${CONFIG_FILE}`;
|
|
15
|
+
if (!/^[A-Z][A-Za-z0-9]*$/.test(name))
|
|
16
|
+
throw new GenError("FV1109", `${where}: a twin is named as its component is, in PascalCase`, { file: CONFIG_FILE });
|
|
17
|
+
if (typeof spec?.rust !== "string" || !/^[A-Za-z_]\w*(::[A-Za-z_]\w*)+$/.test(spec.rust)) {
|
|
18
|
+
throw new GenError("FV1110", `${where} needs \`rust\`, the path of the function that renders it, as \`crate::ui::v_btn\``, { file: CONFIG_FILE });
|
|
19
|
+
}
|
|
20
|
+
const comp = blankComponent(name, "twins", CONFIG_FILE);
|
|
21
|
+
for (const [js, type] of Object.entries(spec.props ?? {})) {
|
|
22
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(js))
|
|
23
|
+
throw new GenError("FV1111", `${where}: the prop \`${js}\` is named in camelCase`, { file: CONFIG_FILE });
|
|
24
|
+
comp.props.fields.push({ js, rust: snake(js), ty: tyOfName(type) });
|
|
25
|
+
}
|
|
26
|
+
for (const slot of spec.slots ?? []) {
|
|
27
|
+
if (!/^[A-Za-z_][\w-]*$/.test(slot))
|
|
28
|
+
throw new GenError("FV1112", `${where}: the slot \`${slot}\` is not a plain name`, { file: CONFIG_FILE });
|
|
29
|
+
comp.slotNames.push(slot);
|
|
30
|
+
}
|
|
31
|
+
comp.inherits = true;
|
|
32
|
+
comp.attrNames = new Set(["class", "style"]);
|
|
33
|
+
twins.set(name, { spec, comp });
|
|
34
|
+
}
|
|
35
|
+
return twins;
|
|
36
|
+
}
|
|
37
|
+
function twinNamed(name) {
|
|
38
|
+
const twins = runOf(twinsPlugin);
|
|
39
|
+
return twins.get(name) ?? twins.get(camelize(name).replace(/^\w/, (c) => c.toUpperCase()));
|
|
40
|
+
}
|
|
41
|
+
function init(s, f, node, n, owner) {
|
|
42
|
+
if (!node) {
|
|
43
|
+
if (f.ty.k === "opt")
|
|
44
|
+
return `${f.rust}: None`;
|
|
45
|
+
if (f.ty.k === "bool")
|
|
46
|
+
return `${f.rust}: false`;
|
|
47
|
+
return fail(s.comp, "FV0506", `${owner} requires \`${f.js}\``, n);
|
|
48
|
+
}
|
|
49
|
+
if (f.ty.k === "bool" && node.type === "StringLiteral" && (node.value === "" || node.value === hyphenate(f.js)))
|
|
50
|
+
return `${f.rust}: true`;
|
|
51
|
+
const v = expr(s, node);
|
|
52
|
+
holdsNothing(s.comp, v, f.ty, node, `<${owner}>'s prop \`${f.js}\``);
|
|
53
|
+
const code = bare(coerce(s.comp, v, f.ty, node));
|
|
54
|
+
return fieldInit(f.rust, f.ty.k === "str" ? strArg(code) : code);
|
|
55
|
+
}
|
|
56
|
+
function callOf(twin) {
|
|
57
|
+
const name = twin.comp.name;
|
|
58
|
+
return {
|
|
59
|
+
comp: twin.comp,
|
|
60
|
+
init: (s, f, node, n) => init(s, f, node, n, name),
|
|
61
|
+
call(s, e, inits, slots, attrs) {
|
|
62
|
+
const props = `&super::twins::${name}Props { ${inits.join(", ")} }`.replace("{ }", "{}");
|
|
63
|
+
callWith(s, e, twin.comp, "super::twins", `${twin.spec.rust}(out, ${props}`, `super::twins::${name}Slots`, `, ${attrs}`, slots, true);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function rustTy(ty) {
|
|
68
|
+
switch (ty.k) {
|
|
69
|
+
case "str":
|
|
70
|
+
return "&'a str";
|
|
71
|
+
case "int":
|
|
72
|
+
return "i64";
|
|
73
|
+
case "float":
|
|
74
|
+
return "f64";
|
|
75
|
+
case "bool":
|
|
76
|
+
return "bool";
|
|
77
|
+
case "opt":
|
|
78
|
+
return `Option<${rustTy(ty.of)}>`;
|
|
79
|
+
default:
|
|
80
|
+
throw new GenError("FV1509", `no Rust type for a twin's prop of type ${JSON.stringify(ty)}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function twinSource({ spec, comp }) {
|
|
84
|
+
const name = comp.name;
|
|
85
|
+
const life = comp.props.fields.some((f) => rustTy(f.ty).includes("'a")) ? "<'a>" : "";
|
|
86
|
+
const fields = comp.props.fields.map((f) => ` pub ${f.rust}: ${rustTy(f.ty)},\n`).join("");
|
|
87
|
+
const props = `/// The props a template gives \`<${name}>\`.
|
|
88
|
+
#[derive(Debug, Clone, Copy)]
|
|
89
|
+
pub struct ${name}Props${life} {
|
|
90
|
+
${fields}}
|
|
91
|
+
`;
|
|
92
|
+
const slots = comp.slotNames.length
|
|
93
|
+
? `
|
|
94
|
+
/// What a template puts in \`<${name}>\`'s slots.
|
|
95
|
+
#[derive(Clone, Copy, Default)]
|
|
96
|
+
pub struct ${name}Slots<'s> {
|
|
97
|
+
${comp.slotNames.map((slot) => ` /// \`#${slot}\`\n pub ${snake(slot)}: Option<fv::Slot<'s>>,\n`).join("")}}
|
|
98
|
+
`
|
|
99
|
+
: "";
|
|
100
|
+
const params = ["&mut String", `&${name}Props${life ? "<'_>" : ""}`, ...(comp.slotNames.length ? [`${name}Slots<'_>`] : []), "&fv::Attrs<'_>"];
|
|
101
|
+
return `${props}${slots}
|
|
102
|
+
/// How generated code calls the twin of \`<${name}>\`: with the buffer, the props,
|
|
103
|
+
/// ${comp.slotNames.length ? "the slots, " : ""}and the attributes and scope ids its root takes.
|
|
104
|
+
pub type ${name}Render = fn(${params.join(", ")});
|
|
105
|
+
|
|
106
|
+
const _: ${name}Render = ${spec.rust};
|
|
107
|
+
`;
|
|
108
|
+
}
|
|
109
|
+
export const twinsPlugin = {
|
|
110
|
+
name: "twins",
|
|
111
|
+
configure: (config) => readTwins(config.twins ?? {}),
|
|
112
|
+
analyse(read) {
|
|
113
|
+
for (const r of read) {
|
|
114
|
+
if (runOf(twinsPlugin).has(r.comp.name))
|
|
115
|
+
throw new GenError("FV1510", `\`twins.${r.comp.name}\` in ${CONFIG_FILE} names ${r.comp.file}, which ferrovue compiles: a twin renders a component it does not`, { file: CONFIG_FILE });
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
scope: () => new Map(),
|
|
119
|
+
scriptImport(s, st) {
|
|
120
|
+
for (const sp of st.specifiers) {
|
|
121
|
+
const name = sp.type === "ImportSpecifier" ? (sp.imported.name ?? sp.imported.value) : sp.type === "ImportDefaultSpecifier" ? sp.local.name : null;
|
|
122
|
+
const twin = name === null ? undefined : runOf(twinsPlugin).get(name);
|
|
123
|
+
if (twin)
|
|
124
|
+
scopeOf(twinsPlugin, s).set(sp.local.name, twin);
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
},
|
|
128
|
+
resolveComponent(s, local, name) {
|
|
129
|
+
const twin = twinNamed(name);
|
|
130
|
+
if (twin)
|
|
131
|
+
scopeOf(twinsPlugin, s).set(local, twin);
|
|
132
|
+
return twin !== undefined;
|
|
133
|
+
},
|
|
134
|
+
component(s, e, n) {
|
|
135
|
+
const target = n.arguments[0];
|
|
136
|
+
const local = target.type === "Identifier" ? target.name : target.type === "MemberExpression" && target.object.name === "$setup" ? (target.computed ? target.property.value : target.property.name) : undefined;
|
|
137
|
+
if (local === undefined)
|
|
138
|
+
return false;
|
|
139
|
+
const file = s.children.get(local);
|
|
140
|
+
const twin = scopeOf(twinsPlugin, s).get(local) ?? (file !== undefined && !s.components.has(file) ? runOf(twinsPlugin).get(file) : undefined);
|
|
141
|
+
if (!twin)
|
|
142
|
+
return false;
|
|
143
|
+
renderChild(s, e, n, callOf(twin));
|
|
144
|
+
return true;
|
|
145
|
+
},
|
|
146
|
+
modules() {
|
|
147
|
+
const twins = [...runOf(twinsPlugin).values()];
|
|
148
|
+
if (!twins.length)
|
|
149
|
+
return [];
|
|
150
|
+
return [
|
|
151
|
+
[
|
|
152
|
+
"twins.rs",
|
|
153
|
+
`${header(CONFIG_FILE, "`twins` in it")}
|
|
154
|
+
//! The props and slots of the components rendered by Rust functions of the project's, its twins,
|
|
155
|
+
//! and the signature each function is held to. ferrovue does not check that a twin writes what Vue
|
|
156
|
+
//! writes: render the parents that use it with Vue in the project's own fixtures to prove it.
|
|
157
|
+
|
|
158
|
+
use ferrovue as fv;
|
|
159
|
+
|
|
160
|
+
${twins.map(twinSource).join("\n")}`,
|
|
161
|
+
],
|
|
162
|
+
];
|
|
163
|
+
},
|
|
164
|
+
};
|
package/dist/routes.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Component } from "vue";
|
|
2
|
+
import type { RouteRecordRaw } from "vue-router";
|
|
3
|
+
/** A route as a routes file lists it: a path, or a path and a name. */
|
|
4
|
+
export type RouteEntry = string | {
|
|
5
|
+
path: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
children?: RouteEntry[];
|
|
8
|
+
};
|
|
9
|
+
/** Route records for vue-router, every route (nested ones too) given the same view. */
|
|
10
|
+
export declare function routeRecords(routes: RouteEntry[], View: Component): RouteRecordRaw[];
|
package/dist/routes.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Route records for vue-router, every route (nested ones too) given the same view. */
|
|
2
|
+
export function routeRecords(routes, View) {
|
|
3
|
+
return routes.map((r) => typeof r === "string"
|
|
4
|
+
? { path: r, component: View }
|
|
5
|
+
: { path: r.path, component: View, ...(r.name ? { name: r.name } : {}), ...(r.children ? { children: routeRecords(r.children, View) } : {}) });
|
|
6
|
+
}
|
package/dist/rust.d.ts
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { type Component, type N, type Struct, type Ty } from "./model.ts";
|
|
2
|
-
import { type RouteDef } from "./context.ts";
|
|
3
2
|
export declare function needsLifetime(ty: Ty, comp: Component, seen?: Set<string>): boolean;
|
|
4
3
|
export declare function structLifetime(st: Struct, comp: Component): boolean;
|
|
5
4
|
export declare function rustTy(ty: Ty, comp: Component): string;
|
|
6
5
|
export declare function structSource(st: Struct, comp: Component, doc: string): string;
|
|
7
6
|
export declare function header(source: string, edit?: string): string;
|
|
8
|
-
/** Rust expressions summing the lengths of the strings a value of type `ty` at `place` holds. */
|
|
9
7
|
export declare function textLen(comp: Component, place: string, ty: Ty, seen?: Set<string>): string[];
|
|
10
|
-
/** Whether the component gets an `island()`: it renders from its props alone, which `data-props` is
|
|
11
|
-
* all the client gets to mount it with. */
|
|
12
8
|
export declare function isIsland(comp: Component): boolean;
|
|
13
9
|
export declare function componentSource(comp: Component, ast: N[], ssr: string, components: Map<string, Component>): string;
|
|
14
|
-
export declare function modSource(comps: Component[]): string;
|
|
15
|
-
export declare function storesSource(dir: string): string;
|
|
10
|
+
export declare function modSource(comps: Component[], modules: string[]): string;
|
|
16
11
|
export declare function typesSource(): string;
|
|
17
|
-
export declare function routesSource(routes: RouteDef[], file: string): string;
|