@yannosay/sinth 4.1.0 → 5.1.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 (78) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/DOCS.md +1359 -0
  3. package/README.md +83 -74
  4. package/bin/sinth.js +2 -1
  5. package/dist/cli/args.d.ts +11 -0
  6. package/dist/cli/args.js +74 -0
  7. package/dist/cli/index.d.ts +1 -0
  8. package/dist/cli/index.js +437 -0
  9. package/dist/cli/templates.d.ts +10 -0
  10. package/dist/cli/templates.js +193 -0
  11. package/dist/cli/ui.d.ts +28 -0
  12. package/dist/cli/ui.js +61 -0
  13. package/dist/cli/update-check.d.ts +2 -0
  14. package/dist/cli/update-check.js +124 -0
  15. package/dist/compiler/ast.d.ts +315 -0
  16. package/dist/compiler/ast.js +4 -0
  17. package/dist/compiler/codegen.d.ts +143 -0
  18. package/dist/compiler/codegen.js +1326 -0
  19. package/dist/compiler/diagnostics.d.ts +36 -0
  20. package/dist/compiler/diagnostics.js +142 -0
  21. package/dist/compiler/elements.d.ts +14 -0
  22. package/dist/compiler/elements.js +78 -0
  23. package/dist/compiler/globals.d.ts +2 -0
  24. package/dist/compiler/globals.js +27 -0
  25. package/dist/compiler/html.d.ts +37 -0
  26. package/dist/compiler/html.js +152 -0
  27. package/dist/compiler/lexer.d.ts +42 -0
  28. package/dist/compiler/lexer.js +404 -0
  29. package/dist/compiler/parser.d.ts +95 -0
  30. package/dist/compiler/parser.js +1374 -0
  31. package/dist/compiler/prerender.d.ts +72 -0
  32. package/dist/compiler/prerender.js +910 -0
  33. package/dist/compiler/script-analysis.d.ts +6 -0
  34. package/dist/compiler/script-analysis.js +106 -0
  35. package/dist/compiler/style.d.ts +39 -0
  36. package/dist/compiler/style.js +463 -0
  37. package/dist/deploy/cloudflare.d.ts +9 -0
  38. package/dist/deploy/cloudflare.js +111 -0
  39. package/dist/index.d.ts +13 -0
  40. package/dist/index.js +23 -0
  41. package/dist/project/build.d.ts +31 -0
  42. package/dist/project/build.js +425 -0
  43. package/dist/project/config.d.ts +33 -0
  44. package/dist/project/config.js +142 -0
  45. package/dist/project/project.d.ts +74 -0
  46. package/dist/project/project.js +535 -0
  47. package/dist/runtime/index.d.ts +68 -0
  48. package/dist/runtime/index.js +912 -0
  49. package/dist/server/client.d.ts +1 -0
  50. package/dist/server/client.js +112 -0
  51. package/dist/server/dev.d.ts +8 -0
  52. package/dist/server/dev.js +244 -0
  53. package/dist/server/preview.d.ts +6 -0
  54. package/dist/server/preview.js +106 -0
  55. package/dist/server/static.d.ts +10 -0
  56. package/dist/server/static.js +136 -0
  57. package/lib/ui/index.sinth +436 -0
  58. package/package.json +33 -15
  59. package/schema/sinth.config.schema.json +54 -0
  60. package/dist/browser/compile.js +0 -63
  61. package/dist/cli.js +0 -509
  62. package/dist/core/builtins.js +0 -117
  63. package/dist/core/cli-compiler.js +0 -705
  64. package/dist/core/compiler.js +0 -1489
  65. package/dist/core/expr.js +0 -129
  66. package/dist/core/head-builder.js +0 -130
  67. package/dist/core/lexer.js +0 -410
  68. package/dist/core/parser.js +0 -1646
  69. package/dist/core/runtime/custom-element.js +0 -81
  70. package/dist/core/runtime/functions.js +0 -99
  71. package/dist/core/runtime/helpers.js +0 -347
  72. package/dist/core/runtime/render.js +0 -136
  73. package/dist/core/style-processor.js +0 -317
  74. package/dist/core/types.js +0 -93
  75. package/dist/resolver.js +0 -175
  76. package/dist/server.js +0 -174
  77. package/dist/update-check.js +0 -109
  78. package/dist/utils.js +0 -80
