ferrovue 0.4.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 (68) hide show
  1. package/README.md +198 -34
  2. package/dist/attrs.d.ts +1 -1
  3. package/dist/attrs.js +24 -22
  4. package/dist/calls.js +17 -15
  5. package/dist/children.d.ts +9 -2
  6. package/dist/children.js +48 -35
  7. package/dist/classes.js +11 -11
  8. package/dist/cli.js +31 -5
  9. package/dist/client.d.ts +35 -2
  10. package/dist/client.js +77 -2
  11. package/dist/compiler.d.ts +1 -1
  12. package/dist/compiler.js +7 -3
  13. package/dist/component.d.ts +3 -1
  14. package/dist/component.js +114 -19
  15. package/dist/constants.d.ts +42 -0
  16. package/dist/constants.js +292 -0
  17. package/dist/context.d.ts +25 -1
  18. package/dist/context.js +11 -5
  19. package/dist/diagnostics.d.ts +23 -0
  20. package/dist/diagnostics.js +30 -0
  21. package/dist/errors.d.ts +867 -0
  22. package/dist/errors.js +330 -0
  23. package/dist/expr.d.ts +1 -0
  24. package/dist/expr.js +120 -49
  25. package/dist/fixture.d.ts +3 -10
  26. package/dist/fixture.js +2 -6
  27. package/dist/hydration.d.ts +15 -0
  28. package/dist/hydration.js +80 -0
  29. package/dist/index.d.ts +2 -1
  30. package/dist/index.js +2 -1
  31. package/dist/link-router.d.ts +24 -0
  32. package/dist/link-router.js +36 -0
  33. package/dist/lists.js +30 -21
  34. package/dist/loops.js +14 -10
  35. package/dist/model.d.ts +32 -1
  36. package/dist/model.js +123 -6
  37. package/dist/narrowing.d.ts +8 -0
  38. package/dist/narrowing.js +40 -9
  39. package/dist/plugins/client-only.d.ts +8 -0
  40. package/dist/plugins/client-only.js +107 -0
  41. package/dist/plugins/i18n.js +14 -14
  42. package/dist/plugins/index.js +3 -1
  43. package/dist/plugins/router-link.js +33 -30
  44. package/dist/plugins/router.js +9 -9
  45. package/dist/plugins/scoped.js +1 -1
  46. package/dist/plugins/shared-types.js +1 -1
  47. package/dist/plugins/stores.js +26 -24
  48. package/dist/plugins/teleport.js +3 -3
  49. package/dist/plugins/twins.d.ts +10 -0
  50. package/dist/plugins/twins.js +164 -0
  51. package/dist/routes.d.ts +10 -0
  52. package/dist/routes.js +6 -0
  53. package/dist/rust.js +18 -14
  54. package/dist/script.d.ts +3 -0
  55. package/dist/script.js +119 -17
  56. package/dist/settle.d.ts +6 -0
  57. package/dist/settle.js +34 -0
  58. package/dist/slots.js +18 -18
  59. package/dist/strings.js +11 -11
  60. package/dist/styles.js +13 -13
  61. package/dist/template.js +11 -11
  62. package/dist/testing.d.ts +1 -0
  63. package/dist/testing.js +3 -2
  64. package/dist/typescript.d.ts +2 -1
  65. package/dist/typescript.js +46 -19
  66. package/dist/vite.d.ts +1 -1
  67. package/dist/vite.js +10 -9
  68. package/package.json +9 -5
