@yannosay/sinth 0.0.9 → 0.0.11

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 (2) hide show
  1. package/package.json +4 -3
  2. package/src/sinth.ts +40 -38
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yannosay/sinth",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
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",
@@ -31,8 +31,9 @@
31
31
  "LICENSE"
32
32
  ],
33
33
  "dependencies": {
34
- "ts-node": "^10.9.0",
35
- "sass": "^1.70.0"
34
+ "@yannosay/sinth": "^0.0.9",
35
+ "sass": "^1.70.0",
36
+ "ts-node": "^10.9.0"
36
37
  },
37
38
  "devDependencies": {
38
39
  "@types/node": "^20.0.0",
package/src/sinth.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // Sinth Compiler v0.0.7 — enum fix, raw-block detection, import resolution, CSS conversion, slot escaping, custom-elements, HTML5 map
2
+ // Sinth Compiler v0.0.11 — enum fix, raw-block detection, import resolution, CSS conversion, slot escaping, custom-elements, HTML5 map
3
3
 
4
4
  import * as fs from "fs";
5
5
  import * as path from "path";
@@ -11,7 +11,7 @@ import * as http from "http";
11
11
 
12
12
  interface Loc { file: string; line: number; col: number }
13
13
 
14
- // === v0.0.7: Must be plain `enum TT`, NOT `const enum TT` — const enum breaks TT[t] string indexing ===
14
+ // === v0.0.11: Must be plain `enum TT`, NOT `const enum TT` — const enum breaks TT[t] string indexing ===
15
15
  enum TT {
16
16
  LBRACE, RBRACE, LPAREN, RPAREN, COLON, COMMA, EQUALS, DOT,
17
17
  STRING, NUMBER, BOOL_TRUE, BOOL_FALSE, NULL_LIT,
@@ -20,7 +20,7 @@ enum TT {
20
20
  KW_IMPORT, KW_AS, KW_CSS,
21
21
  KW_COMPONENT, KW_STYLE, KW_SCRIPT,
22
22
  KW_GLOBAL, KW_PAGE, KW_LANG,
23
- // === v0.0.7: KW_CUSTOM_EL and KW_CUSTOM ensured present ===
23
+ // === v0.0.11: KW_CUSTOM_EL and KW_CUSTOM ensured present ===
24
24
  KW_CUSTOM_EL,
25
25
  KW_CUSTOM,
26
26
  EOF,
@@ -102,7 +102,7 @@ class SinthError extends Error {
102
102
  return s;
103
103
  }
104
104
 
105
- // === v0.0.7: Attach source line to produce error preview ===
105
+ // === v0.0.11: Attach source line to produce error preview ===
106
106
  withSource(lines: string[]): SinthError {
107
107
  if (!this.loc || this.sourceLine !== undefined) return this;
108
108
  const line = lines[this.loc.line - 1] ?? "";
@@ -173,7 +173,7 @@ const KEYWORDS: Record<string, TT> = {
173
173
  "true": TT.BOOL_TRUE,
174
174
  "false": TT.BOOL_FALSE,
175
175
  "null": TT.NULL_LIT,
176
- // === v0.0.7: custom-element and custom lexed as hyphenated identifier ===
176
+ // === v0.0.11: custom-element and custom lexed as hyphenated identifier ===
177
177
  "custom-element": TT.KW_CUSTOM_EL,
178
178
  "custom": TT.KW_CUSTOM,
179
179
  };
@@ -221,7 +221,7 @@ export class Lexer {
221
221
 
222
222
  if (this.isIdentStart(ch)) {
223
223
  const tok = this.readIdent(loc);
224
- // === v0.0.7: Also set rawBlockPending for component, custom-element, custom ===
224
+ // === v0.0.11: Also set rawBlockPending for component, custom-element, custom ===
225
225
  if (
226
226
  tok.type === TT.KW_STYLE ||
227
227
  tok.type === TT.KW_SCRIPT ||
@@ -386,7 +386,7 @@ export class Lexer {
386
386
 
387
387
  private readIdent(loc: Loc): Token {
388
388
  let s = "";
389
- // === v0.0.7: isIdentCont includes '-' so "custom-element" is read as one token ===
389
+ // === v0.0.11: isIdentCont includes '-' so "custom-element" is read as one token ===
390
390
  while (this.pos < this.src.length && this.isIdentCont(this.src[this.pos])) {
391
391
  s += this.src[this.pos]; this.adv();
392
392
  }
@@ -407,7 +407,7 @@ export class Lexer {
407
407
  private loc(): Loc { return { file: this.file, line: this.line, col: this.col }; }
408
408
  private isDigit(c: string) { return c >= "0" && c <= "9"; }
409
409
  private isIdentStart(c: string) { return /[a-zA-Z_\u00C0-\uFFFF]/.test(c); }
410
- // === v0.0.7: '-' allowed in identifiers so "custom-element" is a single token ===
410
+ // === v0.0.11: '-' allowed in identifiers so "custom-element" is a single token ===
411
411
  private isIdentCont(c: string) { return /[a-zA-Z0-9_\-\u00C0-\uFFFF]/.test(c); }
412
412
  }
413
413
 
@@ -503,14 +503,14 @@ export class Parser {
503
503
  const loc = this.consume(TT.KW_COMPONENT).loc;
504
504
  const name = this.consume(TT.IDENT).value;
505
505
  const params = this.parseParamDecls();
506
- // === v0.0.7: rawBlockPending was set by the lexer when KW_COMPONENT was read;
506
+ // === v0.0.11: rawBlockPending was set by the lexer when KW_COMPONENT was read;
507
507
  // the next token is therefore RAW_BLOCK, not LBRACE ===
508
508
  const rawTok = this.consume(TT.RAW_BLOCK);
509
509
  const { body, styles, scripts } = this.parseCompBody(rawTok.value, rawTok.loc);
510
510
  return { name, params, body, styles, scripts, loc };
511
511
  }
512
512
 
513
- // === v0.0.7: Parse custom-element / custom declarations ===
513
+ // === v0.0.11: Parse custom-element / custom declarations ===
514
514
  private parseCustomEl(): CustomElDecl {
515
515
  const loc = this.peek().loc;
516
516
  if (this.check(TT.KW_CUSTOM_EL)) this.consume(TT.KW_CUSTOM_EL);
@@ -690,7 +690,7 @@ interface ResolvedImports {
690
690
  // Module-level import stack for circular detection
691
691
  const IMPORT_STACK: string[] = [];
692
692
 
693
- // === v0.0.7: parseFile catches errors and attaches source line preview ===
693
+ // === v0.0.11: parseFile catches errors and attaches source line preview ===
694
694
  function parseFile(filePath: string): SinthFile {
695
695
  if (!fs.existsSync(filePath)) throw new SinthError(`File not found: ${filePath}`);
696
696
  const src = fs.readFileSync(filePath, "utf-8");
@@ -744,7 +744,7 @@ function resolveImports(
744
744
  const src = resolveLibrary(imp.name, cfg);
745
745
  jsLinks.push({ src, attrs: {} });
746
746
 
747
- // === v0.0.7: Auto-import companion .sinth for JS libraries (e.g. sinthui.sinth) ===
747
+ // === v0.0.11: Auto-import companion .sinth for JS libraries (e.g. sinthui.sinth) ===
748
748
  for (const libDir of cfg.libraryPaths) {
749
749
  const companion = path.join(libDir, imp.name + ".sinth");
750
750
  if (fs.existsSync(companion) && !visited.has(companion)) {
@@ -802,7 +802,7 @@ function resolveLibrary(name: string, cfg: ResolverConfig): string {
802
802
  return `/libraries/${base}`;
803
803
  }
804
804
 
805
- // === v0.0.7: resolveSinthPath — first try relative to importing file, then library paths ===
805
+ // === v0.0.11: resolveSinthPath — first try relative to importing file, then library paths ===
806
806
  function resolveSinthPath(p: string, fromFile: string, cfg: ResolverConfig): string {
807
807
  // Explicit relative path
808
808
  if (p.startsWith("./") || p.startsWith("../")) {
@@ -813,7 +813,7 @@ function resolveSinthPath(p: string, fromFile: string, cfg: ResolverConfig): str
813
813
  throw new SinthError(`Cannot resolve import '${p}' from '${fromFile}'`);
814
814
  }
815
815
 
816
- // === v0.0.7: Non-relative paths (e.g. "components/Card.sinth"): try relative to importing
816
+ // === v0.0.11: Non-relative paths (e.g. "components/Card.sinth"): try relative to importing
817
817
  // file's directory FIRST, then fall back to library paths ===
818
818
  const relToFile = path.resolve(path.dirname(fromFile), p);
819
819
  if (fs.existsSync(relToFile)) return relToFile;
@@ -839,7 +839,7 @@ function resolveSinthPath(p: string, fromFile: string, cfg: ResolverConfig): str
839
839
 
840
840
  interface BuiltinInfo { tag: string; defaultClass?: string; voidEl?: boolean }
841
841
 
842
- // === v0.0.7: Complete HTML5 map; Col = void <col>; Column = grid div; added SubHeading, CardGrid ===
842
+ // === v0.0.11: Complete HTML5 map; Col = void <col>; Column = grid div; added SubHeading, CardGrid ===
843
843
  const BUILTIN_MAP: Record<string, BuiltinInfo> = {
844
844
  // ── Structural ──────────────────────────────────────────
845
845
  Main: { tag: "main" },
@@ -857,12 +857,12 @@ const BUILTIN_MAP: Record<string, BuiltinInfo> = {
857
857
  Flex: { tag: "div", defaultClass: "flex" },
858
858
  Stack: { tag: "div", defaultClass: "stack" },
859
859
  Row: { tag: "div", defaultClass: "row" },
860
- // === v0.0.7: Column = grid helper div; Col = HTML void table col ===
860
+ // === v0.0.11: Column = grid helper div; Col = HTML void table col ===
861
861
  Column: { tag: "div", defaultClass: "col" },
862
862
  // ── Typography ────────────────────────────────────────────
863
863
  Heading: { tag: "h1" }, // resolved dynamically by level attr
864
864
  Paragraph: { tag: "p" },
865
- // === v0.0.7: SubHeading convenience component ===
865
+ // === v0.0.11: SubHeading convenience component ===
866
866
  SubHeading: { tag: "p", defaultClass: "subheading" },
867
867
  Lead: { tag: "p", defaultClass: "lead" },
868
868
  Small: { tag: "small" },
@@ -929,7 +929,7 @@ const BUILTIN_MAP: Record<string, BuiltinInfo> = {
929
929
  Wbr: { tag: "wbr", voidEl: true },
930
930
  Source: { tag: "source", voidEl: true },
931
931
  Embed: { tag: "embed", voidEl: true },
932
- // === v0.0.7: Col = HTML void table column (NOT the grid div) ===
932
+ // === v0.0.11: Col = HTML void table column (NOT the grid div) ===
933
933
  Col: { tag: "col", voidEl: true },
934
934
  Area: { tag: "area", voidEl: true },
935
935
  // ── Lists ─────────────────────────────────────────────────
@@ -949,9 +949,9 @@ const BUILTIN_MAP: Record<string, BuiltinInfo> = {
949
949
  Template: { tag: "template" },
950
950
  Slot: { tag: "slot" },
951
951
  NoScript: { tag: "noscript" },
952
- // === v0.0.7: CardGrid convenience layout wrapper ===
952
+ // === v0.0.11: CardGrid convenience layout wrapper ===
953
953
  CardGrid: { tag: "div", defaultClass: "card-grid" },
954
- // === v0.0.7: RawHTML marker — handled specially in renderCompUse ===
954
+ // === v0.0.11: RawHTML marker — handled specially in renderCompUse ===
955
955
  RawHTML: { tag: "__RAW__" },
956
956
  };
957
957
 
@@ -970,7 +970,7 @@ function eventAttrName(name: string): string | null {
970
970
  // SECTION 7: STYLE PROCESSOR
971
971
  // ═══════════════════════════════════════════════════════════
972
972
 
973
- // === v0.0.7: Completely rewritten convertCSSProps — bulletproof line-by-line approach ===
973
+ // === v0.0.11: Completely rewritten convertCSSProps — bulletproof line-by-line approach ===
974
974
  // Rules:
975
975
  // - Match lines of the form: [whitespace] camelCaseProp : "value" [;]
976
976
  // - Convert property name camelCase → kebab-case
@@ -985,6 +985,8 @@ function convertCSSProps(css: string): string {
985
985
  if (!trimmed) return line;
986
986
  if (trimmed === "}" || trimmed.startsWith("}")) return line;
987
987
  if (trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*")) return line;
988
+ // Strip Sinth comments (-- ...) from style blocks
989
+ if (trimmed.startsWith("--") && !trimmed.startsWith("--[")) return line;
988
990
  if (trimmed.startsWith("@")) return line;
989
991
  // Lines containing { are selector/block openers — leave untouched
990
992
  if (trimmed.includes("{")) return line;
@@ -1022,7 +1024,7 @@ function convertCSSProps(css: string): string {
1022
1024
  }).join("\n");
1023
1025
  }
1024
1026
 
1025
- // === v0.0.7: processStyleBlock — correct order: interpolate {param} → camelCase convert → SCSS → scope ===
1027
+ // === v0.0.11: processStyleBlock — correct order: interpolate {param} → camelCase convert → SCSS → scope ===
1026
1028
  function processStyleBlock(
1027
1029
  block: StyleBlock,
1028
1030
  hash: string,
@@ -1208,7 +1210,7 @@ function renderAttr(attr: Attr, paramMap: Map<string, string>): string {
1208
1210
  return `${name}="${escAttr(raw)}"`;
1209
1211
  }
1210
1212
 
1211
- // === v0.0.7: renderText — "$slot" protected from double-escaping via placeholder approach ===
1213
+ // === v0.0.11: renderText — "$slot" protected from double-escaping via placeholder approach ===
1212
1214
  function renderText(text: string, params: Map<string, string>): string {
1213
1215
  // Map of placeholder → raw HTML for slot-like params
1214
1216
  const rawSlots = new Map<string, string>();
@@ -1246,7 +1248,7 @@ function renderText(text: string, params: Map<string, string>): string {
1246
1248
  // Step 5: Restore \$ → $
1247
1249
  s = s.replace(/\x00DOLLAR\x00/g, "$");
1248
1250
 
1249
- // === v0.0.7: Warn about {identifier} patterns remaining after substitution ===
1251
+ // === v0.0.11: Warn about {identifier} patterns remaining after substitution ===
1250
1252
  const braceRe = /\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
1251
1253
  let m: RegExpExecArray | null;
1252
1254
  while ((m = braceRe.exec(s)) !== null) {
@@ -1282,7 +1284,7 @@ function renderCompUse(
1282
1284
  params: Map<string, string>,
1283
1285
  depth: number,
1284
1286
  ): string {
1285
- // === v0.0.7: RawHTML — output content attribute verbatim, no wrapping tag, no scoping ===
1287
+ // === v0.0.11: RawHTML — output content attribute verbatim, no wrapping tag, no scoping ===
1286
1288
  if (use.name === "RawHTML") {
1287
1289
  const ca = use.attrs.find(a => a.name === "content");
1288
1290
  if (!ca || !ca.value) return "";
@@ -1327,7 +1329,7 @@ function renderCompUse(
1327
1329
  const classes = [defaultClass, userClass].filter(Boolean).join(" ");
1328
1330
  if (classes) attrParts.push(`class="${escAttr(classes)}"`);
1329
1331
 
1330
- // === v0.0.7: Default type="button" for <button> elements ===
1332
+ // === v0.0.11: Default type="button" for <button> elements ===
1331
1333
  if (tag === "button" && !use.attrs.some(a => a.name === "type")) {
1332
1334
  attrParts.push(`type="button"`);
1333
1335
  }
@@ -1389,7 +1391,7 @@ function expandUserComp(
1389
1391
  const slotHTML = use.children.map(c => renderChild(c, ctx, params, depth)).join("");
1390
1392
  local.set("slot", slotHTML);
1391
1393
 
1392
- // === v0.0.7: Process component style blocks with instance params and push to extraCSS ===
1394
+ // === v0.0.11: Process component style blocks with instance params and push to extraCSS ===
1393
1395
  for (const block of def.styles) {
1394
1396
  ctx.extraCSS.push(processStyleBlock(block, ctx.scopeHash, local));
1395
1397
  }
@@ -1490,7 +1492,7 @@ function buildHeadData(meta: MetaEntry[]): HeadData {
1490
1492
  return { title, fav, lang, charset, viewport, metaTags, metaProps };
1491
1493
  }
1492
1494
 
1493
- // === v0.0.7: .jpg and .jpeg return "image/jpeg" ===
1495
+ // === v0.0.11: .jpg and .jpeg return "image/jpeg" ===
1494
1496
  function faviconType(p: string): string {
1495
1497
  const ext = path.extname(p).toLowerCase();
1496
1498
  switch (ext) {
@@ -1553,7 +1555,7 @@ function compileFile(filePath: string, opts: CompileOptions): string | null {
1553
1555
  const { allDefs, customEls, cssLinks, jsLinks } = resolveImports(file, cfg);
1554
1556
  const hash = fnv1a(absPath);
1555
1557
 
1556
- // === v0.0.7: extraCSS collected during rendering (per-instance component styles) ===
1558
+ // === v0.0.11: extraCSS collected during rendering (per-instance component styles) ===
1557
1559
  const ctx: CompileCtx = {
1558
1560
  allDefs, customEls, cssLinks, jsLinks,
1559
1561
  scopeHash: hash, pageFile: absPath, extraCSS: [],
@@ -1624,7 +1626,7 @@ function minifyHTML(html: string): string {
1624
1626
  // SECTION 12: FILE DISCOVERY & ASSET COPY
1625
1627
  // ═══════════════════════════════════════════════════════════
1626
1628
 
1627
- // === v0.0.7: findSinthPages skips outDir to prevent infinite watcher loops ===
1629
+ // === v0.0.11: findSinthPages skips outDir to prevent infinite watcher loops ===
1628
1630
  function findSinthPages(dir: string, outDir?: string): string[] {
1629
1631
  const results: string[] = [];
1630
1632
  for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
@@ -1640,7 +1642,7 @@ function findSinthPages(dir: string, outDir?: string): string[] {
1640
1642
  return results;
1641
1643
  }
1642
1644
 
1643
- // === v0.0.7: Recursive directory copy for assets/ ===
1645
+ // === v0.0.11: Recursive directory copy for assets/ ===
1644
1646
  function copyDir(src: string, dest: string): void {
1645
1647
  if (!fs.existsSync(src)) return;
1646
1648
  fs.mkdirSync(dest, { recursive: true });
@@ -1699,7 +1701,7 @@ async function startDevServer(opts: CompileOptions & { port: number, files?: str
1699
1701
 
1700
1702
  compileAll();
1701
1703
 
1702
- // === v0.0.7: Watch ignores changes whose absolute path is inside outDir ===
1704
+ // === v0.0.11: Watch ignores changes whose absolute path is inside outDir ===
1703
1705
  const resolvedOut = path.resolve(opts.outDir);
1704
1706
  // Use fs.watch with fs.watchFile fallback for Windows reliability
1705
1707
  let watchReady = false;
@@ -1861,7 +1863,7 @@ async function main(): Promise<void> {
1861
1863
  }
1862
1864
  }
1863
1865
 
1864
- // === v0.0.7: Copy assets/ to outDir/assets/ ===
1866
+ // === v0.0.11: Copy assets/ to outDir/assets/ ===
1865
1867
  const assetsIn = path.join(cwd, "assets");
1866
1868
  const assetsOut = path.join(outDir, "assets");
1867
1869
  if (fs.existsSync(assetsIn)) {
@@ -1900,11 +1902,11 @@ async function main(): Promise<void> {
1900
1902
  break;
1901
1903
  }
1902
1904
 
1903
- // === v0.0.7: sinth version command ===
1905
+ // === v0.0.11: sinth version command ===
1904
1906
  case "version":
1905
1907
  case "--version":
1906
1908
  case "-v": {
1907
- process.stdout.write("Sinth Compiler v0.0.7\n");
1909
+ process.stdout.write("Sinth Compiler v0.0.11\n");
1908
1910
  break;
1909
1911
  }
1910
1912
 
@@ -1917,7 +1919,7 @@ async function main(): Promise<void> {
1917
1919
 
1918
1920
  default: {
1919
1921
  process.stdout.write(`
1920
- \x1b[1mSinth Compiler v0.0.7\x1b[0m
1922
+ \x1b[1mSinth Compiler v0.0.11\x1b[0m
1921
1923
 
1922
1924
  \x1b[1mCommands:\x1b[0m
1923
1925
  sinth build [--out ./dist] [--prod] Compile all .sinth pages + copy assets/
@@ -2088,8 +2090,8 @@ component Card(title, color = "blue") {
2088
2090
  \x1b[32m✓ Sinth project scaffolded!\x1b[0m
2089
2091
 
2090
2092
  \x1b[1mNext steps:\x1b[0m
2091
- sinth dev
2092
- sinth build
2093
+ sinth dev ./pages/index.sinth
2094
+ sinth build or sinth build ./index.sinth
2093
2095
  `);
2094
2096
  }
2095
2097