@@ -0,0 +1,404 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Lexer = void 0;
4
+ exports.tokenize = tokenize;
5
+ const diagnostics_1 = require("./diagnostics");
6
+ const PUNCTUATORS = [
7
+ "...", "**=", "??=", "&&=", "||=",
8
+ "=>", "->", "==", "!=", "<=", ">=", "&&", "||", "??", "?.", "+=", "-=", "*=", "/=", "%=", "++", "**",
9
+ "+", "-", "*", "/", "%", "=", "<", ">", "!", "?", ":", ".", ",", ";", "(", ")", "{", "}", "[", "]", "&", "|", "^", "~", "@", "#",
10
+ ];
11
+ const RAW_BLOCK_KEYWORDS = new Set(["style", "script"]);
12
+ function isIdentStart(c) {
13
+ return /[A-Za-z_$À-￿]/.test(c);
14
+ }
15
+ function isIdentPart(c) {
16
+ return /[A-Za-z0-9_$À-￿]/.test(c);
17
+ }
18
+ function isDigit(c) {
19
+ return c >= "0" && c <= "9";
20
+ }
21
+ class Lexer {
22
+ src;
23
+ file;
24
+ baseLoc;
25
+ pos = 0;
26
+ line = 1;
27
+ col = 1;
28
+ sawNewline = false;
29
+ rawPending = false;
30
+ tokens = [];
31
+ constructor(src, file, baseLoc) {
32
+ this.src = src;
33
+ this.file = file;
34
+ this.baseLoc = baseLoc;
35
+ }
36
+ tokenize() {
37
+ for (;;) {
38
+ this.skipTrivia();
39
+ if (this.pos >= this.src.length)
40
+ break;
41
+ const tok = this.next();
42
+ this.tokens.push(tok);
43
+ this.sawNewline = false;
44
+ }
45
+ this.tokens.push(this.make("eof", "", this.here(), this.pos));
46
+ return this.tokens;
47
+ }
48
+ here() {
49
+ if (this.baseLoc) {
50
+ return {
51
+ file: this.file,
52
+ line: this.baseLoc.line + this.line - 1,
53
+ col: this.line === 1 ? this.baseLoc.col + this.col - 1 : this.col,
54
+ };
55
+ }
56
+ return { file: this.file, line: this.line, col: this.col };
57
+ }
58
+ make(kind, value, loc, start, extra) {
59
+ return { kind, value, loc, start, end: this.pos, newlineBefore: this.sawNewline, ...extra };
60
+ }
61
+ advance(n = 1) {
62
+ for (let i = 0; i < n && this.pos < this.src.length; i++) {
63
+ if (this.src[this.pos] === "\n") {
64
+ this.line++;
65
+ this.col = 1;
66
+ }
67
+ else {
68
+ this.col++;
69
+ }
70
+ this.pos++;
71
+ }
72
+ }
73
+ peekChar(offset = 0) {
74
+ return this.src[this.pos + offset] ?? "";
75
+ }
76
+ fail(message, loc = this.here()) {
77
+ throw new diagnostics_1.SinthError("E0001", message, loc);
78
+ }
79
+ skipTrivia() {
80
+ while (this.pos < this.src.length) {
81
+ const c = this.peekChar();
82
+ if (c === "\n") {
83
+ this.sawNewline = true;
84
+ this.advance();
85
+ }
86
+ else if (c === " " || c === "\t" || c === "\r" || c === "") {
87
+ this.advance();
88
+ }
89
+ else if (c === "-" && this.peekChar(1) === "-") {
90
+ if (this.peekChar(2) === "[")
91
+ this.skipBlockComment();
92
+ else
93
+ while (this.pos < this.src.length && this.peekChar() !== "\n")
94
+ this.advance();
95
+ }
96
+ else if (c === "/" && this.peekChar(1) === "/") {
97
+ while (this.pos < this.src.length && this.peekChar() !== "\n")
98
+ this.advance();
99
+ }
100
+ else if (c === "/" && this.peekChar(1) === "*") {
101
+ const loc = this.here();
102
+ this.advance(2);
103
+ while (this.pos < this.src.length && !(this.peekChar() === "*" && this.peekChar(1) === "/"))
104
+ this.advance();
105
+ if (this.pos >= this.src.length)
106
+ this.fail("Unterminated block comment '/* ... */'", loc);
107
+ this.advance(2);
108
+ }
109
+ else {
110
+ break;
111
+ }
112
+ }
113
+ }
114
+ skipBlockComment() {
115
+ const loc = this.here();
116
+ this.advance(3);
117
+ let depth = 1;
118
+ while (this.pos < this.src.length && depth > 0) {
119
+ if (this.peekChar() === "-" && this.peekChar(1) === "-" && this.peekChar(2) === "[") {
120
+ depth++;
121
+ this.advance(3);
122
+ }
123
+ else if (this.peekChar() === "]" && this.peekChar(1) === "-" && this.peekChar(2) === "-") {
124
+ depth--;
125
+ this.advance(3);
126
+ }
127
+ else {
128
+ this.advance();
129
+ }
130
+ }
131
+ if (depth > 0)
132
+ this.fail("Unterminated block comment '--[ ... ]--'", loc);
133
+ }
134
+ next() {
135
+ const loc = this.here();
136
+ const start = this.pos;
137
+ const c = this.peekChar();
138
+ if (c === "{" && this.rawPending) {
139
+ this.rawPending = false;
140
+ return this.readRawBlock(loc, start);
141
+ }
142
+ if ((c === "f" || c === "F") && (this.peekChar(1) === '"' || this.peekChar(1) === "'")) {
143
+ this.advance();
144
+ return this.readString(loc, start, true);
145
+ }
146
+ if (c === '"' || c === "'")
147
+ return this.readString(loc, start, false);
148
+ if (c === "`")
149
+ return this.readTemplate(loc, start);
150
+ if (isDigit(c) || (c === "." && isDigit(this.peekChar(1))))
151
+ return this.readNumber(loc, start);
152
+ if (isIdentStart(c))
153
+ return this.readIdent(loc, start);
154
+ for (const p of PUNCTUATORS) {
155
+ if (this.src.startsWith(p, this.pos)) {
156
+ this.advance(p.length);
157
+ return this.make("punct", p, loc, start);
158
+ }
159
+ }
160
+ return this.fail(`Unexpected character '${c}'`, loc);
161
+ }
162
+ readIdent(loc, start) {
163
+ while (this.pos < this.src.length && isIdentPart(this.peekChar()))
164
+ this.advance();
165
+ let value = this.src.slice(start, this.pos);
166
+ if (value === "custom" && this.src.startsWith("-element", this.pos)) {
167
+ this.advance(8);
168
+ value = "custom-element";
169
+ }
170
+ if (RAW_BLOCK_KEYWORDS.has(value) && this.atStatementStart()) {
171
+ const after = this.src.slice(this.pos).match(/^[ \t]*(\S)/);
172
+ const nextChar = after?.[1] ?? "";
173
+ if (nextChar !== ":" && nextChar !== "=" && nextChar !== "." && nextChar !== "(" && nextChar !== ",")
174
+ this.rawPending = true;
175
+ }
176
+ return this.make("ident", value, loc, start);
177
+ }
178
+ atStatementStart() {
179
+ const prev = this.tokens[this.tokens.length - 1];
180
+ if (!prev)
181
+ return true;
182
+ if (prev.kind === "raw")
183
+ return true;
184
+ if (prev.kind === "punct")
185
+ return prev.value === "{" || prev.value === "}" || prev.value === ";";
186
+ return this.sawNewline && (prev.kind === "string" || prev.kind === "number" || prev.kind === "ident" || prev.kind === "template");
187
+ }
188
+ readNumber(loc, start) {
189
+ if (this.peekChar() === "0" && /[xXbBoO]/.test(this.peekChar(1))) {
190
+ this.advance(2);
191
+ while (/[0-9a-fA-F_]/.test(this.peekChar()))
192
+ this.advance();
193
+ }
194
+ else {
195
+ while (isDigit(this.peekChar()) || this.peekChar() === "_")
196
+ this.advance();
197
+ if (this.peekChar() === "." && isDigit(this.peekChar(1))) {
198
+ this.advance();
199
+ while (isDigit(this.peekChar()) || this.peekChar() === "_")
200
+ this.advance();
201
+ }
202
+ if (/[eE]/.test(this.peekChar()) && (isDigit(this.peekChar(1)) || (/[+-]/.test(this.peekChar(1)) && isDigit(this.peekChar(2))))) {
203
+ this.advance(2);
204
+ while (isDigit(this.peekChar()))
205
+ this.advance();
206
+ }
207
+ }
208
+ const raw = this.src.slice(start, this.pos).replace(/_/g, "");
209
+ if (Number.isNaN(Number(raw)))
210
+ this.fail(`Invalid number literal '${raw}'`, loc);
211
+ return this.make("number", raw, loc, start);
212
+ }
213
+ readEscape(loc) {
214
+ this.advance();
215
+ const e = this.peekChar();
216
+ this.advance();
217
+ switch (e) {
218
+ case "n": return "\n";
219
+ case "r": return "\r";
220
+ case "t": return "\t";
221
+ case "0": return "\0";
222
+ case "b": return "\b";
223
+ case "f": return "\f";
224
+ case "v": return "\v";
225
+ case "\\":
226
+ case '"':
227
+ case "'":
228
+ case "`":
229
+ case "$":
230
+ case "{":
231
+ case "}": return e;
232
+ case "\n": return "";
233
+ case "x": {
234
+ const hex = this.src.slice(this.pos, this.pos + 2);
235
+ if (!/^[0-9a-fA-F]{2}$/.test(hex))
236
+ this.fail("Invalid \\x escape sequence", loc);
237
+ this.advance(2);
238
+ return String.fromCharCode(parseInt(hex, 16));
239
+ }
240
+ case "u": {
241
+ if (this.peekChar() === "{") {
242
+ const close = this.src.indexOf("}", this.pos);
243
+ const hex = close === -1 ? "" : this.src.slice(this.pos + 1, close);
244
+ if (!/^[0-9a-fA-F]{1,6}$/.test(hex) || parseInt(hex, 16) > 0x10ffff)
245
+ this.fail("Invalid \\u{...} escape sequence", loc);
246
+ this.advance(hex.length + 2);
247
+ return String.fromCodePoint(parseInt(hex, 16));
248
+ }
249
+ const hex = this.src.slice(this.pos, this.pos + 4);
250
+ if (!/^[0-9a-fA-F]{4}$/.test(hex))
251
+ this.fail("Invalid \\u escape sequence", loc);
252
+ this.advance(4);
253
+ return String.fromCharCode(parseInt(hex, 16));
254
+ }
255
+ default:
256
+ return this.fail(`Unknown escape sequence '\\${e}'`, loc);
257
+ }
258
+ }
259
+ readString(loc, start, formatted) {
260
+ const quote = this.peekChar();
261
+ this.advance();
262
+ let value = "";
263
+ while (this.pos < this.src.length && this.peekChar() !== quote) {
264
+ const c = this.peekChar();
265
+ if (c === "\n")
266
+ this.fail("Unterminated string literal (strings cannot span lines; use \\n or a `template`)", loc);
267
+ if (c === "\\") {
268
+ if (formatted && (this.peekChar(1) === "{" || this.peekChar(1) === "}")) {
269
+ value += "\\" + this.peekChar(1);
270
+ this.advance(2);
271
+ continue;
272
+ }
273
+ value += this.readEscape(loc);
274
+ continue;
275
+ }
276
+ value += c;
277
+ this.advance();
278
+ }
279
+ if (this.pos >= this.src.length)
280
+ this.fail("Unterminated string literal", loc);
281
+ this.advance();
282
+ if (formatted)
283
+ return this.make("template", value, loc, start, { quote, formatted: true });
284
+ return this.make("string", value, loc, start, { quote });
285
+ }
286
+ readTemplate(loc, start) {
287
+ this.advance();
288
+ let value = "";
289
+ while (this.pos < this.src.length && this.peekChar() !== "`") {
290
+ const c = this.peekChar();
291
+ if (c === "\\") {
292
+ if (this.peekChar(1) === "$" || this.peekChar(1) === "{" || this.peekChar(1) === "}") {
293
+ value += "\\" + this.peekChar(1);
294
+ this.advance(2);
295
+ continue;
296
+ }
297
+ value += this.readEscape(loc);
298
+ continue;
299
+ }
300
+ if (c === "$" && this.peekChar(1) === "{") {
301
+ let depth = 0;
302
+ const exprStart = this.pos;
303
+ this.advance();
304
+ do {
305
+ const ch = this.peekChar();
306
+ if (ch === "{")
307
+ depth++;
308
+ else if (ch === "}")
309
+ depth--;
310
+ this.advance();
311
+ } while (depth > 0 && this.pos < this.src.length);
312
+ value += "{" + this.src.slice(exprStart + 2, this.pos - 1) + "}";
313
+ continue;
314
+ }
315
+ if (c === "{" || c === "}") {
316
+ value += "\\" + c;
317
+ this.advance();
318
+ continue;
319
+ }
320
+ value += c;
321
+ this.advance();
322
+ }
323
+ if (this.pos >= this.src.length)
324
+ this.fail("Unterminated template literal", loc);
325
+ this.advance();
326
+ return this.make("template", value, loc, start, { quote: "`", formatted: true });
327
+ }
328
+ readRawBlock(loc, start) {
329
+ this.advance();
330
+ const contentStart = this.pos;
331
+ let depth = 1;
332
+ while (this.pos < this.src.length) {
333
+ const c = this.peekChar();
334
+ if (c === '"' || c === "'" || c === "`") {
335
+ this.skipQuoted(c);
336
+ continue;
337
+ }
338
+ if (c === "/" && this.peekChar(1) === "/" && (this.pos === contentStart || /\s|[;{}]/.test(this.src[this.pos - 1]))) {
339
+ while (this.pos < this.src.length && this.peekChar() !== "\n")
340
+ this.advance();
341
+ continue;
342
+ }
343
+ if (c === "/" && this.peekChar(1) === "*") {
344
+ this.advance(2);
345
+ while (this.pos < this.src.length && !(this.peekChar() === "*" && this.peekChar(1) === "/"))
346
+ this.advance();
347
+ this.advance(2);
348
+ continue;
349
+ }
350
+ if (c === "-" && this.peekChar(1) === "-" && this.peekChar(2) === "[") {
351
+ this.skipBlockComment();
352
+ continue;
353
+ }
354
+ if (c === "{")
355
+ depth++;
356
+ if (c === "}") {
357
+ depth--;
358
+ if (depth === 0)
359
+ break;
360
+ }
361
+ this.advance();
362
+ }
363
+ if (depth !== 0)
364
+ this.fail("Unterminated block: missing '}'", loc);
365
+ const content = this.src.slice(contentStart, this.pos);
366
+ this.advance();
367
+ const bodyLoc = { ...loc, col: loc.col + 1 };
368
+ return this.make("raw", content, bodyLoc, start);
369
+ }
370
+ skipQuoted(quote) {
371
+ this.advance();
372
+ while (this.pos < this.src.length) {
373
+ const c = this.peekChar();
374
+ if (c === "\\") {
375
+ this.advance(2);
376
+ continue;
377
+ }
378
+ if (c === quote) {
379
+ this.advance();
380
+ return;
381
+ }
382
+ if (c === "\n" && quote !== "`")
383
+ return;
384
+ if (quote === "`" && c === "$" && this.peekChar(1) === "{") {
385
+ this.advance(2);
386
+ let depth = 1;
387
+ while (this.pos < this.src.length && depth > 0) {
388
+ const ch = this.peekChar();
389
+ if (ch === "{")
390
+ depth++;
391
+ else if (ch === "}")
392
+ depth--;
393
+ this.advance();
394
+ }
395
+ continue;
396
+ }
397
+ this.advance();
398
+ }
399
+ }
400
+ }
401
+ exports.Lexer = Lexer;
402
+ function tokenize(src, file, baseLoc) {
403
+ return new Lexer(src, file, baseLoc).tokenize();
404
+ }
@@ -0,0 +1,95 @@
1
+ import { Expr, FunctionDecl, ImportKind, Lifecycle, Node, ScriptBlock, SinthFile, Stmt, StyleBlock, TypeRef, VarDecl, Watcher } from "./ast";
2
+ import { Token } from "./lexer";
3
+ export declare const META_KEYS: ReadonlySet<string>;
4
+ export declare function isMetaKey(key: string): boolean;
5
+ type BodyOwner = {
6
+ vars: VarDecl[];
7
+ functions: FunctionDecl[];
8
+ styles: StyleBlock[];
9
+ scripts: ScriptBlock[];
10
+ lifecycle: Lifecycle[];
11
+ watchers: Watcher[];
12
+ };
13
+ export declare class Parser {
14
+ private readonly source;
15
+ private readonly file;
16
+ private pos;
17
+ private readonly tokens;
18
+ constructor(source: string, file: string);
19
+ static fromTokens(tokens: Token[], file: string): Parser;
20
+ private peek;
21
+ private get tok();
22
+ private next;
23
+ private isPunct;
24
+ private isIdent;
25
+ private eat;
26
+ private eatIdent;
27
+ private describe;
28
+ private fail;
29
+ private expect;
30
+ private expectIdent;
31
+ private sameLine;
32
+ private adjacent;
33
+ parseFile(): SinthFile;
34
+ private tryParseOwnerItem;
35
+ private parseWatch;
36
+ private peekPastModifiersIsRaw;
37
+ private parseImport;
38
+ private parseImportSpecifiers;
39
+ private parseImportAttrs;
40
+ parseTypeRef(): TypeRef;
41
+ private looksLikeType;
42
+ private parseVarDecl;
43
+ private checkName;
44
+ private parseParams;
45
+ private parseFunction;
46
+ private parseComponent;
47
+ private parseTagLiteral;
48
+ private parseLegacyCustomElement;
49
+ private parseStyle;
50
+ private parseScript;
51
+ parseNodesUntilClose(owner: BodyOwner, allowReturn: boolean): Node[];
52
+ private startsElement;
53
+ private parseNode;
54
+ private parseSlotOutlet;
55
+ private parseElement;
56
+ private parseSlotFill;
57
+ private parseAttrName;
58
+ private parseAttrs;
59
+ private atAttrBoundary;
60
+ private parseHandler;
61
+ private parseIfNode;
62
+ private parseIfModifiers;
63
+ private parseNodeBlock;
64
+ private parseLoopHead;
65
+ private loopHeadIsParenthesized;
66
+ private parseForNode;
67
+ parseStmtBlock(): Stmt[];
68
+ private parseStmt;
69
+ parseExpr(): Expr;
70
+ private parseAssign;
71
+ private tryParseArrow;
72
+ private parseArrowBody;
73
+ private parseTernary;
74
+ private binaryLevel;
75
+ private parseNullish;
76
+ private parseOr;
77
+ private parseAnd;
78
+ private parseEquality;
79
+ private parseRelational;
80
+ private parseAdditive;
81
+ private parseMultiplicative;
82
+ private parseExponent;
83
+ private parseUnary;
84
+ private parsePostfix;
85
+ private parseArgs;
86
+ private parseCallMember;
87
+ private parsePrimary;
88
+ private parseArray;
89
+ private parseObject;
90
+ private parseTemplate;
91
+ }
92
+ export declare function isStatementExpr(expr: Expr): boolean;
93
+ export declare function classifyImport(source: string): ImportKind;
94
+ export declare function parseSinth(source: string, file: string): SinthFile;
95
+ export {};