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.
Files changed (106) hide show
  1. package/README.md +225 -42
  2. package/dist/attrs.d.ts +3 -53
  3. package/dist/attrs.js +41 -469
  4. package/dist/calls.d.ts +4 -0
  5. package/dist/calls.js +221 -0
  6. package/dist/children.d.ts +16 -0
  7. package/dist/children.js +286 -0
  8. package/dist/classes.d.ts +13 -0
  9. package/dist/classes.js +176 -0
  10. package/dist/cli.js +31 -22
  11. package/dist/client.d.ts +35 -2
  12. package/dist/client.js +77 -14
  13. package/dist/compiler.d.ts +1 -1
  14. package/dist/compiler.js +31 -92
  15. package/dist/component.d.ts +3 -1
  16. package/dist/component.js +123 -104
  17. package/dist/constants.d.ts +42 -0
  18. package/dist/constants.js +292 -0
  19. package/dist/context.d.ts +29 -67
  20. package/dist/context.js +13 -38
  21. package/dist/diagnostics.d.ts +23 -0
  22. package/dist/diagnostics.js +30 -0
  23. package/dist/diff.d.ts +0 -3
  24. package/dist/diff.js +0 -9
  25. package/dist/emitter.d.ts +0 -8
  26. package/dist/emitter.js +0 -12
  27. package/dist/errors.d.ts +867 -0
  28. package/dist/errors.js +330 -0
  29. package/dist/expr.d.ts +1 -70
  30. package/dist/expr.js +142 -934
  31. package/dist/fallthrough.d.ts +9 -0
  32. package/dist/fallthrough.js +78 -0
  33. package/dist/fixture.d.ts +4 -10
  34. package/dist/fixture.js +38 -27
  35. package/dist/hydration.d.ts +15 -0
  36. package/dist/hydration.js +80 -0
  37. package/dist/index.d.ts +3 -0
  38. package/dist/index.js +2 -0
  39. package/dist/islands.d.ts +1 -0
  40. package/dist/islands.js +1 -0
  41. package/dist/link-router.d.ts +24 -0
  42. package/dist/link-router.js +36 -0
  43. package/dist/lists.d.ts +0 -11
  44. package/dist/lists.js +34 -60
  45. package/dist/loops.d.ts +3 -0
  46. package/dist/loops.js +168 -0
  47. package/dist/model.d.ts +46 -144
  48. package/dist/model.js +150 -18
  49. package/dist/narrowing.d.ts +27 -0
  50. package/dist/narrowing.js +157 -0
  51. package/dist/numbers.d.ts +8 -0
  52. package/dist/numbers.js +73 -0
  53. package/dist/parens.d.ts +0 -27
  54. package/dist/parens.js +0 -44
  55. package/dist/plugin.d.ts +84 -0
  56. package/dist/plugin.js +26 -0
  57. package/dist/plugins/client-only.d.ts +8 -0
  58. package/dist/plugins/client-only.js +107 -0
  59. package/dist/plugins/i18n.d.ts +23 -0
  60. package/dist/{i18n.js → plugins/i18n.js} +88 -31
  61. package/dist/plugins/index.d.ts +2 -0
  62. package/dist/plugins/index.js +10 -0
  63. package/dist/plugins/router-link.d.ts +8 -0
  64. package/dist/{router.js → plugins/router-link.js} +52 -91
  65. package/dist/plugins/router.d.ts +42 -0
  66. package/dist/plugins/router.js +256 -0
  67. package/dist/plugins/scoped.d.ts +12 -0
  68. package/dist/plugins/scoped.js +125 -0
  69. package/dist/plugins/shared-types.d.ts +2 -0
  70. package/dist/plugins/shared-types.js +7 -0
  71. package/dist/plugins/stores.d.ts +37 -0
  72. package/dist/plugins/stores.js +379 -0
  73. package/dist/plugins/teleport.d.ts +5 -0
  74. package/dist/plugins/teleport.js +55 -0
  75. package/dist/plugins/twins.d.ts +10 -0
  76. package/dist/plugins/twins.js +164 -0
  77. package/dist/routes.d.ts +10 -0
  78. package/dist/routes.js +6 -0
  79. package/dist/rust.d.ts +1 -7
  80. package/dist/rust.js +56 -174
  81. package/dist/script.d.ts +3 -6
  82. package/dist/script.js +127 -140
  83. package/dist/settle.d.ts +6 -0
  84. package/dist/settle.js +34 -0
  85. package/dist/slots.d.ts +13 -0
  86. package/dist/slots.js +160 -0
  87. package/dist/strings.d.ts +13 -0
  88. package/dist/strings.js +208 -0
  89. package/dist/styles.d.ts +14 -0
  90. package/dist/styles.js +181 -0
  91. package/dist/template.d.ts +1 -42
  92. package/dist/template.js +25 -749
  93. package/dist/testing.d.ts +2 -0
  94. package/dist/testing.js +4 -10
  95. package/dist/types.d.ts +2 -0
  96. package/dist/typescript.d.ts +2 -14
  97. package/dist/typescript.js +53 -59
  98. package/dist/vite.d.ts +2 -1
  99. package/dist/vite.js +11 -32
  100. package/package.json +15 -6
  101. package/dist/i18n.d.ts +0 -27
  102. package/dist/router.d.ts +0 -17
  103. package/dist/scoped.d.ts +0 -24
  104. package/dist/scoped.js +0 -177
  105. package/dist/stores.d.ts +0 -6
  106. package/dist/stores.js +0 -229
