@yannosay/sinth 0.16.0 → 0.17.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.
package/README.md CHANGED
@@ -133,7 +133,7 @@ Button(onClick: isFullscreen = !isFullscreen, fullscreen: isFullscreen, fullscre
133
133
  Without fullscreenSync, pressing Escape exits fullscreen but the variable stays true.
134
134
  With it, Escape resets the variable to false — button text updates automatically.
135
135
 
136
- ### Opt-in DOM Diffing
136
+ #### Opt-in DOM Diffing
137
137
 
138
138
  Skip re-executing expressions when their variables haven't changed. Perfect for expensive calculations or side effects you only want to fire once.
139
139
 
@@ -146,10 +146,10 @@ var int count = 0
146
146
  Main {
147
147
  Heading(level: 1) { count }
148
148
  (alert("Fires only once!")) -- no dependencies, runs once and never again
149
- Button(onClick: count = += 1) { "Increment" }
149
+ Button(onClick: count += 1) { "Increment" }
150
150
  }
151
151
  ```
152
- Count updates every click because count changed. The alert fires only on page load — zero dependencies means it's cached forever. No library import. No window pollution. Just a meta flag.
152
+ Count updates every click because count changed. The alert fires only on page load — zero dependencies means it's cached forever. Just a meta flag.
153
153
 
154
154
 
155
155
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yannosay/sinth",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "A declarative & reactive language that compiles to pure HTML, CSS, and JavaScript.",
5
5
  "author": "Yannosay Productions",
6
6
  "license": "AGPL-3.0",
@@ -1071,10 +1071,13 @@ export function buildRuntime(opts: {
1071
1071
  let vars = [];
1072
1072
  syncedEls.forEach(function(el) { vars.push(el.dataset.sinthFullscreenSync); });
1073
1073
  document.addEventListener('fullscreenchange', function() {
1074
- if (!document.fullscreenElement) {
1075
- vars.forEach(function(v) { window[v] = false; });
1076
- sinthRender();
1077
- }
1074
+ let state = !!document.fullscreenElement;
1075
+ vars.forEach(function(varName) {
1076
+ switch(varName) {
1077
+ ${[...new Set(varDecls.filter(v => v.name).map(v => `case '${v.name}': ${v.name} = state; break;`))].join('\n ')}
1078
+ }
1079
+ });
1080
+ sinthRender();
1078
1081
  });
1079
1082
  }
1080
1083
  })();`;
@@ -104,9 +104,14 @@ sinthRender();`;
104
104
  continue;
105
105
  }
106
106
 
107
- // component usage
108
- this.pos = savedPos;
109
- uses.push(this.parseCompUse());
107
+ if (nextType === TT.LPAREN && identName[0] === identName[0].toLowerCase()) {
108
+ this.consume(TT.IDENT);
109
+ const expr = this.parseCallExpr({ kind: "variable", name: identName });
110
+ uses.push({ kind: "use", name: "__IF_ROOT__", attrs: [], children: [{ kind: "expr", expression: expr, loc: this.peek().loc }], loc: this.peek().loc });
111
+ } else {
112
+ this.pos = savedPos;
113
+ uses.push(this.parseCompUse());
114
+ }
110
115
  }
111
116
  else throw new SinthError(
112
117
  `Unexpected token '${this.peek().value}' (${TT[this.peek().type]}) at top level`,
@@ -809,19 +814,10 @@ private parseArrayLiteral(): Literal {
809
814
  if (identName[0] === identName[0].toUpperCase() && identName[0] !== identName[0].toLowerCase()) {
810
815
  children.push(this.parseCompUse());
811
816
  } else {
812
- this.consume(TT.IDENT);
813
- this.consume(TT.LPAREN);
814
- const args: Expression[] = [];
815
- if (!this.check(TT.RPAREN)) {
816
- args.push(this.parseExpression()!);
817
- while (this.check(TT.COMMA)) {
818
- this.consume(TT.COMMA);
819
- args.push(this.parseExpression()!);
820
- }
817
+ const expr = this.parseExpression();
818
+ if (expr) {
819
+ children.push({ kind: "expr", expression: expr, loc });
821
820
  }
822
- this.consume(TT.RPAREN);
823
- const callExpr: Expression = { kind: "call", callee: { kind: "variable", name: identName }, args };
824
- children.push({ kind: "expr", expression: callExpr, loc });
825
821
  }
826
822
  continue;
827
823
  }