@@ -0,0 +1,107 @@
1
+ import { parse as parseJs } from "@babel/parser";
2
+ import { fail } from "../model.js";
3
+ import { isAttrs } from "../attrs.js";
4
+ import { slotContent } from "../slots.js";
5
+ import { statements } from "../template.js";
6
+ import { runOf } from "../plugin.js";
7
+ const CLIENT_MODULES = new Set(["ferrovue", "ferrovue/client"]);
8
+ function setupName(target) {
9
+ if (target?.type !== "MemberExpression" || target.object.type !== "Identifier" || target.object.name !== "$setup")
10
+ return null;
11
+ return target.computed ? (target.property.value ?? null) : target.property.name;
12
+ }
13
+ function clientOnlyLocals(script) {
14
+ const locals = new Set();
15
+ for (const st of script) {
16
+ if (st.type !== "ImportDeclaration" || !CLIENT_MODULES.has(st.source.value) || st.importKind === "type")
17
+ continue;
18
+ for (const sp of st.specifiers) {
19
+ if (sp.type === "ImportSpecifier" && (sp.imported.name ?? sp.imported.value) === "ClientOnly")
20
+ locals.add(sp.local.name);
21
+ }
22
+ }
23
+ return locals;
24
+ }
25
+ function namesOutside(code, locals) {
26
+ const names = new Set();
27
+ const walk = (n) => {
28
+ if (!n || typeof n !== "object")
29
+ return;
30
+ if (Array.isArray(n)) {
31
+ for (const x of n)
32
+ walk(x);
33
+ return;
34
+ }
35
+ if (n.type === "Identifier")
36
+ names.add(n.name);
37
+ if (n.type === "VariableDeclarator") {
38
+ walk(n.init);
39
+ return;
40
+ }
41
+ if (n.type === "CallExpression" && n.callee.type === "Identifier" && n.callee.name === "_ssrRenderComponent" && locals.has(setupName(n.arguments[0]) ?? "")) {
42
+ const [, props, slots, ...rest] = n.arguments;
43
+ walk([props, rest]);
44
+ if (slots?.type === "ObjectExpression") {
45
+ for (const p of slots.properties)
46
+ if ((p.key?.name ?? p.key?.value) !== "default")
47
+ walk(p);
48
+ }
49
+ else
50
+ walk(slots);
51
+ return;
52
+ }
53
+ for (const [key, v] of Object.entries(n))
54
+ if (key !== "loc" && key !== "start" && key !== "end")
55
+ walk(v);
56
+ };
57
+ walk(parseJs(code, { sourceType: "module" }).program);
58
+ return names;
59
+ }
60
+ export const clientOnly = {
61
+ name: "client-only",
62
+ configure: () => ({ locals: new Map(), outside: new Map() }),
63
+ compiled(comp, code, script) {
64
+ const locals = clientOnlyLocals(script);
65
+ if (!locals.size)
66
+ return;
67
+ const run = runOf(clientOnly);
68
+ run.locals.set(comp, locals);
69
+ run.outside.set(comp, namesOutside(code, locals));
70
+ },
71
+ resolveComponent(s, local) {
72
+ const outside = runOf(clientOnly).outside.get(s.comp);
73
+ return outside !== undefined && !outside.has(local);
74
+ },
75
+ component(s, e, n) {
76
+ if (!runOf(clientOnly).locals.get(s.comp)?.has(setupName(n.arguments[0]) ?? ""))
77
+ return false;
78
+ const [, props, slots] = n.arguments;
79
+ if (props && props.type !== "NullLiteral" && !isAttrs(props)) {
80
+ fail(s.comp, "FV1504", "`<ClientOnly>` takes no attributes: the server renders none of them; put them on an element inside it", props);
81
+ }
82
+ let fallback = null;
83
+ if (slots && slots.type !== "NullLiteral") {
84
+ if (slots.type !== "ObjectExpression")
85
+ fail(s.comp, "FV0006", "unexpected `<ClientOnly>` content", slots);
86
+ for (const p of slots.properties) {
87
+ const key = p.key?.name ?? p.key?.value;
88
+ if (key === "_" || key === "default")
89
+ continue;
90
+ if (key !== "fallback" || p.type !== "ObjectProperty" || p.computed)
91
+ fail(s.comp, "FV1505", "`<ClientOnly>` has a default slot and a `#fallback` slot, and no other", p);
92
+ fallback = p.value;
93
+ }
94
+ }
95
+ if (fallback === null) {
96
+ e.lit("<!---->");
97
+ return true;
98
+ }
99
+ const { body, param } = slotContent(s, fallback);
100
+ if (param && !(param.type === "Identifier" && param.name === "_"))
101
+ fail(s.comp, "FV1506", "`<ClientOnly>`'s `#fallback` passes no props", param);
102
+ e.lit("<!--[-->");
103
+ statements({ ...s, fill: false, vnode: false, sid: null }, e, body);
104
+ e.lit("<!--]-->");
105
+ return true;
106
+ },
107
+ };
@@ -1,7 +1,7 @@
1
1
  import { readdirSync, readFileSync } from "node:fs";
2
2
  import { basename, join } from "node:path";
3
3
  import { createParser } from "@intlify/message-compiler";
4
- import { fail, GenError, rustStr, STR } from "../model.js";
4
+ import { fail, failIn, rustStr, STR } from "../model.js";
5
5
  import { expr } from "../expr.js";
