@yannosay/sinth 5.2.2 → 5.3.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 (42) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +38 -19
  3. package/dist/browser/compile.d.ts +35 -0
  4. package/dist/browser/compile.js +158 -0
  5. package/dist/browser/sinth.js +1492 -0
  6. package/dist/cli/index.js +3 -1
  7. package/dist/cli/templates.js +2 -2
  8. package/dist/cli/ui.d.ts +0 -1
  9. package/dist/cli/ui.js +1 -2
  10. package/dist/compiler/ast.d.ts +11 -0
  11. package/dist/compiler/codegen.d.ts +2 -87
  12. package/dist/compiler/codegen.js +49 -6
  13. package/dist/compiler/diagnostics.d.ts +0 -1
  14. package/dist/compiler/diagnostics.js +0 -4
  15. package/dist/compiler/html.d.ts +2 -0
  16. package/dist/compiler/html.js +11 -1
  17. package/dist/compiler/lexer.js +9 -2
  18. package/dist/compiler/parser.js +27 -1
  19. package/dist/compiler/prerender.js +4 -0
  20. package/dist/index.d.ts +2 -0
  21. package/dist/index.js +3 -1
  22. package/dist/project/build.d.ts +6 -0
  23. package/dist/project/build.js +69 -41
  24. package/dist/project/config.d.ts +1 -0
  25. package/dist/project/config.js +3 -2
  26. package/dist/project/project.d.ts +1 -0
  27. package/dist/project/project.js +2 -1
  28. package/dist/runtime/index.d.ts +6 -0
  29. package/dist/runtime/index.js +18 -2
  30. package/dist/runtime/router.d.ts +36 -0
  31. package/dist/runtime/router.js +215 -0
  32. package/dist/server/client.js +3 -1
  33. package/dist/server/dev.js +65 -25
  34. package/dist/server/functions.d.ts +49 -0
  35. package/dist/server/functions.js +309 -0
  36. package/dist/server/preview.d.ts +2 -0
  37. package/dist/server/preview.js +41 -18
  38. package/dist/server/static.d.ts +10 -0
  39. package/dist/server/static.js +25 -0
  40. package/package.json +20 -12
  41. package/schema/sinth.config.schema.json +2 -1
  42. package/DOCS.md +0 -1360
package/dist/cli/index.js CHANGED
@@ -123,7 +123,7 @@ const commands = {
123
123
  ui_1.c.cyan(p.page.route),
124
124
  ui_1.c.gray(p.page.outFile),
125
125
  (0, ui_1.formatBytes)(p.bytes),
126
- js ? ui_1.c.yellow("js " + (0, ui_1.formatBytes)(js.contents.byteLength)) : ui_1.c.green("no js"),
126
+ !js ? ui_1.c.green("no js") : p.interactive ? ui_1.c.yellow("js " + (0, ui_1.formatBytes)(js.contents.byteLength)) : ui_1.c.green("router " + (0, ui_1.formatBytes)(js.contents.byteLength)),
127
127
  css ? ui_1.c.magenta("css " + (0, ui_1.formatBytes)(css.contents.byteLength)) : "",
128
128
  ]);
129
129
  }
@@ -156,6 +156,8 @@ const commands = {
156
156
  port: Number(args.flags.port ?? project.config.previewPort),
157
157
  host: String(args.flags.host ?? project.config.host),
158
158
  open: !!args.flags.open,
159
+ base: project.config.base,
160
+ root: project.root,
159
161
  });
160
162
  return -1;
161
163
  },
@@ -24,7 +24,7 @@ function templateFiles(template, name, version) {
24
24
  scripts: { dev: "sinth dev", build: "sinth build", preview: "sinth preview", check: "sinth check", deploy: "sinth deploy" },
25
25
  devDependencies: { "@yannosay/sinth": `^${version.replace(/-.*$/, "")}` },
26
26
  }, null, 2) + "\n",