@@ -0,0 +1,208 @@
1
+ import { BOOL, fail, INT, opt, rustStr, STR } from "./model.js";
2
+ import { atom, bare, binary, condition, enclosed, receiver, strArg } from "./parens.js";
3
+ import { computed } from "./lists.js";
4
+ import { expr } from "./expr.js";
5
+ import { known } from "./narrowing.js";
6
+ import { asF64, isNumber } from "./numbers.js";
7
+ export function lonely(what) {
8
+ return `${what} with a string that may hold half of a surrogate pair (cut by \`slice\`, \`substring\`, \`at\`, \`charAt\`, \`split("")\` and the like): JavaScript keeps the half, which can match, order or join with another where ferrovue holds U+FFFD`;
9
+ }
10
+ export function meet(comp, a, b, what, n, how) {
11
+ const literal = (v) => v.code.startsWith('"');
12
+ const fffd = (v) => literal(v) && v.code.includes("\u{FFFD}");
13
+ const low = (v) => literal(v) && !/[\u{D800}-\u{10FFFF}]/u.test(v.code);
14
+ const refused = how === "order" ? (a.lone && !low(b)) || (b.lone && !low(a))
15
+ : how === "join" ? a.lone && b.lone
16
+ : how === "search" ? b.lone || (a.lone && fffd(b))
17
+ : (a.lone && b.lone) || (a.lone && fffd(b)) || (b.lone && fffd(a));
18
+ if (refused)
19
+ fail(comp, "FV0706", lonely(what), n);
20
+ }
21
+ export function loneOf(...vs) {
22
+ return vs.some((v) => v?.lone) ? { lone: true } : {};
23
+ }
24
+ function nonEmptyLiteral(v) {
25
+ return /^"[^"]/.test(v.code);
26
+ }
27
+ export function isTemporary(v) {
28
+ if (v.ty.k !== "str")
29
+ return false;
30
+ const trimmed = /^fv::js_trim(?:_start|_end)?\(([^]*)\)$/.exec(v.code);
31
+ if (trimmed?.[1] !== undefined)
32
+ return isTemporary({ code: trimmed[1].replace(/^&(?!\*)/, "&*"), ty: v.ty });
33
+ return /^&\*(?!\**[\w.]+$)/.test(v.code) || /\.unwrap_or\(&\*(?!\**[\w.]+\)$)/.test(v.code);
34
+ }
35
+ export function asCow(v) {
36
+ if (!isTemporary(v))
37
+ return `std::borrow::Cow::<str>::Borrowed(${bare(v.code)})`;
38
+ const built = /^&\*(.*)$/s.exec(v.code)?.[1];
39
+ if (built === undefined)
40
+ return `std::borrow::Cow::<str>::Owned(${atom(v.code)}.to_owned())`;
41
+ if (enclosed(built))
42
+ return bare(built);
43
+ if (yieldsCow(built))
44
+ return built.startsWith("fv::") ? `std::borrow::Cow::<str>::Owned(${built}.into_owned())` : bare(built);
45
+ if (/^fv::js_(?:char_at|trim|trim_start|trim_end)\(/.test(built))
46
+ return `std::borrow::Cow::<str>::Owned(${built}.to_owned())`;
47
+ return `std::borrow::Cow::<str>::Owned(${built})`;
48
+ }
49
+ export function yieldsCow(code) {
50
+ const routine = /^fv::js_(?:slice|substring|replace|replace_all|pad_start|pad_end)(?=\()/.exec(code);
51
+ if (routine !== null)
52
+ return enclosed(code.slice(routine[0].length));
53
+ const fallback = code.lastIndexOf(".unwrap_or(std::borrow::Cow::<str>::");
54
+ return fallback >= 0 && enclosed(code.slice(fallback + ".unwrap_or".length));
55
+ }
56
+ export function unquote(literal) {
57
+ const escapes = { n: "\n", r: "\r", t: "\t" };
58
+ return literal.slice(1, -1).replace(/\\(?:u\{([0-9a-f]+)\}|(.))/g, (_, hex, c) => (hex ? String.fromCodePoint(parseInt(hex, 16)) : (escapes[c] ?? c)));
59
+ }
60
+ export function stringsEqual(a, b) {
61
+ if (known(a) !== undefined && known(b) !== undefined)
62
+ return String(unquote(a.code) === unquote(b.code));
63
+ if (a.code === '""' || b.code === '""')
64
+ return `${receiver(a.code === '""' ? b.code : a.code)}.is_empty()`;
65
+ return binary(a.code, "==", b.code);
66
+ }
67
+ export function formatted(comp, parts, n, what) {
68
+ let fmt = "";
69
+ const args = [];
70
+ let before;
71
+ const lone = loneOf(...parts.map((p) => (typeof p === "string" ? undefined : p)));
72
+ for (const part of parts) {
73
+ if (typeof part === "string" || (part.ty.k === "str" && known(part) !== undefined)) {
74
+ const text = typeof part === "string" ? part : unquote(part.code);
75
+ if (text !== "")
76
+ before = undefined;
77
+ fmt += text.replace(/[{}]/g, (c) => c + c);
78
+ continue;
79
+ }
80
+ if (before)
81
+ meet(comp, before, part, what, n, "join");
82
+ before = part;
83
+ if (part.format) {
84
+ fmt += part.format.text;
85
+ args.push(...part.format.args);
86
+ continue;
87
+ }
88
+ if (part.ty.k === "str")
89
+ args.push(receiver(part.code).replace(/^(fv::Js\(.*\))\.to_string\(\)$/s, "$1"));
90
+ else if (isNumber(part.ty))
91
+ args.push(`fv::Js(${bare(part.code)})`);
92
+ else if (part.ty.k === "bool")
93
+ args.push(`if ${condition(part.code)} { "true" } else { "false" }`);
94
+ else
95
+ fail(comp, "FV0708", "a template literal interpolates strings, numbers and booleans that are present", n);
96
+ fmt += "{}";
97
+ }
98
+ if (!args.length)
99
+ return { code: rustStr(fmt.replace(/\{\{|\}\}/g, (c) => c[0])), ty: STR };
100
+ const one = parts.filter((p) => (typeof p === "string" ? p !== "" : p.code !== '""'));
101
+ if (fmt === "{}" && one.length === 1 && typeof one[0] !== "string" && one[0].ty.k === "str")
102
+ return one[0];
103
+ return { code: `&*format!(${rustStr(fmt)}, ${args.join(", ")})`, ty: STR, format: { text: fmt, args }, ...lone };
104
+ }
105
+ export function stringMethod(s, target, method, args, n) {
106
+ const comp = s.comp;
107
+ const t = strArg(target.code);
108
+ const arity = (least, most) => {
109
+ if (args.length < least || args.length > most) {
110
+ fail(comp, "FV0709", `\`.${method}()\` takes ${least === most ? least : `${least} to ${most}`} argument${most === 1 ? "" : "s"} here`, n);
111
+ }
112
+ };
113
+ const str = (i) => {
114
+ if (args[i]?.type === "RegExpLiteral")
115
+ fail(comp, "FV0710", `\`.${method}()\` with a regular expression, which the server does not run: give it a string`, args[i]);
116
+ const v = expr(s, args[i]);
117
+ if (v.ty.k !== "str")
118
+ fail(comp, "FV0711", `\`.${method}()\` takes a string that is present`, args[i]);
119
+ return v;
120
+ };
121
+ const num = (i, fallback) => {
122
+ if (args[i] === undefined)
123
+ return fallback;
124
+ const v = expr(s, args[i]);
125
+ if (v.ty.k === "undef")
126
+ return fallback;
127
+ if (!isNumber(v.ty))
128
+ fail(comp, "FV0712", `\`.${method}()\` takes a number that is present`, args[i]);
129
+ return asF64(v);
130
+ };
131
+ const cut = { lone: true };
132
+ switch (method) {
133
+ case "includes":
134
+ case "startsWith":
135
+ case "endsWith": {
136
+ arity(1, 1);
137
+ const x = str(0);
138
+ meet(comp, target, x, `\`.${method}()\``, n, "search");
139
+ const rust = { includes: "contains", startsWith: "starts_with", endsWith: "ends_with" }[method];
140
+ return { code: `${receiver(target.code)}.${rust}(${bare(x.code)})`, ty: BOOL };
141
+ }
142
+ case "indexOf":
143
+ case "lastIndexOf": {
144
+ arity(1, 1);
145
+ const x = str(0);
146
+ meet(comp, target, x, `\`.${method}()\``, n, "search");
147
+ return { code: `fv::js_${method === "indexOf" ? "index_of" : "last_index_of"}(${t}, ${strArg(x.code)})`, ty: INT };
148
+ }
149
+ case "slice":
150
+ case "substring": {
151
+ arity(0, 2);
152
+ const end = num(1, "");
153
+ return { code: `&*fv::js_${method}(${t}, ${num(0, "0.0")}, ${end ? `Some(${end})` : "None"})`, ty: STR, ...cut };
154
+ }
155
+ case "at": {
156
+ arity(1, 1);
157
+ const at = `fv::js_at(${t}, ${num(0, "0.0")})`;
158
+ if (!isTemporary(target))
159
+ return { code: at, ty: opt(STR), ...cut };
160
+ const held = `${at}.map(|v| std::borrow::Cow::<str>::Owned(v.to_owned()))`;
161
+ return { code: `${atom(held)}.as_deref()`, ty: opt(STR), held, ...cut };
162
+ }
163
+ case "charAt":
164
+ arity(0, 1);
165
+ return { code: `${isTemporary(target) ? "&*" : ""}fv::js_char_at(${t}, ${num(0, "0.0")})`, ty: STR, ...cut };
166
+ case "split": {
167
+ arity(1, 1);
168
+ const sep = str(0);
169
+ meet(comp, target, sep, "`.split()`", n, "search");
170
+ return computed(`fv::js_split(${t}, ${strArg(sep.code)}).into_iter()`, STR, target.lone || !nonEmptyLiteral(sep));
171
+ }
172
+ case "replace":
173
+ case "replaceAll": {
174
+ arity(2, 2);
175
+ if (args[1].type === "ArrowFunctionExpression" || args[1].type === "FunctionExpression") {
176
+ fail(comp, "FV0713", `\`.${method}()\` with a function, which the server does not run: give it a string`, args[1]);
177
+ }
178
+ const [pattern, replacement] = [str(0), str(1)];
179
+ meet(comp, target, pattern, `\`.${method}()\``, n, "search");
180
+ meet(comp, target, replacement, `\`.${method}()\``, n, "join");
181
+ const lone = target.lone || replacement.lone || (method === "replaceAll" && !nonEmptyLiteral(pattern));
182
+ return { code: `&*fv::js_${method === "replace" ? "replace" : "replace_all"}(${t}, ${strArg(pattern.code)}, ${strArg(replacement.code)})`, ty: STR, ...(lone ? cut : {}) };
183
+ }
184
+ case "padStart":
185
+ case "padEnd": {
186
+ arity(1, 2);
187
+ const fill = args.length > 1 ? str(1) : { code: '" "', ty: STR };
188
+ const whole = fill.code.startsWith('"') && !/[\u{10000}-\u{10FFFF}]/u.test(fill.code);
189
+ if (fill.lone || (method === "padStart" && target.lone && !whole))
190
+ fail(comp, "FV0706", lonely(`\`.${method}()\``), n);
191
+ return { code: `&*fv::js_${method === "padStart" ? "pad_start" : "pad_end"}(${t}, ${num(0, "0.0")}, ${strArg(fill.code)})`, ty: STR, ...(target.lone || !whole ? cut : {}) };
192
+ }
193
+ case "repeat": {
194
+ arity(1, 1);
195
+ const c = args[0];
196
+ if ((c.type === "UnaryExpression" && c.operator === "-" && c.argument.type === "NumericLiteral" && c.argument.value > 0) || (c.type === "Identifier" && c.name === "Infinity")) {
197
+ fail(comp, "FV0714", "`.repeat()` with a negative or infinite count, which throws a `RangeError`", c);
198
+ }
199
+ if (target.lone)
200
+ fail(comp, "FV0706", lonely("`.repeat()`"), n);
201
+ return { code: `&*fv::js_repeat(${t}, ${num(0, "0.0")})`, ty: STR };
202
+ }
203
+ case "toLocaleUpperCase":
204
+ case "toLocaleLowerCase":
205
+ return fail(comp, "FV0715", `\`.${method}()\` maps case by the locale the server runs in, which the browser need not share: use \`.${method.replace("Locale", "")}()\``, n);
206
+ }
207
+ return null;
208
+ }
@@ -0,0 +1,14 @@
1
+ import { type N, type Scope } from "./model.ts";
2
+ import { Emitter } from "./emitter.ts";
3
+ export declare function mergedStyle(s: Scope, e: Emitter, n: N): void;
4
+ export declare function styleAttr(s: Scope, n: N): string;
5
+ export interface StyleItem {
6
+ cond: string | null;
7
+ entries: {
8
+ key: string;
9
+ css: string;
10
+ value: N;
11
+ }[];
12
+ }
13
+ export declare function styleItems(s: Scope, n: N, when: string | null): StyleItem[];
14
+ export declare function renderStyle(s: Scope, e: Emitter, n: N): void;
package/dist/styles.js ADDED
@@ -0,0 +1,181 @@
1
+ import { escapeHtml, hyphenate, parseStringStyle } from "@vue/shared";
2
+ import { fail, nothing, rustStr } from "./model.js";
3
+ import { expr } from "./expr.js";
4
+ import { cond } from "./narrowing.js";
5
+ import { condition, logical, not, strArg } from "./parens.js";
6
+ import { Emitter } from "./emitter.js";
7
+ import { display, valueAttr } from "./attrs.js";
8
+ export function mergedStyle(s, e, n) {
9
+ if (n.type === "StringLiteral") {
10
+ renderStyle(s, e, { type: "ArrayExpression", elements: [n] });
11
+ return;
12
+ }
13
+ if (n.fvMerged || ["ObjectExpression", "ArrayExpression", "ConditionalExpression", "LogicalExpression", "NullLiteral"].includes(n.type)) {
14
+ renderStyle(s, e, n);
15
+ return;
16
+ }
17
+ const v = expr(s, n);
18
+ if (v.ty.k === "str")
19
+ e.stmt(`fv::style_text_into(out, ${strArg(v.code)});`);
20
+ else if (v.ty.k === "opt" && v.ty.of.k === "str") {
21
+ e.open(`if let Some(v) = ${v.code}`);
22
+ e.stmt("fv::style_text_into(out, v);");
23
+ e.close();
24
+ }
25
+ else if (!nothing(v.ty))
26
+ fail(s.comp, "FV1007", "a style binding is a string, an object or an array", n);
27
+ }
28
+ export function styleAttr(s, n) {
29
+ switch (n.type) {
30
+ case "StringLiteral":
31
+ return `fv::Attr::str(${rustStr(n.value)})`;
32
+ case "NullLiteral":
33
+ return "fv::Attr::Undefined";
34
+ case "ObjectExpression": {
35
+ const entries = n.properties.map((p) => {
36
+ if (p.type !== "ObjectProperty" || p.computed)
37
+ fail(s.comp, "FV1008", "a style object holds plain `property: value` pairs", p);
38
+ const key = p.key.type === "Identifier" ? p.key.name : String(p.key.value);
39
+ if (/^\d+$/.test(key) || key.startsWith(":"))
40
+ fail(s.comp, "FV1009", `style property \`${key}\``, p);
41
+ return `(${rustStr(key)}, ${valueAttr(s, expr(s, p.value), p.value)})`;
42
+ });
43
+ return `fv::Attr::style([${entries.join(", ")}])`;
44
+ }
45
+ case "ArrayExpression":
46
+ return `fv::Attr::styles([${n.elements.map((el) => (el ? styleAttr(s, el) : "fv::Attr::Undefined")).join(", ")}])`;
47
+ case "LogicalExpression":
48
+ if (n.operator === "&&")
49
+ return `if ${condition(cond(s, n.left))} { ${styleAttr(s, n.right)} } else { fv::Attr::Undefined }`;
50
+ break;
51
+ case "ConditionalExpression":
52
+ return `if ${condition(cond(s, n.test))} { ${styleAttr(s, n.consequent)} } else { ${styleAttr(s, n.alternate)} }`;
53
+ }
54
+ const v = expr(s, n);
55
+ if (v.ty.k === "str" || nothing(v.ty) || (v.ty.k === "opt" && v.ty.of.k === "str"))
56
+ return valueAttr(s, v, n);
57
+ return fail(s.comp, "FV1007", "a style binding is a string, an object or an array", n);
58
+ }
59
+ export function styleItems(s, n, when) {
60
+ if (when === "false")
61
+ return [];
62
+ if (when === "true")
63
+ when = null;
64
+ const both = (a, b) => (a === null ? b : logical(a, "&&", b));
65
+ switch (n.type) {
66
+ case "NullLiteral":
67
+ return [];
68
+ case "ArrayExpression":
69
+ return n.elements.flatMap((el) => (el ? styleItems(s, el, when) : []));
70
+ case "StringLiteral":
71
+ return [{ cond: when, entries: Object.entries(parseStringStyle(n.value)).map(([key, v]) => ({ key, css: key, value: { type: "StringLiteral", value: v } })) }];
72
+ case "ConditionalExpression": {
73
+ const t = cond(s, n.test);
74
+ return [...styleItems(s, n.consequent, both(when, t)), ...styleItems(s, n.alternate, both(when, not(t)))];
75
+ }
76
+ case "LogicalExpression":
77
+ if (n.operator === "&&")
78
+ return styleItems(s, n.right, both(when, cond(s, n.left)));
79
+ break;
80
+ case "ObjectExpression":
81
+ return [{
82
+ cond: when,
83
+ entries: n.properties.map((p) => {
84
+ if (p.type !== "ObjectProperty" || p.computed)
85
+ fail(s.comp, "FV1008", "a style object holds plain `property: value` pairs", p);
86
+ const key = p.key.type === "Identifier" ? p.key.name : String(p.key.value);
87
+ if (/^\d+$/.test(key) || key.startsWith(":"))
88
+ fail(s.comp, "FV1009", `style property \`${key}\``, p);
89
+ return { key, css: key.startsWith("--") ? key : hyphenate(key), value: p.value };
90
+ }),
91
+ }];
92
+ }
93
+ return fail(s.comp, "FV1010", "a style binding is an object, an array of objects, or a string on its own", n);
94
+ }
95
+ export function renderStyle(s, e, n) {
96
+ if (n.type === "StringLiteral") {
97
+ e.lit(escapeHtml(n.value));
98
+ return;
99
+ }
100
+ if (n.type !== "ObjectExpression" && n.type !== "ArrayExpression" && n.type !== "ConditionalExpression" && n.type !== "LogicalExpression" && n.type !== "NullLiteral") {
101
+ const v = expr(s, n);
102
+ if (v.ty.k === "str")
103
+ e.stmt(`fv::escape_into(out, ${strArg(v.code)});`);
104
+ else if (v.ty.k === "opt" && v.ty.of.k === "str") {
105
+ e.open(`if let Some(v) = ${v.code}`);
106
+ e.stmt("fv::escape_into(out, v);");
107
+ e.close();
108
+ }
109
+ else if (!nothing(v.ty))
110
+ fail(s.comp, "FV1007", "a style binding is a string, an object or an array", n);
111
+ return;
112
+ }
113
+ const items = styleItems(s, n, null);
114
+ const order = [];
115
+ const sets = new Map();
116
+ for (const it of items) {
117
+ for (const en of it.entries) {
118
+ if (!sets.has(en.key)) {
119
+ order.push(en.key);
120
+ sets.set(en.key, []);
121
+ }
122
+ sets.get(en.key).push({ cond: it.cond, css: en.css, value: en.value });
123
+ }
124
+ }
125
+ const write = (css, value) => {
126
+ if (value.type === "StringLiteral" || value.type === "NumericLiteral") {
127
+ e.lit(escapeHtml(`${css}:${String(value.value)};`));
128
+ return;
129
+ }
130
+ const v = expr(s, value);
131
+ const one = (w) => {
132
+ if (w.ty.k === "str" || w.ty.k === "int" || w.ty.k === "float") {
133
+ e.lit(`${escapeHtml(css)}:`);
134
+ display(e, w);
135
+ e.lit(";");
136
+ }
137
+ else if (w.ty.k === "opt") {
138
+ e.open(`if let Some(v) = ${w.code}`);
139
+ one({ code: "v", ty: w.ty.of });
140
+ e.close();
141
+ }
142
+ };
143
+ one(v);
144
+ };
145
+ const flat = items.flatMap((it, i) => it.entries.map((en) => ({ key: en.key, item: i, cond: it.cond })));
146
+ for (const key of order) {
147
+ const at = flat.filter((f) => f.key === key);
148
+ if (at.length < 2 || at[0].cond === null)
149
+ continue;
150
+ const first = flat.indexOf(at[0]);
151
+ const again = flat.indexOf(at[at.length - 1]);
152
+ const between = flat.slice(first + 1, again).some((f) => order.indexOf(f.key) > order.indexOf(key));
153
+ if (between)
154
+ fail(s.comp, "FV1011", `the place of style property \`${key}\` would depend on a condition; set it unconditionally first`, n);
155
+ }
156
+ for (const key of order) {
157
+ const chain = [];
158
+ for (const set of sets.get(key).toReversed()) {
159
+ chain.push(set);
160
+ if (set.cond === null)
161
+ break;
162
+ }
163
+ if (chain.length === 1 && chain[0].cond === null) {
164
+ write(chain[0].css, chain[0].value);
165
+ continue;
166
+ }
167
+ chain.forEach((set, i) => {
168
+ if (set.cond === null) {
169
+ e.close(" else {");
170
+ }
171
+ else if (i === 0) {
172
+ e.open(`if ${condition(set.cond)}`);
173
+ }
174
+ else {
175
+ e.close(` else if ${condition(set.cond)} {`);
176
+ }
177
+ write(set.css, set.value);
178
+ });
179
+ e.close();
180
+ }
181
+ }
@@ -1,48 +1,7 @@
1
- import { type Component, type N, type Scope, type Ty, type Val } from "./model.ts";
1
+ import { type N, type Scope } from "./model.ts";
2
2
  import { Emitter } from "./emitter.ts";
3
- /** One `${...}` inside a pushed template literal. */
4
3
  export declare function slot(s: Scope, e: Emitter, n: N): void;
5
- /** `isComment` in `@vue/server-renderer`: a chunk that is only comments and whitespace. */
6
4
  export declare function isComment(text: string): boolean;
7
- /** Whether a `_push` argument is content to `ssrRenderSlot` rather than only comments — `"run"`
8
- * when that depends on the values it interpolates (`${of1}<!--[-->` is a comment when `of1` writes
9
- * nothing). Vue asks it of each pushed string, so the generated code asks `fv::is_comment` of what
10
- * that push wrote. */
11
5
  export declare function pushesContent(n: N): boolean | "run";
12
6
  export declare function push(s: Scope, e: Emitter, n: N): void;
13
- export declare function renderChild(s: Scope, e: Emitter, n: N): void;
14
- /** `name: value` in a struct literal, or the name alone when the value is a variable of that name. */
15
- export declare function fieldInit(name: string, value: string): string;
16
- /** Whether a component takes a `Slots` argument. */
17
- export declare function takesSlots(c: Component): boolean;
18
- /** The arguments after `props` that a component's `render` takes. */
19
- export declare function extraParams(c: Component): string;
20
- /** `render(out, props[, slots][, route])` for a child, with the slot content this template gives
21
- * it as closures; `render_scoped`, with the scope ids its root is handed last — and the attributes
22
- * it is passed, as `fv::Attrs` — for a child that may be handed some. */
23
- export declare function callChild(s: Scope, e: Emitter, child: Component, propsCode: string, slots: N, attrs: string | null): void;
24
- /** The statements a parent's slot content pushes: the `if (_push)` half of its `_withCtx`. */
25
- export declare function slotBody(s: Scope, value: N): N[];
26
- /** A parent's slot content: what it pushes, and the parameter its scoped slot props are bound to
27
- * (`_` when it takes none). */
28
- export declare function slotContent(s: Scope, value: N): {
29
- body: N[];
30
- param: N;
31
- };
32
- /** Whether slot content always pushes something that is not a comment: a push of content outside
33
- * any `if` or loop. Then nothing has to be decided at run time. */
34
- export declare function staticallyFilled(body: N[]): boolean;
35
- /** `RowSlotProps`, `RowSlot`: the names of a scoped slot's props struct and content type. */
36
- export declare function slotTypeName(slotName: string, suffix: string): string;
37
- /** Whether a scoped slot prop's Rust type borrows, and so needs the props' lifetime `'v`. */
38
- export declare function slotFieldBorrows(ty: Ty): boolean;
39
- /** A scoped slot prop's Rust type: a scalar copied, anything else borrowed from the render for `'v`. */
40
- export declare function slotFieldTy(ty: Ty, comp: Component): string;
41
- /** A value an outlet passes, as the scoped slot prop field holds it. */
42
- export declare function slotFieldValue(s: Scope, v: Val, n: N): string;
43
- /** `<slot name="x" :prop="…">fallback</slot>`: `ssrRenderSlot`, with the props a scoped slot passes. */
44
- export declare function slotOutlet(s: Scope, e: Emitter, c: N): void;
45
- /** A value into a child's props field, whose strings are `Cow`s. */
46
- export declare function ownInto(comp: Component, v: Val, want: Ty, node: N): string;
47
7
  export declare function statements(s: Scope, e: Emitter, body: N[]): void;
48
- export declare function list(s: Scope, e: Emitter, c: N): void;