6
6
  import { bare, strArg } from "../parens.js";
7
7
  import { header } from "../rust.js";
@@ -18,7 +18,7 @@ function readLocales(root, config) {
18
18
  data = JSON.parse(readFileSync(join(dir, f), "utf8"));
19
19
  }
20
20
  catch (e) {
21
- throw new GenError(`${file}: ${e.message}`);
21
+ failIn(file, "FV1401", e.message);
22
22
  }
23
23
  const messages = new Map();
24
24
  const nested = new Map();
@@ -39,7 +39,7 @@ function readLocales(root, config) {
39
39
  messages.set(key, parser.parse(text));
40
40
  }
41
41
  catch (e) {
42
- throw new GenError(`${file}: message \`${key}\`: ${e.message}`);
42
+ failIn(file, "FV1402", `message \`${key}\`: ${e.message}`);
43
43
  }
44
44
  }
45
45
  return { name: basename(f, ".json"), file, messages };
@@ -62,15 +62,15 @@ function messageSource(file, key, ast) {
62
62
  return `Part::Literal(${rustStr(item.value)})`;
63
63
  case 6: {
64
64
  if (item.key?.type !== 7)
65
- throw new GenError(`${file}: message \`${key}\` links to a key chosen at run time, which is not supported`);
65
+ failIn(file, "FV1403", `message \`${key}\` links to a key chosen at run time, which is not supported`);
66
66
  const modifier = item.modifier?.value;
67
67
  if (modifier !== undefined && !MODIFIERS.has(modifier)) {
68
- throw new GenError(`${file}: message \`${key}\` uses the modifier \`${modifier}\`, which vue-i18n does not define`);
68
+ failIn(file, "FV1404", `message \`${key}\` uses the modifier \`${modifier}\`, which vue-i18n does not define`);
69
69
  }
70
70
  return `Part::Linked { key: ${rustStr(item.key.value)}, modifier: ${modifier === undefined ? "None" : `Some(${rustStr(modifier)})`} }`;
71
71
  }
72
72
  default:
73
- throw new GenError(`${file}: message \`${key}\` holds a construct ferrovue does not render (node type ${item.type})`);
73
+ return failIn(file, "FV1405", `message \`${key}\` holds a construct ferrovue does not render (node type ${item.type})`);
74
74
  }
75
75
  };
76
76
  const items = (c) => c.items ?? (c.static !== undefined ? [{ type: 3, value: c.static }] : []);
@@ -126,17 +126,17 @@ function i18nValue(s, n) {
126
126
  case "bool":
127
127
  return `fv::i18n::Value::Bool(${bare(v.code)})`;
128
128
  default:
129
- return fail(s.comp, "a value given to `t()` is a string, a number or a boolean that is present: narrow an optional one with `v-if` first", n);
129
+ return fail(s.comp, "FV1406", "a value given to `t()` is a string, a number or a boolean that is present: narrow an optional one with `v-if` first", n);
130
130
  }
131
131
  }
