@yannosay/sinth 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/sinth.js +1 -1
- package/package.json +1 -2
- package/src/sinth.ts +18 -12
package/bin/sinth.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yannosay/sinth",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "A declarative language that compiles to pure HTML, CSS, and JavaScript.",
|
|
5
5
|
"author": "Yannosay Productions",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"LICENSE"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@yannosay/sinth": "^0.0.9",
|
|
36
35
|
"sass": "^1.70.0",
|
|
37
36
|
"ts-node": "^10.9.0"
|
|
38
37
|
},
|
package/src/sinth.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Sinth Compiler
|
|
3
|
-
// Single-file TypeScript compiler for the Sinth declarative web language.
|
|
4
|
-
// Run with: npx ts-node sinth.ts build | sinth build | sinth dev
|
|
2
|
+
// Sinth Compiler
|
|
5
3
|
|
|
6
4
|
import * as fs from "fs";
|
|
7
5
|
import * as path from "path";
|
|
@@ -10,7 +8,6 @@ import * as http from "http";
|
|
|
10
8
|
|
|
11
9
|
interface Loc { file: string; line: number; col: number }
|
|
12
10
|
|
|
13
|
-
// plain `enum TT` so TT[t] string-indexing works at runtime.
|
|
14
11
|
enum TT {
|
|
15
12
|
LBRACE, RBRACE, LPAREN, RPAREN, COLON, COMMA, EQUALS, DOT,
|
|
16
13
|
LBRACKET, RBRACKET,
|
|
@@ -168,7 +165,6 @@ class SinthWarning {
|
|
|
168
165
|
}
|
|
169
166
|
}
|
|
170
167
|
|
|
171
|
-
// FNV-1a 32-bit hash → 8-char hex scope id
|
|
172
168
|
function fnv1a(s: string): string {
|
|
173
169
|
let h = 0x811c9dc5;
|
|
174
170
|
for (let i = 0; i < s.length; i++) {
|
|
@@ -184,7 +180,6 @@ function camelToKebab(s: string): string {
|
|
|
184
180
|
return s.replace(/([A-Z])/g, m => `-${m.toLowerCase()}`);
|
|
185
181
|
}
|
|
186
182
|
|
|
187
|
-
// "w-counter" → "WCounter"
|
|
188
183
|
function tagNameToPascal(tag: string): string {
|
|
189
184
|
return tag.split("-").map(p => p.charAt(0).toUpperCase() + p.slice(1)).join("");
|
|
190
185
|
}
|
|
@@ -314,7 +309,7 @@ export class Lexer {
|
|
|
314
309
|
const ch = this.src[this.pos];
|
|
315
310
|
if (ch === " " || ch === "\t" || ch === "\r" || ch === "\n") { this.adv(); continue; }
|
|
316
311
|
|
|
317
|
-
// sinth comments: -- line or --[ nestable block ]--
|
|
312
|
+
// sinth comments: -- line or --[ nestable block for when doing longgerrr comments]--
|
|
318
313
|
if (ch === "-" && this.src[this.pos + 1] === "-") {
|
|
319
314
|
if (this.src[this.pos + 2] === "[") {
|
|
320
315
|
this.adv(); this.adv(); this.adv();
|
|
@@ -3132,7 +3127,8 @@ function compileFile(filePath: string, opts: CompileOptions): { html: string; sh
|
|
|
3132
3127
|
const body = file.uses.map(u => renderCompUse(u, ctx, new Map(), 0)).join("\n");
|
|
3133
3128
|
const pageCSS = file.styles.map(s => processStyleBlock(s, hash)).join("\n");
|
|
3134
3129
|
const allCSS = [pageCSS, ...ctx.extraCSS].join("\n");
|
|
3135
|
-
|
|
3130
|
+
const h = `${body}\n<style>\n${allCSS}\n</style>`;
|
|
3131
|
+
return { html: h };
|
|
3136
3132
|
}
|
|
3137
3133
|
|
|
3138
3134
|
const headData = buildHeadData(file.meta);
|
|
@@ -3268,8 +3264,9 @@ async function startDevServer(opts: CompileOptions & { port: number; files?: str
|
|
|
3268
3264
|
: findSinthPages(opts.projectRoot, opts.outDir);
|
|
3269
3265
|
for (const p of pages) {
|
|
3270
3266
|
try {
|
|
3271
|
-
const
|
|
3272
|
-
if (!
|
|
3267
|
+
const result = compileFile(p, { ...opts, checkOnly: false });
|
|
3268
|
+
if (!result) continue;
|
|
3269
|
+
const html = result.html;
|
|
3273
3270
|
const rel = path.relative(opts.projectRoot, p).replace(/\.sinth$/, ".html").replace(/\\/g, "/");
|
|
3274
3271
|
const url = "/" + rel;
|
|
3275
3272
|
cache.set(url, html + LIVE_RELOAD_SCRIPT);
|
|
@@ -3286,13 +3283,22 @@ async function startDevServer(opts: CompileOptions & { port: number; files?: str
|
|
|
3286
3283
|
|
|
3287
3284
|
const resolvedOut = path.resolve(opts.outDir);
|
|
3288
3285
|
let watchReady = false;
|
|
3286
|
+
const pending = new Map<string, NodeJS.Timeout>();
|
|
3287
|
+
const DEBOUNCE_MS = 300;
|
|
3288
|
+
|
|
3289
3289
|
try {
|
|
3290
3290
|
fs.watch(opts.projectRoot, { recursive: true }, (_, filename) => {
|
|
3291
3291
|
if (!filename) return;
|
|
3292
3292
|
const abs = path.resolve(opts.projectRoot, filename);
|
|
3293
3293
|
if (abs.startsWith(resolvedOut + path.sep) || abs === resolvedOut) return;
|
|
3294
|
-
|
|
3295
|
-
|
|
3294
|
+
if (pending.has(abs)) {
|
|
3295
|
+
clearTimeout(pending.get(abs)!);
|
|
3296
|
+
}
|
|
3297
|
+
pending.set(abs, setTimeout(() => {
|
|
3298
|
+
pending.delete(abs);
|
|
3299
|
+
process.stdout.write(`\x1b[36m[sinth]\x1b[0m Changed: ${filename}\n`);
|
|
3300
|
+
compileAll(); notify();
|
|
3301
|
+
}, DEBOUNCE_MS));
|
|
3296
3302
|
});
|
|
3297
3303
|
watchReady = true;
|
|
3298
3304
|
} catch {}
|