27
- ".gitignore": "node_modules/\ndist/\n.sinth/\n.wrangler/\n",
27
+ ".gitignore": "node_modules/\ndist/\n.sinth/\n.wrangler/\n.dev.vars\n.env\n",
28
28
  "README.md": `# ${name}\n\nBuilt with [Sinth](https://sinth.yannosay.com).\n\n\`\`\`bash\nnpm install\nnpm run dev # http://localhost:3000\nnpm run build # production build in dist/\nnpm run deploy # deploy to Cloudflare Pages\n\`\`\`\n`,
29
29
  "public/robots.txt": "User-agent: *\nAllow: /\n",
30
30
  };
@@ -145,7 +145,7 @@ descr = "About this site."
145
145
 
146
146
  Layout(current: "/about") {
147
147
  Heading(level: 1) { "About" }
148
- Paragraph { "This page is static, so Sinth ships it without any JavaScript." }
148
+ Paragraph { "This page is static: it is prerendered at build time and needs no code of its own." }
149
149
  }
150
150
  `;
151
151
  files["pages/404.sinth"] = `import { Layout } from "../components/Layout.sinth"
package/dist/cli/ui.d.ts CHANGED
@@ -12,7 +12,6 @@ export declare const c: {
12
12
  violet: (s: string) => string;
13
13
  underline: (s: string) => string;
14
14
  };
15
- export declare const colorEnabled: boolean;
16
15
  export declare function brand(label: string, version: string): string;