132
132
  function translate(s, args, n) {
133
133
  if (!runOf(i18n).setup)
134
- fail(s.comp, "`t()` needs `i18n` in ferrovue.config.json: where the locale files are", n);
134
+ fail(s.comp, "FV1407", "`t()` needs `i18n` in ferrovue.config.json: where the locale files are", n);
135
135
  if (args.length < 1 || args.length > 3)
136
- fail(s.comp, "`t()` takes a key, then named values, a list or a plural number", n);
136
+ fail(s.comp, "FV1408", "`t()` takes a key, then named values, a list or a plural number", n);
137
137
  const key = expr(s, args[0]);
138
138
  if (key.ty.k !== "str")
139
- fail(s.comp, "the key given to `t()` is a string", args[0]);
139
+ fail(s.comp, "FV1409", "the key given to `t()` is a string", args[0]);
140
140
  let named = "&[]";
141
141
  let list = "&[]";
142
142
  let plural = "None";
@@ -144,7 +144,7 @@ function translate(s, args, n) {
144
144
  if (a.type === "ObjectExpression") {
145
145
  const pairs = a.properties.map((p) => {
146
146
  if (p.type !== "ObjectProperty" || p.computed)
147
- fail(s.comp, "named values hold plain keys", p);
147
+ fail(s.comp, "FV1410", "named values hold plain keys", p);
148
148
  return `(${rustStr(String(p.key.name ?? p.key.value))}, ${i18nValue(s, p.value)})`;
149
149
  });
150
150
  named = `&[${pairs.join(", ")}]`;
@@ -155,9 +155,9 @@ function translate(s, args, n) {
155
155
  else {
156
156
  const v = expr(s, a);
157
157
  if (v.ty.k === "str")
158
- fail(s.comp, "a default message given to `t()` is not supported: add the message to the locale files", a);
158
+ fail(s.comp, "FV1411", "a default message given to `t()` is not supported: add the message to the locale files", a);
159
159
  if (v.ty.k !== "int")
160
- fail(s.comp, "the plural number given to `t()` is an integer", a);
160
+ fail(s.comp, "FV1412", "the plural number given to `t()` is an integer", a);
161
161
  plural = `Some(${bare(v.code)})`;
162
162
  }
163
163
  }
@@ -191,7 +191,7 @@ export const i18n = {
191
191
  }
192
192
  for (const p of d.id.properties) {
193
193
  if (p.type !== "ObjectProperty" || p.computed || p.value.type !== "Identifier") {
194
- fail(s.comp, "`useI18n()` is destructured into plain names", p);
194
+ fail(s.comp, "FV1413", "`useI18n()` is destructured into plain names", p);
195
195
  }
196
196
  const key = p.key.name ?? p.key.value;
197
197
  if (key === "t")
@@ -5,4 +5,6 @@ import { sharedTypes } from "./shared-types.js";
5
5
  import { i18n } from "./i18n.js";
6
6
  import { teleport } from "./teleport.js";
7
7
  import { scoped } from "./scoped.js";
8
- export const PLUGINS = [router, piniaStores, sharedTypes, i18n, teleport, scoped];
8
+ import { clientOnly } from "./client-only.js";
9
+ import { twinsPlugin } from "./twins.js";
10
+ export const PLUGINS = [router, piniaStores, sharedTypes, i18n, teleport, scoped, clientOnly, twinsPlugin];
@@ -20,7 +20,7 @@ export function routeParams(path) {
20
20
  }
21
21
  function noHalves(s, v, n) {
22
22
  if (v.lone)
23
- fail(s.comp, lonely("a `<RouterLink>` location"), n);
23
+ fail(s.comp, "FV0706", lonely("a `<RouterLink>` location"), n);
24
24
  }
25
25
  export function urlText(s, v, n) {
26
26
  noHalves(s, v, n);
@@ -30,13 +30,13 @@ export function urlText(s, v, n) {
30
30
  return `&*fv::Js(${bare(v.code)}).to_string()`;
31
31
  if (v.ty.k === "bool")
32
32
  return `if ${condition(v.code)} { "true" } else { "false" }`;
33
- return fail(s.comp, "a route parameter is a string or a number that is present", n);
33
+ return fail(s.comp, "FV1201", "a route parameter is a string or a number that is present", n);
34
34
  }
35
35
  export function resolveLink(s, e, to) {
36
36
  if (to.type !== "ObjectExpression") {
37
37
  const target = expr(s, to);
38
38
  if (target.ty.k !== "str")
39
- fail(s.comp, "`<RouterLink>`'s `to` is a string or an object literal", to);
39
+ fail(s.comp, "FV1202", "`<RouterLink>`'s `to` is a string or an object literal", to);
40
40
  noHalves(s, target, to);
41
41
  e.stmt(`let fv_link = fv_route.link(${strArg(target.code)});`);
42
42
  return;
@@ -44,12 +44,12 @@ export function resolveLink(s, e, to) {
44
44
  const parts = new Map();
45
45
  for (const p of to.properties) {
46
46
  if (p.type !== "ObjectProperty" || p.computed)
47
- fail(s.comp, "a `to` object holds plain keys", p);
47
+ fail(s.comp, "FV1203", "a `to` object holds plain keys", p);
48
48
  const key = p.key.name ?? p.key.value;
49
49
  if (["replace", "force", "state"].includes(key))
50
50
  continue;
51
51
  if (!["name", "path", "params", "query", "hash"].includes(key))
52
- fail(s.comp, `\`${key}\` in a \`to\` object`, p);
52
+ fail(s.comp, "FV1204", `\`${key}\` in a \`to\` object`, p);
53
53
  parts.set(key, p.value);
54
54
  }
55
55
  e.open("let fv_link =");
@@ -58,12 +58,15 @@ export function resolveLink(s, e, to) {
58
58
  if (query) {
59
59
  e.stmt("let mut fv_search = String::new();");
60
60
  if (query.type !== "ObjectExpression")
61
- fail(s.comp, "a `to`'s `query` is an object literal", query);
61
+ fail(s.comp, "FV1205", "a `to`'s `query` is an object literal", query);
62
62
  for (const p of query.properties) {
63
63
  if (p.type !== "ObjectProperty" || p.computed)
64
- fail(s.comp, "a query holds plain keys", p);
64
+ fail(s.comp, "FV1206", "a query holds plain keys", p);
65
65
  const key = String(p.key.name ?? p.key.value);
66
66
  const v = expr(s, p.value);
67
+ if (v.ty.k === "null" || (v.ty.k === "opt" && v.ty.none !== undefined)) {
68
+ fail(s.comp, "FV1207", "a query value that may be `null`, which vue-router writes as the key alone: give `undefined` to leave it out", p.value);
69
+ }
67
70
  if (v.ty.k === "undef")
68
71
  continue;
69
72
  if (v.ty.k === "opt") {
@@ -80,7 +83,7 @@ export function resolveLink(s, e, to) {
80
83
  if (h) {
81
84
  const v = expr(s, h);
82
85
  if (v.ty.k !== "str")
83
- fail(s.comp, "a `to`'s `hash` is a string", h);
86
+ fail(s.comp, "FV1208", "a `to`'s `hash` is a string", h);
84
87
  noHalves(s, v, h);
85
88
  hash = strArg(v.code);
86
89
  }
@@ -88,42 +91,42 @@ export function resolveLink(s, e, to) {
88
91
  const path = parts.get("path");
89
92
  if (name) {
90
93
  if (name.type !== "StringLiteral")
91
- fail(s.comp, "a `to`'s `name` is a string literal, checked against the routes", name);
94
+ fail(s.comp, "FV1209", "a `to`'s `name` is a string literal, checked against the routes", name);
92
95
  const route = allRoutes(runOf(router).routes).find((r) => r.name === name.value);
93
96
  if (!route)
94
- fail(s.comp, `no route is called \`${name.value}\``, name);
97
+ fail(s.comp, "FV1210", `no route is called \`${name.value}\``, name);
95
98
  const wanted = routeParams(route.fullPath);
96
99
  const given = new Map();
97
100
  const params = parts.get("params");
98
101
  if (params) {
99
102
  if (params.type !== "ObjectExpression")
100
- fail(s.comp, "a `to`'s `params` is an object literal", params);
103
+ fail(s.comp, "FV1211", "a `to`'s `params` is an object literal", params);
101
104
  for (const p of params.properties) {
102
105
  if (p.type !== "ObjectProperty" || p.computed)
103
- fail(s.comp, "params hold plain keys", p);
106
+ fail(s.comp, "FV1212", "params hold plain keys", p);
104
107
  const key = String(p.key.name ?? p.key.value);
105
108
  if (!wanted.includes(key))
106
- fail(s.comp, `route \`${name.value}\` has no parameter \`${key}\``, p);
109
+ fail(s.comp, "FV1213", `route \`${name.value}\` has no parameter \`${key}\``, p);
107
110
  given.set(key, p.value);
108
111
  }
109
112
  }
110
113
  const missing = wanted.filter((w) => !given.has(w));
111
114
  if (missing.length)
112
- fail(s.comp, `route \`${name.value}\` needs \`${missing.join("`, `")}\`: give every parameter`, to);
115
+ fail(s.comp, "FV1214", `route \`${name.value}\` needs \`${missing.join("`, `")}\`: give every parameter`, to);
113
116
  const list = wanted.map((w) => `(${rustStr(w)}, ${urlText(s, expr(s, given.get(w)), given.get(w))})`);
114
117
  e.stmt(`fv_route.link_named(${rustStr(name.value)}, &[${list.join(", ")}], ${search}, ${hash})`);
115
118
  }
116
119
  else if (path) {
117
120
  if (parts.has("params"))
118
- fail(s.comp, "a `to` with a `path` takes no `params`, which vue-router ignores", path);
121
+ fail(s.comp, "FV1215", "a `to` with a `path` takes no `params`, which vue-router ignores", path);
119
122
  const v = expr(s, path);
120
123
  if (v.ty.k !== "str")
121
- fail(s.comp, "a `to`'s `path` is a string", path);
124
+ fail(s.comp, "FV1216", "a `to`'s `path` is a string", path);
122
125
  noHalves(s, v, path);
123
126
  e.stmt(`fv_route.link_path(${strArg(v.code)}, ${search}, ${hash})`);
124
127
  }
125
128
  else
126
- fail(s.comp, "a `to` object has a `name` or a `path`", to);
129
+ fail(s.comp, "FV1217", "a `to` object has a `name` or a `path`", to);
127
130
  e.close(";");
128
131
  }
129
132
  export function routerLink(s, e, n) {
@@ -133,12 +136,12 @@ export function routerLink(s, e, n) {
133
136
  props = mergeProps(s, props);
134
137
  }
135
138
  if (props?.type !== "ObjectExpression")
136
- fail(s.comp, "`<RouterLink>` takes literal attributes", n);
139
+ fail(s.comp, "FV1218", "`<RouterLink>` takes literal attributes", n);
137
140
  const fields = new Map();
138
141
  const attrs = [];
139
142
  for (const p of props.properties) {
140
143
  if (p.type !== "ObjectProperty" || p.computed)
141
- fail(s.comp, "`<RouterLink>` attributes hold plain keys", p);
144
+ fail(s.comp, "FV1219", "`<RouterLink>` attributes hold plain keys", p);
142
145
  const raw = p.key.type === "Identifier" ? p.key.name : p.key.value;
143
146
  const key = raw.replace(/-(\w)/g, (_, c) => c.toUpperCase());
144
147
  if (ROUTER_LINK_PROPS.has(key))
@@ -146,15 +149,15 @@ export function routerLink(s, e, n) {
146
149
  else if (/^on[^a-z]/.test(raw) || IGNORED_PROPS.has(raw) || ROUTER_LINK_INERT.has(key))
147
150
  continue;
148
151
  else if (key === "custom")
149
- fail(s.comp, "`custom` on `<RouterLink>` renders a scoped slot, which is not supported", p);
152
+ fail(s.comp, "FV1220", "`custom` on `<RouterLink>` renders a scoped slot, which is not supported", p);
150
153
  else if (key === "href" || key === "ariaCurrent")
151
- fail(s.comp, `\`${raw}\` on \`<RouterLink>\` is its own`, p);
154
+ fail(s.comp, "FV1221", `\`${raw}\` on \`<RouterLink>\` is its own`, p);
152
155
  else
153
156
  attrs.push({ ...p, key: { type: "StringLiteral", value: raw } });
154
157
  }
155
158
  const to = fields.get("to");
156
159
  if (!to)
157
- fail(s.comp, "`<RouterLink>` needs `to`", n);
160
+ fail(s.comp, "FV1222", "`<RouterLink>` needs `to`", n);
158
161
  const passed = (rawProps?.type === "Identifier" && rawProps.name === "_attrs") || rawProps?.arguments?.some((a) => a.type === "Identifier" && a.name === "_attrs");
159
162
  const base = passed ? s.attrs : null;
160
163
  const slotted = slotScopeId ? s.sid : null;
@@ -166,19 +169,19 @@ export function routerLink(s, e, n) {
166
169
  };
167
170
  const writesScopeId = (x) => x.type === "TemplateLiteral" && x.expressions.some((y) => y.type === "Identifier" && y.name === "_scopeId");
168
171
  if (slotted !== null && holds(writesScopeId)) {
169
- fail(s.comp, "an element inside a `<RouterLink>` in slot content given a slot scope id: vue-router writes those ids by rules of its own", to);
172
+ fail(s.comp, "FV1223", "an element inside a `<RouterLink>` in slot content given a slot scope id: vue-router writes those ids by rules of its own", to);
170
173
  }
171
174
  if ((scopeId !== null || slotted !== null || base !== null) && holds((x) => x.type === "CallExpression" && x.callee.name === "_ssrRenderSlot")) {
172
- fail(s.comp, "a `<slot>` inside a `<RouterLink>` that takes scope ids: vue-router renders it by rules of its own", to);
175
+ fail(s.comp, "FV1224", "a `<slot>` inside a `<RouterLink>` that takes scope ids: vue-router renders it by rules of its own", to);
173
176
  }
174
177
  if (!runOf(router).routes)
175
- fail(s.comp, `\`<RouterLink>\` needs \`routes\` in ${CONFIG_FILE}: the paths it resolves against`, n);
178
+ fail(s.comp, "FV1225", `\`<RouterLink>\` needs \`routes\` in ${CONFIG_FILE}: the paths it resolves against`, n);
176
179
  const literal = (key, fallback) => {
177
180
  const v = fields.get(key);
178
181
  if (!v)
179
182
  return fallback;
180
183
  if (v.type !== "StringLiteral")
181
- fail(s.comp, `\`${key}\` on \`<RouterLink>\` is a string literal`, v);
184
+ fail(s.comp, "FV1226", `\`${key}\` on \`<RouterLink>\` is a string literal`, v);
182
185
  return v.value;
183
186
  };
184
187
  const activeClass = literal("activeClass", runOf(router).linkActive);
@@ -194,10 +197,10 @@ export function routerLink(s, e, n) {
194
197
  for (const name of s.comp.attrNames) {
195
198
  const key = camelize(name);
196
199
  if ((ROUTER_LINK_PROPS.has(key) && key !== "class") || ROUTER_LINK_INERT.has(key) || key === "custom" || key === "viewTransition") {
197
- fail(s.comp, `\`${name}\`, an attribute ${s.comp.name} may be passed, would reach its \`<RouterLink>\` as a prop`, n);
200
+ fail(s.comp, "FV1227", `\`${name}\`, an attribute ${s.comp.name} may be passed, would reach its \`<RouterLink>\` as a prop`, n);
198
201
  }
199
202
  if (key === "href" || key === "ariaCurrent")
200
- fail(s.comp, `\`${name}\`, an attribute ${s.comp.name} may be passed, would replace its \`<RouterLink>\`'s own`, n);
203
+ fail(s.comp, "FV1228", `\`${name}\`, an attribute ${s.comp.name} may be passed, would replace its \`<RouterLink>\`'s own`, n);
201
204
  }
202
205
  e.open(`if ${s.fallthrough}.is_empty()`);
203
206
  }
@@ -265,13 +268,13 @@ export function routerLink(s, e, n) {
265
268
  e.lit(">");
266
269
  if (slots && slots.type !== "NullLiteral") {
267
270
  if (slots.type !== "ObjectExpression")
268
- fail(s.comp, "slots must be an object literal", slots);
271
+ fail(s.comp, "FV0901", "slots must be an object literal", slots);
269
272
  for (const p of slots.properties) {
270
273
  const key = p.key?.type === "Identifier" ? p.key.name : p.key?.value;
271
274
  if (key === "_")
272
275
  continue;
273
276
  if (key !== "default")
274
- fail(s.comp, "`<RouterLink>` has only its default slot", p);
277
+ fail(s.comp, "FV1229", "`<RouterLink>` has only its default slot", p);
275
278
  statements({ ...s, fill: false, vnode: true }, e, slotBody(s, p.value));
276
279
  }
277
280
  }
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { BOOL, fail, GenError, opt, rustStr, STR } from "../model.js";
3
+ import { BOOL, fail, failIn, GenError, opt, rustStr, STR } from "../model.js";
4
4
  import { CONFIG_FILE } from "../context.js";
5
5
  import { expr } from "../expr.js";
6
6
  import { boolOf, pathOf } from "../narrowing.js";
@@ -22,7 +22,7 @@ function typeofString(n) {
22
22
  }
23
23
  function theRoute(s, n) {
24
24
  if (!runOf(router).routes)
25
- fail(s.comp, `reading the route needs \`routes\` in ${CONFIG_FILE}`, n);
25
+ fail(s.comp, "FV1230", `reading the route needs \`routes\` in ${CONFIG_FILE}`, n);
26
26
  runOf(router).readers.add(s.comp);
27
27
  return { code: "fv_route", ty: { k: "route" } };
28
28
  }
@@ -46,16 +46,16 @@ function routeField(s, base, prop, n) {
46
46
  case "fullPath":
47
47
  return { code: "fv_route.full_path()", ty: STR };
48
48
  }
49
- return fail(s.comp, `\`route.${prop}\` is not available on the server: \`path\`, \`fullPath\`, \`hash\`, \`name\`, \`params\` and \`query\` are`, n);
49
+ return fail(s.comp, "FV1231", `\`route.${prop}\` is not available on the server: \`path\`, \`fullPath\`, \`hash\`, \`name\`, \`params\` and \`query\` are`, n);
50
50
  }
51
51
  export function readRoutes(root, file) {
52
52
  const raw = JSON.parse(readFileSync(join(root, file), "utf8"));
53
53
  if (!Array.isArray(raw))
54
- throw new GenError(`${file} lists the routes in an array`);
54
+ throw new GenError("FV1232", `${file} lists the routes in an array`, { file });
55
55
  const read = (list, parent) => list.map((r) => {
56
56
  const o = (typeof r === "string" ? { path: r } : r);
57
57
  if (typeof o?.path !== "string" || (o.name !== undefined && typeof o.name !== "string") || (o.children !== undefined && !Array.isArray(o.children))) {
58
- throw new GenError(`${file}: a route is a path, or \`{ "path": "…", "name": "…", "children": [ … ] }\``);
58
+ failIn(file, "FV1233", `a route is a path, or \`{ "path": "…", "name": "…", "children": [ … ] }\``);
59
59
  }
60
60
  const fullPath = parent === null || o.path.startsWith("/") ? o.path : `${parent}${parent.endsWith("/") || o.path === "" ? "" : "/"}${o.path}`;
61
61
  const def = { path: o.path, fullPath };
@@ -160,7 +160,7 @@ export const router = {
160
160
  return null;
161
161
  const v = expr(s, tested.target);
162
162
  if (v.ty.k !== "query")
163
- fail(s.comp, '`typeof` tests a query value only, as `typeof route.query.q === "string"`', n);
163
+ fail(s.comp, "FV1234", '`typeof` tests a query value only, as `typeof route.query.q === "string"`', n);
164
164
  const one = `${atom(v.code)}.attr_value().is_some()`;
165
165
  return boolOf(tested.negated ? not(one) : one);
166
166
  },
@@ -191,7 +191,7 @@ export const router = {
191
191
  if (a.ty.k !== "query")
192
192
  return undefined;
193
193
  if (b.ty.k !== "str")
194
- fail(s.comp, "`??` after a query value takes a string", n);
194
+ fail(s.comp, "FV1235", "`??` after a query value takes a string", n);
195
195
  return { code: `${atom(a.code)}.or(${bare(b.code)})`, ty: a.ty };
196
196
  },
197
197
  equals(a, b) {
@@ -225,7 +225,7 @@ export const router = {
225
225
  routerLink(s, e, n);
226
226
  else if (routed === "RouterView") {
227
227
  if (scopeIdOf(s.comp) !== null)
228
- fail(s.comp, "`<RouterView>` in a component with `<style scoped>` gives the page this component's id, which the server's page does not carry", n);
228
+ fail(s.comp, "FV1236", "`<RouterView>` in a component with `<style scoped>` gives the page this component's id, which the server's page does not carry", n);
229
229
  e.stmt("fv_slots.router_view.render_to(out);");
230
230
  }
231
231
  else
@@ -234,7 +234,7 @@ export const router = {
234
234
  },
235
235
  child(s, child, n) {
236
236
  if (runOf(router).views.has(child)) {
237
- fail(s.comp, `${child.name} holds \`<RouterView>\`: the server renders it at the top, never as a child`, n);
237
+ fail(s.comp, "FV1237", `${child.name} holds \`<RouterView>\`: the server renders it at the top, never as a child`, n);
238
238
  }
239
239
  },
240
240
  slotFields: (comp) => (runOf(router).views.has(comp) ? [{ js: "routerView", rust: "router_view", doc: "The page `<RouterView>` shows." }] : []),
@@ -98,7 +98,7 @@ function childIds(s, child, passesAttrs, inSlot, n) {
98
98
  else
99
99
  code = `&fv::scope_attrs(${base ?? '""'}, ${own === null ? '""' : rustStr(own)}, ${slotted ?? '""'})`;
100
100
  if (code !== null && !child.inherits)
101
- fail(s.comp, `${child.name} is handed scope ids its render does not take`, n);
101
+ fail(s.comp, "FV1012", `${child.name} is handed scope ids its render does not take`, n);
102
102
  return code;
103
103
  }
104
104
  export const scoped = {
@@ -3,5 +3,5 @@ import { typesSource } from "../rust.js";
3
3
  import {} from "../plugin.js";
4
4
  export const sharedTypes = {
5
5
  name: "types",
6
- modules: () => (ctx.typeStructs.size ? [["types.rs", typesSource()]] : []),
6
+ modules: () => (ctx.typeStructs.size || ctx.typeConsts.size ? [["types.rs", typesSource()]] : []),
7
7
  };