@yannosay/sinth 1.12.0 → 1.12.2
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/dist/cli.js +37 -0
- package/dist/core/cli-compiler.js +1 -0
- package/dist/core/compiler.js +13 -13
- package/dist/update-check.js +5 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -74,6 +74,11 @@ async function main() {
|
|
|
74
74
|
case "build": {
|
|
75
75
|
const nonSinth = cleanArgs.filter(a => !a.endsWith(".sinth"));
|
|
76
76
|
const buildStart = Date.now();
|
|
77
|
+
const pkgPath4 = path.join(__dirname, "..", "package.json");
|
|
78
|
+
if (fs.existsSync(pkgPath4)) {
|
|
79
|
+
const pkg4 = JSON.parse(fs.readFileSync(pkgPath4, "utf-8"));
|
|
80
|
+
(0, update_check_1.checkForUpdate)(pkg4.version);
|
|
81
|
+
}
|
|
77
82
|
if (nonSinth.length > 0)
|
|
78
83
|
process.stdout.write(`\x1b[33mSkipping non-.sinth files:\x1b[0m ${nonSinth.join(", ")}\n`);
|
|
79
84
|
const fileArgs = cleanArgs.filter(a => a.endsWith(".sinth"));
|
|
@@ -137,6 +142,11 @@ async function main() {
|
|
|
137
142
|
break;
|
|
138
143
|
}
|
|
139
144
|
case "dev": {
|
|
145
|
+
const pkgPath3 = path.join(__dirname, "..", "package.json");
|
|
146
|
+
if (fs.existsSync(pkgPath3)) {
|
|
147
|
+
const pkg3 = JSON.parse(fs.readFileSync(pkgPath3, "utf-8"));
|
|
148
|
+
(0, update_check_1.checkForUpdate)(pkg3.version);
|
|
149
|
+
}
|
|
140
150
|
const fileArgs = cleanArgs.filter(a => a.endsWith(".sinth"));
|
|
141
151
|
const files = fileArgs.length > 0
|
|
142
152
|
? fileArgs.map(f => path.resolve(cwd, f)).filter(f => fs.existsSync(f))
|
|
@@ -160,6 +170,33 @@ async function main() {
|
|
|
160
170
|
}
|
|
161
171
|
process.exit(hadError ? 1 : 0);
|
|
162
172
|
}
|
|
173
|
+
case "update": {
|
|
174
|
+
const pkgPath2 = path.join(__dirname, "..", "package.json");
|
|
175
|
+
const current = fs.existsSync(pkgPath2) ? JSON.parse(fs.readFileSync(pkgPath2, "utf-8")).version : null;
|
|
176
|
+
const https = require("https");
|
|
177
|
+
https.get("https://registry.npmjs.org/@yannosay/sinth/latest", { timeout: 5000 }, (res) => {
|
|
178
|
+
let data = "";
|
|
179
|
+
res.on("data", (chunk) => data += chunk);
|
|
180
|
+
res.on("end", () => {
|
|
181
|
+
try {
|
|
182
|
+
const latest = JSON.parse(data).version;
|
|
183
|
+
if (latest === current) {
|
|
184
|
+
process.stdout.write(`\x1b[32mAlready on latest version: ${current} ✓\x1b[0m\n`);
|
|
185
|
+
}
|
|
186
|
+
else if (latest) {
|
|
187
|
+
process.stdout.write(`\x1b[36mUpdating Sinth ${current} → ${latest}...\x1b[0m\n`);
|
|
188
|
+
const { execSync } = require("child_process");
|
|
189
|
+
execSync("npm install -g @yannosay/sinth@latest", { stdio: "inherit" });
|
|
190
|
+
process.stdout.write(`\x1b[32m✓ Sinth updated to ${latest}!\x1b[0m\n`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
process.stderr.write("\x1b[31mCould not check for updates.\x1b[0m\n");
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}).on("error", () => process.stderr.write("\x1b[31mCould not reach npm registry.\x1b[0m\n"));
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
163
200
|
case "version":
|
|
164
201
|
case "--version":
|
|
165
202
|
case "-v": {
|
|
@@ -430,6 +430,7 @@ function compileFile(filePath, opts) {
|
|
|
430
430
|
sharedRuntime: opts.sharedRuntime,
|
|
431
431
|
functionsJS: compiledFunctions,
|
|
432
432
|
namespace: hash,
|
|
433
|
+
declaredVars: ctx.declaredVars,
|
|
433
434
|
});
|
|
434
435
|
const runtimeJS = typeof runtimeResult === 'string' ? runtimeResult : runtimeResult.page;
|
|
435
436
|
const sharedJS = typeof runtimeResult === 'string' ? null : runtimeResult.shared;
|
package/dist/core/compiler.js
CHANGED
|
@@ -52,7 +52,7 @@ exports.INLINE_STYLE_PROPS = new Set([
|
|
|
52
52
|
function inlineFunctionBody(fnDef, args, ctx) {
|
|
53
53
|
const paramMap = new Map();
|
|
54
54
|
for (let i = 0; i < fnDef.params.length && i < args.length; i++) {
|
|
55
|
-
paramMap.set(fnDef.params[i].name, (0, expr_1.compileExprToJS)(args[i], ctx.loopVars, ctx.namespace));
|
|
55
|
+
paramMap.set(fnDef.params[i].name, (0, expr_1.compileExprToJS)(args[i], ctx.loopVars, ctx.namespace, ctx.declaredVars));
|
|
56
56
|
}
|
|
57
57
|
const subExpr = (expr) => {
|
|
58
58
|
if (expr.kind === "variable" && expr.name && paramMap.has(expr.name)) {
|
|
@@ -162,7 +162,7 @@ function inlineFunctionBody(fnDef, args, ctx) {
|
|
|
162
162
|
else if (lit.value.startsWith("__EXPR__")) {
|
|
163
163
|
try {
|
|
164
164
|
const innerExpr = JSON.parse(lit.value.substring(8));
|
|
165
|
-
initJS = (0, expr_1.compileExprToJS)(subExpr(innerExpr), ctx.loopVars, ctx.namespace);
|
|
165
|
+
initJS = (0, expr_1.compileExprToJS)(subExpr(innerExpr), ctx.loopVars, ctx.namespace, ctx.declaredVars);
|
|
166
166
|
}
|
|
167
167
|
catch {
|
|
168
168
|
initJS = JSON.stringify(lit.value);
|
|
@@ -363,7 +363,7 @@ function renderAttr(attr, paramMap, ctx) {
|
|
|
363
363
|
const exprJson = raw.substring("__MULTI_EXPR__".length);
|
|
364
364
|
try {
|
|
365
365
|
const exprs = JSON.parse(exprJson);
|
|
366
|
-
const jsExprs = exprs.map(e => (0, expr_1.compileExprToJS)(e, undefined, ctx.namespace)).join("; ");
|
|
366
|
+
const jsExprs = exprs.map(e => (0, expr_1.compileExprToJS)(e, undefined, ctx.namespace, ctx.declaredVars)).join("; ");
|
|
367
367
|
const ev = eventAttrName(name);
|
|
368
368
|
let bumps = "";
|
|
369
369
|
if (ctx.diffingEnabled) {
|
|
@@ -396,7 +396,7 @@ function renderAttr(attr, paramMap, ctx) {
|
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
|
-
let jsExpr = (0, expr_1.compileExprToJS)(expr, ctx?.loopVars, ctx.namespace);
|
|
399
|
+
let jsExpr = (0, expr_1.compileExprToJS)(expr, ctx?.loopVars, ctx.namespace, ctx.declaredVars);
|
|
400
400
|
if (ctx.scopePrefix && ctx.scopeVar) {
|
|
401
401
|
if (expr.kind === "variable" && expr.name && ctx.varDecls?.some(v => v.name === expr.name)) {
|
|
402
402
|
jsExpr = `${ctx.scopePrefix}${expr.name}`;
|
|
@@ -528,16 +528,16 @@ function renderChild(child, ctx, params, depth) {
|
|
|
528
528
|
if (isMemo) {
|
|
529
529
|
if (fnName && fnName.includes(".")) {
|
|
530
530
|
types_1.SinthWarning.emit(`'$' on '${fnName}()' has no effect — dotted calls cannot be memoized.`);
|
|
531
|
-
ctx.logicBlocks.push((0, expr_1.compileExprToJS)(child.expression, undefined, ctx.namespace) + ";");
|
|
531
|
+
ctx.logicBlocks.push((0, expr_1.compileExprToJS)(child.expression, undefined, ctx.namespace, ctx.declaredVars) + ";");
|
|
532
532
|
return "";
|
|
533
533
|
}
|
|
534
|
-
const js = (0, expr_1.compileExprToJS)(child.expression);
|
|
534
|
+
const js = (0, expr_1.compileExprToJS)(child.expression, undefined, ctx.namespace, ctx.declaredVars);
|
|
535
535
|
ctx.logicBlocks.push(`if(!_memo_${fnName}_done){_memo_${fnName}=${js};_memo_${fnName}_done=true;}`);
|
|
536
536
|
const exprId = registerExpr(ctx, { kind: "variable", name: `_memo_${fnName}` });
|
|
537
537
|
return `<span class="sinth-expr" data-expr-id="${exprId}"></span>`;
|
|
538
538
|
}
|
|
539
539
|
if (fnName && fnName.includes(".")) {
|
|
540
|
-
ctx.logicBlocks.push((0, expr_1.compileExprToJS)(child.expression, undefined, ctx.namespace) + ";");
|
|
540
|
+
ctx.logicBlocks.push((0, expr_1.compileExprToJS)(child.expression, undefined, ctx.namespace, ctx.declaredVars) + ";");
|
|
541
541
|
return "";
|
|
542
542
|
}
|
|
543
543
|
if (fnName === "remove" && child.expression.args && child.expression.args.length === 1) {
|
|
@@ -668,7 +668,7 @@ function renderChild(child, ctx, params, depth) {
|
|
|
668
668
|
return `<span class="sinth-expr" data-expr-id="${exprId}"${ctx.diffingEnabled ? ` data-sinth-deps="${exprDeps(child.expression, ctx.declaredVars ?? new Set())}"` : ""}></span>`;
|
|
669
669
|
}
|
|
670
670
|
case "assign_stmt": {
|
|
671
|
-
ctx.logicBlocks.push((0, expr_1.compileExprToJS)(child.expression, undefined, ctx.namespace) + ";");
|
|
671
|
+
ctx.logicBlocks.push((0, expr_1.compileExprToJS)(child.expression, undefined, ctx.namespace, ctx.declaredVars) + ";");
|
|
672
672
|
return "";
|
|
673
673
|
}
|
|
674
674
|
case "remove": {
|
|
@@ -783,7 +783,7 @@ function renderIfBlock(ifBlock, ctx, params, depth) {
|
|
|
783
783
|
.filter(c => c.kind === "assign_stmt")
|
|
784
784
|
.map(c => {
|
|
785
785
|
const e = c.expression;
|
|
786
|
-
const js = (0, expr_1.compileExprToJS)(e, undefined, ctx.namespace);
|
|
786
|
+
const js = (0, expr_1.compileExprToJS)(e, undefined, ctx.namespace, ctx.declaredVars);
|
|
787
787
|
let bump = "";
|
|
788
788
|
if (ctx.diffingEnabled && e.kind === "assign" && e.target) {
|
|
789
789
|
bump = `;window._bump&&window._bump('${e.target.replace(/'/g, "\\'")}')`;
|
|
@@ -799,7 +799,7 @@ function renderIfBlock(ifBlock, ctx, params, depth) {
|
|
|
799
799
|
.filter(c => c.kind === "assign_stmt")
|
|
800
800
|
.map(c => {
|
|
801
801
|
const e = c.expression;
|
|
802
|
-
const js = (0, expr_1.compileExprToJS)(e, undefined, ctx.namespace);
|
|
802
|
+
const js = (0, expr_1.compileExprToJS)(e, undefined, ctx.namespace, ctx.declaredVars);
|
|
803
803
|
let bump = "";
|
|
804
804
|
if (ctx.diffingEnabled && e.kind === "assign" && e.target) {
|
|
805
805
|
bump = `;window._bump&&window._bump('${e.target.replace(/'/g, "\\'")}')`;
|
|
@@ -1082,7 +1082,7 @@ function renderCompUse(use, ctx, params, depth) {
|
|
|
1082
1082
|
if (raw.startsWith("__EXPR__")) {
|
|
1083
1083
|
try {
|
|
1084
1084
|
const expr = JSON.parse(raw.substring(8));
|
|
1085
|
-
const jsExpr = (0, expr_1.compileExprToJS)(expr, undefined, ctx.namespace);
|
|
1085
|
+
const jsExpr = (0, expr_1.compileExprToJS)(expr, undefined, ctx.namespace, ctx.declaredVars);
|
|
1086
1086
|
attrParts.push(`onchange="(function(){ ${jsExpr}; ${renderFn}(); })(event)"`);
|
|
1087
1087
|
}
|
|
1088
1088
|
catch { }
|
|
@@ -1210,7 +1210,7 @@ function buildRuntime(opts) {
|
|
|
1210
1210
|
if (val.startsWith("__EXPR__")) {
|
|
1211
1211
|
try {
|
|
1212
1212
|
const expr = JSON.parse(val.substring(8));
|
|
1213
|
-
const js = (0, expr_1.compileExprToJS)(expr);
|
|
1213
|
+
const js = (0, expr_1.compileExprToJS)(expr, undefined, opts.namespace, opts.declaredVars);
|
|
1214
1214
|
const id = exprRegistry.length;
|
|
1215
1215
|
exprRegistry.push(js);
|
|
1216
1216
|
return `var ${vn} = __X${ns}[${id}]({});`;
|
|
@@ -1259,7 +1259,7 @@ function buildRuntime(opts) {
|
|
|
1259
1259
|
.map(v => {
|
|
1260
1260
|
try {
|
|
1261
1261
|
const expr = JSON.parse((0, utils_1.litToString)(v.value).substring(8));
|
|
1262
|
-
const js = (0, expr_1.compileExprToJS)(expr);
|
|
1262
|
+
const js = (0, expr_1.compileExprToJS)(expr, undefined, opts.namespace, opts.declaredVars);
|
|
1263
1263
|
const idx = exprRegistry.indexOf(js);
|
|
1264
1264
|
const vn2 = ns ? ns.slice(1) + "_" + v.name : v.name;
|
|
1265
1265
|
return `${vn2} = __X${ns}[${idx}]({});`;
|
package/dist/update-check.js
CHANGED
|
@@ -85,8 +85,12 @@ async function checkForUpdate(currentVersion) {
|
|
|
85
85
|
return;
|
|
86
86
|
writeCache();
|
|
87
87
|
const latest = await fetchLatestVersion();
|
|
88
|
-
if (!latest
|
|
88
|
+
if (!latest)
|
|
89
89
|
return;
|
|
90
|
+
if (latest === currentVersion) {
|
|
91
|
+
process.stdout.write(`\n\x1b[2mSinth is up to date (v${currentVersion})!\x1b[0m\n`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
90
94
|
// simple semver compare (major.minor.patch)
|
|
91
95
|
const curParts = currentVersion.split(".").map(Number);
|
|
92
96
|
const latParts = latest.split(".").map(Number);
|
package/package.json
CHANGED