17
16
  export declare const log: {
18
17
  info: (msg: string) => void;
package/dist/cli/ui.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.log = exports.colorEnabled = exports.c = void 0;
3
+ exports.log = exports.c = void 0;
4
4
  exports.brand = brand;
5
5
  exports.printDiagnostic = printDiagnostic;
6
6
  exports.formatBytes = formatBytes;
@@ -22,7 +22,6 @@ exports.c = {
22
22
  violet: (s) => (enabled ? `\u001b[38;2;192;132;252m${s}\u001b[39m` : s),
23
23
  underline: wrap("4", "24"),
24
24
  };
25
- exports.colorEnabled = enabled;
26
25
  function brand(label, version) {
27
26
  return [exports.c.violet(exports.c.bold("Sinth")), label ? exports.c.bold(label) : "", exports.c.gray("v" + version)].filter(Boolean).join(" ");
28
27
  }
@@ -152,6 +152,17 @@ export type Stmt = {
152
152
  test: Expr;
153
153
  body: Stmt[];
154
154
  loc: Loc;
155
+ } | {
156
+ k: "try";
157
+ body: Stmt[];
158
+ param?: string;
159
+ handler?: Stmt[];
160
+ finalizer?: Stmt[];
161
+ loc: Loc;
162
+ } | {
163
+ k: "throw";
164
+ value: Expr;
165
+ loc: Loc;
155
166
  } | {
156
167
  k: "return";
157
168
  value?: Expr;
@@ -1,5 +1,5 @@
1
- import { Expr, ImportDecl, Param, SinthFile, Stmt, TypeRef, VarDecl } from "./ast";
2
- import { DiagnosticBag, Loc } from "./diagnostics";
1
+ import { ImportDecl, Param, SinthFile, Stmt, TypeRef, VarDecl } from "./ast";
2
+ import { DiagnosticBag } from "./diagnostics";
3
3
  import { isStatementExpr } from "./parser";
4
4
  import { ScssCompiler } from "./style";
5
5
  export interface ComponentSig {
@@ -52,92 +52,7 @@ export interface ModuleOutput {
52
52
  usesState: boolean;
53
53
  diagnostics: DiagnosticBag;
54
54
  }
55
- type BindingKind = "local" | "loop" | "param" | "state" | "computed" | "const" | "function" | "component" | "global" | "import";
56
- interface Binding {
57
- kind: BindingKind;
58
- js: string;
59
- type?: TypeRef;
60
- fn?: FunctionSig;
61
- comp?: ComponentSig;
62
- defaultValue?: Expr;
63
- bindable?: boolean;
64
- ref?: string;
65
- loc?: Loc;
66
- }
67
- declare class Scope {
68
- readonly parent: Scope | null;
69
- readonly kind: "module" | "component" | "function" | "block" | "loop";
70
- private readonly names;
71
- constructor(parent: Scope | null, kind?: "module" | "component" | "function" | "block" | "loop");
72
- define(name: string, b: Binding): void;
73
- has(name: string): boolean;
74
- lookup(name: string): Binding | undefined;
75
- all(): string[];
76
- inComponent(): boolean;
77
- }
78
55
  export declare function collectExports(file: SinthFile): ModuleExports;
79
- export declare class ModuleCompiler {
80
- private readonly file;
81
- private readonly imports;
82
- private readonly opts;
83
- private readonly out;
84
- private readonly css;
85
- private uid;
86
- private interactive;
87
- private uses;
88
- private readonly componentInfo;
89
- private usesState;
90
- readonly diagnostics: DiagnosticBag;
91
- private readonly moduleScope;
92
- private readonly importLines;
93
- private readonly exportsInfo;
94
- private readonly fileHash;
95
- private readonly pageCssVars;
96
- constructor(file: SinthFile, imports: ResolvedImport[], opts: CodegenOptions);
97
- private id;
98
- private fail;
99
- compile(): ModuleOutput;
100
- private persistKey;
101
- private checkDuplicate;
102
- private defineComponent;
103
- private declareImports;
104
- private resolveNamespacedComponent;
105
- private genVarDecl;
106
- private genFunction;
107
- private genParams;
108
- private genComponent;
109
- private genLifecycle;
110
- private addStyle;
111
- private genNodes;
112
- private genNode;
113
- private genText;
114
- private genUiCall;
115
- private isConstantExpr;
116
- private isStaticNode;
117
- private staticHtml;
118
- private headingTag;
119
- private elementShape;
120
- private isStyleProp;
121
- private genElement;
122
- private genRawHtml;
123
- private genDynamicAttrs;
124
- private genHandler;
125
- private genComponentUse;
126
- private genIf;
127
- private genFor;
128
- private stmts;
129
- private stmt;
130
- private calleeBinding;
131
- private unknownName;
132
- private resolveId;
133
- private bindingJs;
134
- private assignTarget;
135
- private genCallArgs;
136
- expr(e: Expr, scope: Scope): string;
137
- private checkBinary;
138
- inferType(e: Expr, scope: Scope): TypeRef | undefined;
139
- private checkAssignable;
140
- }
141
56
  export declare function containsAwait(stmts: Stmt[]): boolean;
142
57
  export declare function compileModule(file: SinthFile, imports: ResolvedImport[], opts: CodegenOptions): ModuleOutput;
143
58
  export { isStatementExpr };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isStatementExpr = exports.ModuleCompiler = void 0;
3
+ exports.isStatementExpr = void 0;
4
4
  exports.collectExports = collectExports;
5
5
  exports.containsAwait = containsAwait;
6
6
  exports.compileModule = compileModule;
@@ -42,6 +42,9 @@ class Scope {
42
42
  }
43
43
  }
44
44
  const T = (base, array = 0) => ({ base, array, nullable: false });
45
+ const MUTATING_METHODS = new Set([
46
+ "push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin", "set", "delete", "add", "clear",
47
+ ]);
45
48
  function typeName(t) {
46
49
  return t.base + "[]".repeat(t.array) + (t.nullable ? "?" : "");
47
50
  }
@@ -87,7 +90,6 @@ class ModuleCompiler {
87
90
  file;
88
91
  imports;
89
92
  opts;
90
- out = [];
91
93
  css = [];
92
94
  uid = 0;
93
95
  interactive = false;
@@ -943,6 +945,26 @@ class ModuleCompiler {
943
945
  }
944
946
  case "while":
945
947
  return `while (${this.expr(s.test, scope)}) {\n${indent(this.stmts(s.body, new Scope(scope), returnType))}\n}`;
948
+ case "try": {
949
+ let code = `try {
950
+ ${indent(this.stmts(s.body, new Scope(scope), returnType))}
951
+ }`;
952
+ if (s.handler) {
953
+ const inner = new Scope(scope);
954
+ if (s.param)
955
+ inner.define(s.param, { kind: "local", js: s.param });
956
+ code += ` catch${s.param ? ` (${s.param})` : ""} {
957
+ ${indent(this.stmts(s.handler, inner, returnType))}
958
+ }`;
959
+ }
960
+ if (s.finalizer)
961
+ code += ` finally {
962
+ ${indent(this.stmts(s.finalizer, new Scope(scope), returnType))}
963
+ }`;
964
+ return code;
965
+ }
966
+ case "throw":
967
+ return `throw ${this.expr(s.value, scope)};`;
946
968
  case "return":
947
969
  if (s.value && returnType && returnType.base !== "any") {
948
970
  if (returnType.base === "void")
@@ -956,6 +978,19 @@ class ModuleCompiler {
956
978
  return "continue;";
957
979
  }
958
980
  }
981
+ /**
982
+ * Whether writing to `target` can change what the page shows: true for state, parameters, loop
983
+ * items and local aliases of them, false for JavaScript globals and imported modules.
984
+ */
985
+ isTracked(target, scope) {
986
+ let root = target;
987
+ while (root.k === "member" || root.k === "index")
988
+ root = root.object;
989
+ if (root.k !== "id")
990
+ return false;
991
+ const kind = scope.lookup(root.name)?.kind;
992
+ return kind !== undefined && kind !== "global" && kind !== "import" && kind !== "function" && kind !== "component";
993
+ }
959
994
  calleeBinding(callee, scope) {
960
995
  if (callee.k === "id")
961
996
  return scope.lookup(callee.name);
@@ -1094,6 +1129,8 @@ class ModuleCompiler {
1094
1129
  if (!b?.fn && e.args.some(a => a.name))
1095
1130
  this.fail("E0316", "Named arguments are only supported for Sinth functions", e.args.find(a => a.name)?.loc);
1096
1131
  const call = `${callee}${e.optional ? "?." : ""}(${args})`;
1132
+ if (e.callee.k === "member" && MUTATING_METHODS.has(e.callee.prop) && this.isTracked(e.callee.object, scope))
1133
+ return `$$.changed(${call})`;
1097
1134
  if (e.memo)
1098
1135
  return `$$.memo(${JSON.stringify(this.fileHash + ":" + e.loc.line + ":" + e.loc.col)}, () => ${call}, [${args}])`;
1099
1136
  return call;
@@ -1115,6 +1152,7 @@ class ModuleCompiler {
1115
1152
  return `(${this.expr(e.test, scope)} ? ${this.expr(e.then, scope)} : ${this.expr(e.else, scope)})`;
1116
1153
  case "assign": {
1117
1154
  const target = this.assignTarget(e.target, scope, e.loc);
1155
+ const tracked = this.isTracked(e.target, scope);
1118
1156
  if (e.target.k === "id") {
1119
1157
  const t = this.resolveId(e.target.name, e.loc, scope).type;
1120
1158
  if (t) {
@@ -1127,10 +1165,14 @@ class ModuleCompiler {
1127
1165
  }
1128
1166
  }
1129
1167
  }
1130
- return `${target} ${e.op} ${this.expr(e.value, scope)}`;
1168
+ const assignment = `${target} ${e.op} ${this.expr(e.value, scope)}`;
1169
+ return tracked ? `$$.changed(${assignment})` : assignment;
1170
+ }
1171
+ case "update": {
1172
+ const target = this.assignTarget(e.target, scope, e.loc);
1173
+ const update = e.prefix ? `++${target}` : `${target}++`;
1174
+ return this.isTracked(e.target, scope) ? `$$.changed(${update})` : update;
1131
1175
  }
1132
- case "update":
1133
- return e.prefix ? `++${this.assignTarget(e.target, scope, e.loc)}` : `${this.assignTarget(e.target, scope, e.loc)}++`;
1134
1176
  case "array":
1135
1177
  return `[${e.items.map(i => (i.spread ? "..." : "") + this.expr(i.value, scope)).join(", ")}]`;
1136
1178
  case "object":
@@ -1258,7 +1300,6 @@ class ModuleCompiler {
1258
1300
  }
1259
1301
  }
1260
1302
  }
1261
- exports.ModuleCompiler = ModuleCompiler;
1262
1303
  function defaultFor(t) {
1263
1304
  if (!t)
1264
1305
  return "null";
@@ -1309,6 +1350,8 @@ function containsAwait(stmts) {
1309
1350
  case "if": return exprHasAwait(s.test) || containsAwait(s.then) || (!!s.else && containsAwait(s.else));
1310
1351
  case "for": return exprHasAwait(s.iter) || containsAwait(s.body);
1311
1352
  case "while": return exprHasAwait(s.test) || containsAwait(s.body);
1353
+ case "try": return containsAwait(s.body) || containsAwait(s.handler ?? []) || containsAwait(s.finalizer ?? []);
1354
+ case "throw": return exprHasAwait(s.value);
1312
1355
  case "return": return !!s.value && exprHasAwait(s.value);
1313
1356
  default: return false;
1314
1357
  }
@@ -15,7 +15,6 @@ export interface Diagnostic {
15
15
  hint?: string;
16
16
  }
17
17
  export declare function registerSource(file: string, source: string): void;
18
- export declare function getSource(file: string): string | undefined;
19
18
  export declare class SinthError extends Error {
20
19
  readonly diagnostic: Diagnostic;
21
20
  constructor(code: string, message: string, loc?: Span, hint?: string);
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DiagnosticBag = exports.SinthError = void 0;
4
4
  exports.registerSource = registerSource;
5
- exports.getSource = getSource;
6
5
  exports.codeFrame = codeFrame;
7
6
  exports.setDisplayRoot = setDisplayRoot;
8
7
  exports.formatDiagnostic = formatDiagnostic;
@@ -12,9 +11,6 @@ const sourceCache = new Map();
12
11
  function registerSource(file, source) {
13
12
  sourceCache.set(file, source);
14
13
  }
15
- function getSource(file) {
16
- return sourceCache.get(file);
17
- }
18
14
  class SinthError extends Error {
19
15
  diagnostic;
20
16
  constructor(code, message, loc, hint) {
@@ -16,6 +16,8 @@ export interface HeadData {
16
16
  htmlClass?: string;
17
17
  metaNames: [string, string][];
18
18
  metaProps: [string, string][];
19
+ /** Structured data, emitted as <script type="application/ld+json">. */
20
+ jsonLd: string[];
19
21
  }
20
22
  export interface MetaValue {
21
23
  key: string;
@@ -28,7 +28,7 @@ const NAME_MAP = {
28
28
  };
29
29
  function buildHead(meta, resolveAsset) {
30
30
  const head = {
31
- lang: "en", charset: "utf-8", viewport: "width=device-width, initial-scale=1", metaNames: [], metaProps: [],
31
+ lang: "en", charset: "utf-8", viewport: "width=device-width, initial-scale=1", metaNames: [], metaProps: [], jsonLd: [],
32
32
  };
33
33
  for (const m of meta) {
34
34
  if (!m.known) {
@@ -36,6 +36,12 @@ function buildHead(meta, resolveAsset) {
36
36
  }
37
37
  if (m.value === null || m.value === undefined || m.value === false)
38
38
  continue;
39
+ if (m.key === "jsonLd") {
40
+ if (typeof m.value !== "object")
41
+ throw new diagnostics_1.SinthError("E0701", "Metadata 'jsonLd' must be an object or an array of objects", m.loc);
42
+ head.jsonLd.push(JSON.stringify(m.value).replace(/</g, "\\u003c"));
43
+ continue;
44
+ }
39
45
  if (typeof m.value === "object")
40
46
  throw new diagnostics_1.SinthError("E0701", `Metadata '${m.key}' must be a string, number or boolean`, m.loc);
41
47
  const value = String(m.value);
@@ -95,6 +101,8 @@ function buildHead(meta, resolveAsset) {
95
101
  head.metaProps.push(["og:description", description]);
96
102
  if (!has(head.metaProps, "og:type"))
97
103
  head.metaProps.push(["og:type", "website"]);
104
+ if (!has(head.metaNames, "generator"))
105
+ head.metaNames.push(["generator", "Sinth"]);
98
106
  if (!has(head.metaNames, "twitter:card"))
99
107
  head.metaNames.push(["twitter:card", has(head.metaProps, "og:image") ? "summary_large_image" : "summary"]);
100
108
  return head;
@@ -134,6 +142,8 @@ function renderDocument(head, body, assets) {
134
142
  lines.push(`<link rel="apple-touch-icon" href="${escapeAttr(head.appleTouchIcon)}">`);
135
143
  if (head.manifest)
136
144
  lines.push(`<link rel="manifest" href="${escapeAttr(head.manifest)}">`);
145
+ for (const data of head.jsonLd)
146
+ lines.push(`<script type="application/ld+json">${data}</script>`);
137
147
  for (const href of assets.preloads)
138
148
  lines.push(`<link rel="modulepreload" href="${escapeAttr(href)}">`);
139
149
  for (const href of assets.styles)
@@ -87,6 +87,9 @@ class Lexer {
87
87
  this.advance();
88
88
  }
89
89
  else if (c === "-" && this.peekChar(1) === "-") {
90
+ if (/[\w)\]]/.test(this.src[this.pos - 1] ?? "") && /^--\s*[;)}\n]|^--$/.test(this.src.slice(this.pos, this.pos + 4).replace(/\r/g, ""))) {
91
+ throw new diagnostics_1.SinthError("E0001", "'--' starts a comment in Sinth, so it cannot decrement", { ...this.here(), length: 2 }, "Write 'x -= 1' instead of 'x--'");
92
+ }
90
93
  if (this.peekChar(2) === "[")
91
94
  this.skipBlockComment();
92
95
  else
@@ -181,8 +184,12 @@ class Lexer {
181
184
  return true;
182
185
  if (prev.kind === "raw")
183
186
  return true;
184
- if (prev.kind === "punct")
185
- return prev.value === "{" || prev.value === "}" || prev.value === ";";
187
+ if (prev.kind === "punct") {
188
+ if (prev.value === "{" || prev.value === "}" || prev.value === ";")
189
+ return true;
190
+ // `var x = f()` or `var xs = [1]` followed by a block on the next line.
191
+ return this.sawNewline && (prev.value === ")" || prev.value === "]");
192
+ }
186
193
  return this.sawNewline && (prev.kind === "string" || prev.kind === "number" || prev.kind === "ident" || prev.kind === "template");
187
194
  }
188
195
  readNumber(loc, start) {
@@ -10,7 +10,7 @@ const diagnostics_1 = require("./diagnostics");
10
10
  const lexer_1 = require("./lexer");
11
11
  exports.META_KEYS = new Set([
12
12
  "title", "descr", "description", "fav", "favicon", "lang", "charset", "viewport", "author", "keywords", "robots",
13
- "themeColor", "colorScheme", "canonical", "generator", "manifest", "appleTouchIcon", "base", "bodyClass", "htmlClass", "paths",
13
+ "themeColor", "colorScheme", "canonical", "generator", "manifest", "appleTouchIcon", "base", "bodyClass", "htmlClass", "paths", "jsonLd",
14
14
  ]);
15
15
  function isMetaKey(key) {
16
16
  return exports.META_KEYS.has(key) || /^(og|twitter)[A-Z]/.test(key);
@@ -932,6 +932,32 @@ class Parser {
932
932
  const test = this.parseExpr();
933
933
  return { k: "while", test, body: this.parseStmtBlock(), loc: t.loc };
934
934
  }
935
+ case "try": {
936
+ this.next();
937
+ const body = this.parseStmtBlock();
938
+ let param;
939
+ let handler;
940
+ let finalizer;
941
+ if (this.eatIdent("catch")) {
942
+ if (this.isPunct("(")) {
943
+ this.next();
944
+ param = this.expectIdent("a name for the caught error").value;
945
+ this.expect(")", "after the caught error name");
946
+ }
947
+ else if (this.tok.kind === "ident") {
948
+ param = this.expectIdent("a name for the caught error").value;
949
+ }
950
+ handler = this.parseStmtBlock();
951
+ }
952
+ if (this.eatIdent("finally"))
953
+ finalizer = this.parseStmtBlock();
954
+ if (!handler && !finalizer)
955
+ this.fail("'try' needs a 'catch' or 'finally' block", t);
956
+ return { k: "try", body, param, handler, finalizer, loc: t.loc };
957
+ }
958
+ case "throw":
959
+ this.next();
960
+ return { k: "throw", value: this.parseExpr(), loc: t.loc };
935
961
  case "return": {
936
962
  this.next();
937
963
  if (this.isPunct("}") || this.isPunct(";") || this.tok.newlineBefore || this.tok.kind === "eof" || this.atAttrBoundary()) {
@@ -236,6 +236,10 @@ class Prerenderer {
236
236
  }
237
237
  return;
238
238
  }
239
+ case "try":
240
+ case "throw":
241
+ // Error handling depends on runtime failures, so it is left to the browser.
242
+ throw new ReturnSignal(UNKNOWN);
239
243
  case "return":
240
244
  throw new ReturnSignal(s.value ? this.eval(s.value, env, file) : undefined);
241
245
  case "break":
package/dist/index.d.ts CHANGED
@@ -11,3 +11,5 @@ export { Project } from "./project/project";
11
11
  export { buildProject, checkProject } from "./project/build";
12
12
  export type { BuildOutput } from "./project/build";
13
13
  export type * from "./compiler/ast";
14
+ export { compileFiles } from "./browser/compile";
15
+ export type { CompileFilesOptions, CompileFilesResult, CompiledModule } from "./browser/compile";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkProject = exports.buildProject = exports.Project = exports.loadConfig = exports.compileStyle = exports.formatDiagnostic = exports.SinthError = exports.collectExports = exports.compileModule = exports.tokenize = exports.Parser = exports.parseSinth = void 0;
3
+ exports.compileFiles = exports.checkProject = exports.buildProject = exports.Project = exports.loadConfig = exports.compileStyle = exports.formatDiagnostic = exports.SinthError = exports.collectExports = exports.compileModule = exports.tokenize = exports.Parser = exports.parseSinth = void 0;
4
4
  var parser_1 = require("./compiler/parser");
5
5
  Object.defineProperty(exports, "parseSinth", { enumerable: true, get: function () { return parser_1.parseSinth; } });
6
6
  Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_1.Parser; } });
@@ -21,3 +21,5 @@ Object.defineProperty(exports, "Project", { enumerable: true, get: function () {
21
21
  var build_1 = require("./project/build");
22
22
  Object.defineProperty(exports, "buildProject", { enumerable: true, get: function () { return build_1.buildProject; } });
23
23
  Object.defineProperty(exports, "checkProject", { enumerable: true, get: function () { return build_1.checkProject; } });
24
+ var compile_1 = require("./browser/compile");
25
+ Object.defineProperty(exports, "compileFiles", { enumerable: true, get: function () { return compile_1.compileFiles; } });
@@ -1,3 +1,4 @@
1
+ import * as esbuild from "esbuild";
1
2
  import { Diagnostic, SinthError } from "../compiler/diagnostics";
2
3
  import { CompiledPage, PageInfo, Project } from "./project";
3
4
  export interface OutputFile {
@@ -22,6 +23,11 @@ export interface BuildOptions {
22
23
  write: boolean;
23
24
  devClient?: string;
24
25
  }
26
+ /**
27
+ * Bundles every component declared `as <tag-name>` into a standalone script per tag, plus
28
+ * `elements/index.js` that registers all of them, for use in any HTML page.
29
+ */
30
+ export declare function buildCustomElements(project: Project): Promise<esbuild.OutputFile[]>;
25
31
  export declare function contentSecurityPolicy(pages: CompiledPage[], custom: boolean | string): string | undefined;
26
32
  export declare function buildProject(project: Project, options: BuildOptions): Promise<BuildOutput>;
27
33
  export declare function checkProject(project: Project): {