rip-lang 3.7.3 → 3.8.8
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/CHANGELOG.md +111 -0
- package/README.md +42 -34
- package/docs/RIP-INTERNALS.md +2 -4
- package/docs/RIP-LANG.md +150 -3
- package/docs/RIP-TYPES.md +1 -2
- package/docs/demo.html +342 -0
- package/docs/dist/rip-ui.min.js +516 -0
- package/docs/dist/rip-ui.min.js.br +0 -0
- package/docs/dist/rip.browser.js +379 -461
- package/docs/dist/rip.browser.min.js +204 -220
- package/docs/dist/rip.browser.min.js.br +0 -0
- package/docs/dist/ui.js +956 -0
- package/docs/dist/ui.min.js +2 -0
- package/docs/dist/ui.min.js.br +0 -0
- package/docs/dist/ui.rip +957 -0
- package/docs/dist/ui.rip.br +0 -0
- package/docs/examples.rip +180 -0
- package/docs/index.html +3 -1599
- package/docs/playground-app.html +1022 -0
- package/docs/playground-js.html +1645 -0
- package/docs/playground-rip-ui.html +1419 -0
- package/docs/playground-rip.html +1450 -0
- package/docs/rip-fav.svg +5 -0
- package/package.json +3 -3
- package/scripts/serve.js +3 -2
- package/src/browser.js +38 -16
- package/src/compiler.js +165 -226
- package/src/components.js +153 -140
- package/src/grammar/README.md +234 -0
- package/src/grammar/lunar.rip +2412 -0
- package/src/grammar/solar.rip +18 -4
- package/src/lexer.js +82 -30
- package/src/parser-rd.js +3242 -0
- package/src/parser.js +6 -5
- package/src/repl.js +24 -5
- package/docs/NOTES.md +0 -93
- package/docs/RIP-GUIDE.md +0 -698
- package/docs/RIP-REACTIVITY.md +0 -311
package/docs/dist/rip.browser.js
CHANGED
|
@@ -1354,7 +1354,7 @@ var NEWLINE_RE = /^(?:\n[^\n\S]*)+/;
|
|
|
1354
1354
|
var COMMENT_RE = /^(\s*)###([^#][\s\S]*?)(?:###([^\n\S]*)|###$)|^((?:\s*#(?!##[^#]).*)+)/;
|
|
1355
1355
|
var CODE_RE = /^[-=]>/;
|
|
1356
1356
|
var REACTIVE_RE = /^(?:~[=>]|=!)/;
|
|
1357
|
-
var STRING_START_RE = /^(?:'''|"""|'|")/;
|
|
1357
|
+
var STRING_START_RE = /^(?:'''\\|"""\\|'''|"""|'|")/;
|
|
1358
1358
|
var STRING_SINGLE_RE = /^(?:[^\\']|\\[\s\S])*/;
|
|
1359
1359
|
var STRING_DOUBLE_RE = /^(?:[^\\"#$]|\\[\s\S]|\#(?!\{)|\$(?!\{))*/;
|
|
1360
1360
|
var HEREDOC_SINGLE_RE = /^(?:[^\\']|\\[\s\S]|'(?!''))*/;
|
|
@@ -1650,6 +1650,20 @@ class Lexer {
|
|
|
1650
1650
|
return fallback;
|
|
1651
1651
|
}
|
|
1652
1652
|
commentToken() {
|
|
1653
|
+
if (this.inRenderBlock) {
|
|
1654
|
+
if (/^#[a-zA-Z_]/.test(this.chunk)) {
|
|
1655
|
+
let prev = this.prev();
|
|
1656
|
+
if (prev && (prev[0] === "IDENTIFIER" || prev[0] === "PROPERTY"))
|
|
1657
|
+
return 0;
|
|
1658
|
+
let m = /^#([a-zA-Z_][\w-]*)/.exec(this.chunk);
|
|
1659
|
+
if (m) {
|
|
1660
|
+
this.emit("IDENTIFIER", "div#" + m[1]);
|
|
1661
|
+
return m[0].length;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
if (/^\s+#[a-zA-Z_]/.test(this.chunk))
|
|
1665
|
+
return 0;
|
|
1666
|
+
}
|
|
1653
1667
|
let match = COMMENT_RE.exec(this.chunk);
|
|
1654
1668
|
if (!match)
|
|
1655
1669
|
return 0;
|
|
@@ -1766,12 +1780,14 @@ class Lexer {
|
|
|
1766
1780
|
if (!m)
|
|
1767
1781
|
return 0;
|
|
1768
1782
|
let quote = m[0];
|
|
1783
|
+
let raw = quote.length > 1 && quote.endsWith("\\");
|
|
1784
|
+
let baseQuote = raw ? quote.slice(0, -1) : quote;
|
|
1769
1785
|
let prev = this.prev();
|
|
1770
1786
|
if (prev && this.prevVal() === "from" && (this.seenImport || this.seenExport)) {
|
|
1771
1787
|
prev[0] = "FROM";
|
|
1772
1788
|
}
|
|
1773
1789
|
let regex;
|
|
1774
|
-
switch (
|
|
1790
|
+
switch (baseQuote) {
|
|
1775
1791
|
case "'":
|
|
1776
1792
|
regex = STRING_SINGLE_RE;
|
|
1777
1793
|
break;
|
|
@@ -1785,13 +1801,13 @@ class Lexer {
|
|
|
1785
1801
|
regex = HEREDOC_DOUBLE_RE;
|
|
1786
1802
|
break;
|
|
1787
1803
|
}
|
|
1788
|
-
let { tokens: parts, index: end } = this.matchWithInterpolations(regex, quote);
|
|
1789
|
-
let heredoc =
|
|
1804
|
+
let { tokens: parts, index: end } = this.matchWithInterpolations(regex, quote, baseQuote);
|
|
1805
|
+
let heredoc = baseQuote.length === 3;
|
|
1790
1806
|
let indent = null;
|
|
1791
1807
|
if (heredoc) {
|
|
1792
|
-
indent = this.processHeredocIndent(end,
|
|
1808
|
+
indent = this.processHeredocIndent(end, baseQuote, parts);
|
|
1793
1809
|
}
|
|
1794
|
-
this.mergeInterpolationTokens(parts, { quote, indent, endOffset: end });
|
|
1810
|
+
this.mergeInterpolationTokens(parts, { quote: baseQuote, indent, endOffset: end, raw });
|
|
1795
1811
|
return end;
|
|
1796
1812
|
}
|
|
1797
1813
|
processHeredocIndent(end, quote, tokens) {
|
|
@@ -1875,7 +1891,7 @@ class Lexer {
|
|
|
1875
1891
|
}
|
|
1876
1892
|
return { tokens, index: offset + closingDelimiter.length };
|
|
1877
1893
|
}
|
|
1878
|
-
mergeInterpolationTokens(tokens, { quote, indent, endOffset }) {
|
|
1894
|
+
mergeInterpolationTokens(tokens, { quote, indent, endOffset, raw }) {
|
|
1879
1895
|
if (tokens.length > 1) {
|
|
1880
1896
|
this.emit("STRING_START", "(", { len: quote?.length || 0, data: { quote } });
|
|
1881
1897
|
}
|
|
@@ -1897,6 +1913,9 @@ class Lexer {
|
|
|
1897
1913
|
if (i === tokens.length - 1 && quote?.length === 3) {
|
|
1898
1914
|
processed = processed.replace(/\n[^\S\n]*$/, "");
|
|
1899
1915
|
}
|
|
1916
|
+
if (raw) {
|
|
1917
|
+
processed = processed.replace(/\\([nrtbfv0\\'"`xu])/g, "\\\\$1");
|
|
1918
|
+
}
|
|
1900
1919
|
this.emit("STRING", `"${processed}"`, { len: val.length, data: { quote } });
|
|
1901
1920
|
}
|
|
1902
1921
|
}
|
|
@@ -1936,7 +1955,7 @@ class Lexer {
|
|
|
1936
1955
|
let [flags2] = REGEX_FLAGS_RE.exec(this.chunk.slice(index2));
|
|
1937
1956
|
let end2 = index2 + flags2.length;
|
|
1938
1957
|
if (parts.length === 1 || !parts.some((p) => p[0] === "TOKENS")) {
|
|
1939
|
-
let body2 = parts[0]?.[1] || "";
|
|
1958
|
+
let body2 = (parts[0]?.[1] || "").replace(/(?<!\\)\//g, "\\/");
|
|
1940
1959
|
this.emit("REGEX", `/${body2}/${flags2}`, { len: end2, data: { delimiter: "///", heregex: { flags: flags2 } } });
|
|
1941
1960
|
} else {
|
|
1942
1961
|
this.emit("REGEX_START", "(", { len: 0 });
|
|
@@ -2049,8 +2068,19 @@ class Lexer {
|
|
|
2049
2068
|
tag = "REACT_ASSIGN";
|
|
2050
2069
|
else if (val === "=!")
|
|
2051
2070
|
tag = "READONLY_ASSIGN";
|
|
2052
|
-
else if (val === "*" && (!prev || prev[0] === "TERMINATOR" || prev[0] === "INDENT" || prev[0] === "OUTDENT") && /^[a-zA-Z_$]/.test(this.chunk[1] || "")) {
|
|
2071
|
+
else if (val === "*" && (!prev || prev[0] === "TERMINATOR" || prev[0] === "INDENT" || prev[0] === "OUTDENT") && (/^[a-zA-Z_$]/.test(this.chunk[1] || "") || this.chunk[1] === "@")) {
|
|
2053
2072
|
let rest = this.chunk.slice(1);
|
|
2073
|
+
let mAt = /^@(\s*)=(?!=)/.exec(rest);
|
|
2074
|
+
if (mAt) {
|
|
2075
|
+
let space = mAt[1];
|
|
2076
|
+
this.emit("IDENTIFIER", "Object");
|
|
2077
|
+
this.emit(".", ".");
|
|
2078
|
+
let t = this.emit("PROPERTY", "assign");
|
|
2079
|
+
t.spaced = true;
|
|
2080
|
+
this.emit("@", "@");
|
|
2081
|
+
this.emit(",", ",");
|
|
2082
|
+
return 1 + 1 + space.length + 1;
|
|
2083
|
+
}
|
|
2054
2084
|
let m = /^((?:(?!\s)[$\w\x7f-\uffff])+(?:\.[a-zA-Z_$][\w]*)*)(\s*)=(?!=)/.exec(rest);
|
|
2055
2085
|
if (m) {
|
|
2056
2086
|
let target = m[1], space = m[2];
|
|
@@ -2253,7 +2283,7 @@ class Lexer {
|
|
|
2253
2283
|
let isTemplateTag = (name) => {
|
|
2254
2284
|
return isHtmlTag(name) || isComponent(name);
|
|
2255
2285
|
};
|
|
2256
|
-
let
|
|
2286
|
+
let startsWithTag = (tokens, i) => {
|
|
2257
2287
|
let j = i;
|
|
2258
2288
|
while (j > 0) {
|
|
2259
2289
|
let pt = tokens[j - 1][0];
|
|
@@ -2262,7 +2292,7 @@ class Lexer {
|
|
|
2262
2292
|
}
|
|
2263
2293
|
j--;
|
|
2264
2294
|
}
|
|
2265
|
-
return tokens[j] && tokens[j][0] === "IDENTIFIER" &&
|
|
2295
|
+
return tokens[j] && tokens[j][0] === "IDENTIFIER" && isTemplateTag(tokens[j][1]);
|
|
2266
2296
|
};
|
|
2267
2297
|
this.scanTokens(function(token, i, tokens) {
|
|
2268
2298
|
let tag = token[0];
|
|
@@ -2328,7 +2358,7 @@ class Lexer {
|
|
|
2328
2358
|
if (tag === "IDENTIFIER" || tag === "PROPERTY") {
|
|
2329
2359
|
let next = tokens[i + 1];
|
|
2330
2360
|
let nextNext = tokens[i + 2];
|
|
2331
|
-
if (next && next[0] === "#" && nextNext && nextNext[0] === "PROPERTY") {
|
|
2361
|
+
if (next && next[0] === "#" && nextNext && (nextNext[0] === "PROPERTY" || nextNext[0] === "IDENTIFIER")) {
|
|
2332
2362
|
token[1] = token[1] + "#" + nextNext[1];
|
|
2333
2363
|
if (nextNext.spaced)
|
|
2334
2364
|
token.spaced = true;
|
|
@@ -2366,7 +2396,7 @@ class Lexer {
|
|
|
2366
2396
|
let prevToken = i > 0 ? tokens[i - 1] : null;
|
|
2367
2397
|
let prevTag = prevToken ? prevToken[0] : null;
|
|
2368
2398
|
let atLineStart = prevTag === "INDENT" || prevTag === "TERMINATOR";
|
|
2369
|
-
let cxToken = gen("PROPERTY", "
|
|
2399
|
+
let cxToken = gen("PROPERTY", "__clsx", token);
|
|
2370
2400
|
nextToken[0] = "CALL_START";
|
|
2371
2401
|
let depth = 1;
|
|
2372
2402
|
for (let j = i + 2;j < tokens.length && depth > 0; j++) {
|
|
@@ -2394,12 +2424,14 @@ class Lexer {
|
|
|
2394
2424
|
return 1;
|
|
2395
2425
|
}
|
|
2396
2426
|
let isTemplateElement = false;
|
|
2397
|
-
|
|
2427
|
+
let prevTag = i > 0 ? tokens[i - 1][0] : null;
|
|
2428
|
+
let isAfterControlFlow = prevTag === "IF" || prevTag === "UNLESS" || prevTag === "WHILE" || prevTag === "UNTIL" || prevTag === "WHEN";
|
|
2429
|
+
if (tag === "IDENTIFIER" && isTemplateTag(token[1]) && !isAfterControlFlow) {
|
|
2398
2430
|
isTemplateElement = true;
|
|
2399
2431
|
} else if (tag === "PROPERTY" || tag === "STRING" || tag === "CALL_END" || tag === ")") {
|
|
2400
|
-
isTemplateElement =
|
|
2432
|
+
isTemplateElement = startsWithTag(tokens, i);
|
|
2401
2433
|
} else if (tag === "IDENTIFIER" && i > 1 && tokens[i - 1][0] === "...") {
|
|
2402
|
-
if (
|
|
2434
|
+
if (startsWithTag(tokens, i)) {
|
|
2403
2435
|
let commaToken = gen(",", ",", token);
|
|
2404
2436
|
let arrowToken = gen("->", "->", token);
|
|
2405
2437
|
arrowToken.newLine = true;
|
|
@@ -2408,14 +2440,27 @@ class Lexer {
|
|
|
2408
2440
|
}
|
|
2409
2441
|
}
|
|
2410
2442
|
if (isTemplateElement) {
|
|
2411
|
-
let
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2443
|
+
let isClassOrIdTail = tag === "PROPERTY" && i > 0 && (tokens[i - 1][0] === "." || tokens[i - 1][0] === "#");
|
|
2444
|
+
if (tag === "IDENTIFIER" && isTemplateTag(token[1]) || isClassOrIdTail) {
|
|
2445
|
+
let callStartToken = gen("CALL_START", "(", token);
|
|
2446
|
+
let arrowToken = gen("->", "->", token);
|
|
2447
|
+
arrowToken.newLine = true;
|
|
2448
|
+
tokens.splice(i + 1, 0, callStartToken, arrowToken);
|
|
2449
|
+
pendingCallEnds.push(currentIndent + 1);
|
|
2450
|
+
return 3;
|
|
2451
|
+
} else {
|
|
2452
|
+
let commaToken = gen(",", ",", token);
|
|
2453
|
+
let arrowToken = gen("->", "->", token);
|
|
2454
|
+
arrowToken.newLine = true;
|
|
2455
|
+
tokens.splice(i + 1, 0, commaToken, arrowToken);
|
|
2456
|
+
return 3;
|
|
2457
|
+
}
|
|
2417
2458
|
}
|
|
2418
2459
|
}
|
|
2460
|
+
if (tag === "IDENTIFIER" && isComponent(token[1]) && nextToken && (nextToken[0] === "OUTDENT" || nextToken[0] === "TERMINATOR")) {
|
|
2461
|
+
tokens.splice(i + 1, 0, gen("CALL_START", "(", token), gen("CALL_END", ")", token));
|
|
2462
|
+
return 3;
|
|
2463
|
+
}
|
|
2419
2464
|
return 1;
|
|
2420
2465
|
});
|
|
2421
2466
|
}
|
|
@@ -3420,11 +3465,12 @@ var parserInstance = {
|
|
|
3420
3465
|
[TERROR, EOF] = [2, 1];
|
|
3421
3466
|
lexer = Object.create(this.lexer);
|
|
3422
3467
|
sharedState = { ctx: {} };
|
|
3423
|
-
for (const k in this.ctx)
|
|
3424
|
-
if (Object.hasOwn(this.ctx, k))
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3468
|
+
for (const k in this.ctx) {
|
|
3469
|
+
if (!Object.hasOwn(this.ctx, k))
|
|
3470
|
+
continue;
|
|
3471
|
+
const v = this.ctx[k];
|
|
3472
|
+
sharedState.ctx[k] = v;
|
|
3473
|
+
}
|
|
3428
3474
|
lexer.setInput(input, sharedState.ctx);
|
|
3429
3475
|
[sharedState.ctx.lexer, sharedState.ctx.parser] = [lexer, this];
|
|
3430
3476
|
if (lexer.loc == null)
|
|
@@ -3571,14 +3617,20 @@ function installComponentSupport(CodeGenerator) {
|
|
|
3571
3617
|
}
|
|
3572
3618
|
current = current[1];
|
|
3573
3619
|
}
|
|
3574
|
-
|
|
3575
|
-
|
|
3620
|
+
let raw = typeof current === "string" ? current : current instanceof String ? current.valueOf() : "div";
|
|
3621
|
+
let [tag, id] = raw.split("#");
|
|
3622
|
+
if (!tag)
|
|
3623
|
+
tag = "div";
|
|
3624
|
+
return { tag, classes, id };
|
|
3576
3625
|
};
|
|
3577
3626
|
proto.transformComponentMembers = function(sexpr) {
|
|
3578
3627
|
if (!Array.isArray(sexpr)) {
|
|
3579
3628
|
if (typeof sexpr === "string" && this.reactiveMembers && this.reactiveMembers.has(sexpr)) {
|
|
3580
3629
|
return [".", [".", "this", sexpr], "value"];
|
|
3581
3630
|
}
|
|
3631
|
+
if (typeof sexpr === "string" && this.componentMembers && this.componentMembers.has(sexpr)) {
|
|
3632
|
+
return [".", "this", sexpr];
|
|
3633
|
+
}
|
|
3582
3634
|
return sexpr;
|
|
3583
3635
|
}
|
|
3584
3636
|
if (sexpr[0] === "." && sexpr[1] === "this" && typeof sexpr[2] === "string") {
|
|
@@ -3588,6 +3640,9 @@ function installComponentSupport(CodeGenerator) {
|
|
|
3588
3640
|
}
|
|
3589
3641
|
return sexpr;
|
|
3590
3642
|
}
|
|
3643
|
+
if (sexpr[0] === ".") {
|
|
3644
|
+
return [".", this.transformComponentMembers(sexpr[1]), sexpr[2]];
|
|
3645
|
+
}
|
|
3591
3646
|
if (sexpr[0] === "->") {
|
|
3592
3647
|
return ["=>", ...sexpr.slice(1).map((item) => this.transformComponentMembers(item))];
|
|
3593
3648
|
}
|
|
@@ -3673,43 +3728,43 @@ function installComponentSupport(CodeGenerator) {
|
|
|
3673
3728
|
this.reactiveMembers = reactiveMembers;
|
|
3674
3729
|
const lines = [];
|
|
3675
3730
|
let blockFactoriesCode = "";
|
|
3676
|
-
lines.push("class {");
|
|
3677
|
-
lines.push("
|
|
3678
|
-
lines.push(" const __prevComponent = __pushComponent(this);");
|
|
3679
|
-
lines.push("");
|
|
3731
|
+
lines.push("class extends __Component {");
|
|
3732
|
+
lines.push(" _init(props) {");
|
|
3680
3733
|
for (const { name, value } of readonlyVars) {
|
|
3681
3734
|
const val = this.generateInComponent(value, "value");
|
|
3682
3735
|
lines.push(` this.${name} = props.${name} ?? ${val};`);
|
|
3683
3736
|
}
|
|
3684
3737
|
for (const { name, value } of stateVars) {
|
|
3685
3738
|
const val = this.generateInComponent(value, "value");
|
|
3686
|
-
lines.push(` this.${name} =
|
|
3739
|
+
lines.push(` this.${name} = __state(props.${name} ?? ${val});`);
|
|
3687
3740
|
}
|
|
3688
3741
|
for (const { name, expr } of derivedVars) {
|
|
3689
3742
|
const val = this.generateInComponent(expr, "value");
|
|
3690
3743
|
lines.push(` this.${name} = __computed(() => ${val});`);
|
|
3691
3744
|
}
|
|
3692
3745
|
for (const effect of effects) {
|
|
3693
|
-
const effectBody = effect[
|
|
3746
|
+
const effectBody = effect[2];
|
|
3694
3747
|
const effectCode = this.generateInComponent(effectBody, "value");
|
|
3695
|
-
lines.push(` __effect(${effectCode});`);
|
|
3748
|
+
lines.push(` __effect(() => { ${effectCode}; });`);
|
|
3696
3749
|
}
|
|
3697
|
-
lines.push("");
|
|
3698
|
-
lines.push(" __popComponent(__prevComponent);");
|
|
3699
3750
|
lines.push(" }");
|
|
3700
3751
|
for (const { name, func } of methods) {
|
|
3701
3752
|
if (Array.isArray(func) && (func[0] === "->" || func[0] === "=>")) {
|
|
3702
3753
|
const [, params, methodBody] = func;
|
|
3703
3754
|
const paramStr = Array.isArray(params) ? params.map((p) => this.formatParam(p)).join(", ") : "";
|
|
3704
|
-
const
|
|
3705
|
-
|
|
3755
|
+
const transformed = this.reactiveMembers ? this.transformComponentMembers(methodBody) : methodBody;
|
|
3756
|
+
const isAsync = this.containsAwait(methodBody);
|
|
3757
|
+
const bodyCode = this.generateFunctionBody(transformed, params || []);
|
|
3758
|
+
lines.push(` ${isAsync ? "async " : ""}${name}(${paramStr}) ${bodyCode}`);
|
|
3706
3759
|
}
|
|
3707
3760
|
}
|
|
3708
3761
|
for (const { name, value } of lifecycleHooks) {
|
|
3709
3762
|
if (Array.isArray(value) && (value[0] === "->" || value[0] === "=>")) {
|
|
3710
3763
|
const [, , hookBody] = value;
|
|
3711
|
-
const
|
|
3712
|
-
|
|
3764
|
+
const transformed = this.reactiveMembers ? this.transformComponentMembers(hookBody) : hookBody;
|
|
3765
|
+
const isAsync = this.containsAwait(hookBody);
|
|
3766
|
+
const bodyCode = this.generateFunctionBody(transformed, []);
|
|
3767
|
+
lines.push(` ${isAsync ? "async " : ""}${name}() ${bodyCode}`);
|
|
3713
3768
|
}
|
|
3714
3769
|
}
|
|
3715
3770
|
if (renderBlock) {
|
|
@@ -3736,21 +3791,6 @@ function installComponentSupport(CodeGenerator) {
|
|
|
3736
3791
|
lines.push(" }");
|
|
3737
3792
|
}
|
|
3738
3793
|
}
|
|
3739
|
-
lines.push(" mount(target) {");
|
|
3740
|
-
lines.push(' if (typeof target === "string") target = document.querySelector(target);');
|
|
3741
|
-
lines.push(" this._target = target;");
|
|
3742
|
-
lines.push(" this._root = this._create();");
|
|
3743
|
-
lines.push(" target.appendChild(this._root);");
|
|
3744
|
-
lines.push(" if (this._setup) this._setup();");
|
|
3745
|
-
lines.push(" if (this.mounted) this.mounted();");
|
|
3746
|
-
lines.push(" return this;");
|
|
3747
|
-
lines.push(" }");
|
|
3748
|
-
lines.push(" unmount() {");
|
|
3749
|
-
lines.push(" if (this.unmounted) this.unmounted();");
|
|
3750
|
-
lines.push(" if (this._root && this._root.parentNode) {");
|
|
3751
|
-
lines.push(" this._root.parentNode.removeChild(this._root);");
|
|
3752
|
-
lines.push(" }");
|
|
3753
|
-
lines.push(" }");
|
|
3754
3794
|
lines.push("}");
|
|
3755
3795
|
this.componentMembers = prevComponentMembers;
|
|
3756
3796
|
this.reactiveMembers = prevReactiveMembers;
|
|
@@ -3767,6 +3807,9 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
3767
3807
|
if (typeof sexpr === "string" && this.reactiveMembers && this.reactiveMembers.has(sexpr)) {
|
|
3768
3808
|
return `this.${sexpr}.value`;
|
|
3769
3809
|
}
|
|
3810
|
+
if (typeof sexpr === "string" && this.componentMembers && this.componentMembers.has(sexpr)) {
|
|
3811
|
+
return `this.${sexpr}`;
|
|
3812
|
+
}
|
|
3770
3813
|
if (Array.isArray(sexpr) && this.reactiveMembers) {
|
|
3771
3814
|
const transformed = this.transformComponentMembers(sexpr);
|
|
3772
3815
|
return this.generate(transformed, context);
|
|
@@ -3827,8 +3870,11 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
3827
3870
|
this._setupLines.push(`__effect(() => { ${textVar2}.data = this.${str}.value; });`);
|
|
3828
3871
|
return textVar2;
|
|
3829
3872
|
}
|
|
3873
|
+
const [tagStr, idStr] = str.split("#");
|
|
3830
3874
|
const elVar = this.newElementVar();
|
|
3831
|
-
this._createLines.push(`${elVar} = document.createElement('${
|
|
3875
|
+
this._createLines.push(`${elVar} = document.createElement('${tagStr || "div"}');`);
|
|
3876
|
+
if (idStr)
|
|
3877
|
+
this._createLines.push(`${elVar}.id = '${idStr}';`);
|
|
3832
3878
|
return elVar;
|
|
3833
3879
|
}
|
|
3834
3880
|
if (!Array.isArray(sexpr)) {
|
|
@@ -3842,7 +3888,8 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
3842
3888
|
return this.generateChildComponent(headStr, rest);
|
|
3843
3889
|
}
|
|
3844
3890
|
if (headStr && this.isHtmlTag(headStr)) {
|
|
3845
|
-
|
|
3891
|
+
let [tagName, id] = headStr.split("#");
|
|
3892
|
+
return this.generateTag(tagName || "div", [], rest, id);
|
|
3846
3893
|
}
|
|
3847
3894
|
if (headStr === ".") {
|
|
3848
3895
|
const [, obj, prop] = sexpr;
|
|
@@ -3853,15 +3900,13 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
3853
3900
|
this._setupLines.push(`__effect(() => { ${textVar3}.data = this.${prop}.value; });`);
|
|
3854
3901
|
return textVar3;
|
|
3855
3902
|
}
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
return slotVar;
|
|
3860
|
-
}
|
|
3903
|
+
const slotVar = this.newElementVar("slot");
|
|
3904
|
+
this._createLines.push(`${slotVar} = this.${prop} instanceof Node ? this.${prop} : (this.${prop} != null ? document.createTextNode(String(this.${prop})) : document.createComment(''));`);
|
|
3905
|
+
return slotVar;
|
|
3861
3906
|
}
|
|
3862
|
-
const { tag, classes } = this.collectTemplateClasses(sexpr);
|
|
3907
|
+
const { tag, classes, id } = this.collectTemplateClasses(sexpr);
|
|
3863
3908
|
if (tag && this.isHtmlTag(tag)) {
|
|
3864
|
-
return this.generateTag(tag, classes, []);
|
|
3909
|
+
return this.generateTag(tag, classes, [], id);
|
|
3865
3910
|
}
|
|
3866
3911
|
const textVar2 = this.newTextVar();
|
|
3867
3912
|
const exprCode2 = this.generateInComponent(sexpr, "value");
|
|
@@ -3869,17 +3914,17 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
3869
3914
|
return textVar2;
|
|
3870
3915
|
}
|
|
3871
3916
|
if (Array.isArray(head)) {
|
|
3872
|
-
if (Array.isArray(head[0]) && head[0][0] === "." && (head[0][2] === "
|
|
3917
|
+
if (Array.isArray(head[0]) && head[0][0] === "." && (head[0][2] === "__clsx" || head[0][2] instanceof String && head[0][2].valueOf() === "__clsx")) {
|
|
3873
3918
|
const tag2 = typeof head[0][1] === "string" ? head[0][1] : head[0][1].valueOf();
|
|
3874
3919
|
const classExprs = head.slice(1);
|
|
3875
3920
|
return this.generateDynamicTag(tag2, classExprs, rest);
|
|
3876
3921
|
}
|
|
3877
|
-
const { tag, classes } = this.collectTemplateClasses(head);
|
|
3922
|
+
const { tag, classes, id } = this.collectTemplateClasses(head);
|
|
3878
3923
|
if (tag && this.isHtmlTag(tag)) {
|
|
3879
|
-
if (classes.length === 1 && classes[0] === "
|
|
3924
|
+
if (classes.length === 1 && classes[0] === "__clsx") {
|
|
3880
3925
|
return this.generateDynamicTag(tag, rest, []);
|
|
3881
3926
|
}
|
|
3882
|
-
return this.generateTag(tag, classes, rest);
|
|
3927
|
+
return this.generateTag(tag, classes, rest, id);
|
|
3883
3928
|
}
|
|
3884
3929
|
}
|
|
3885
3930
|
if (headStr === "->" || headStr === "=>") {
|
|
@@ -3901,14 +3946,9 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
3901
3946
|
}
|
|
3902
3947
|
return textVar;
|
|
3903
3948
|
};
|
|
3904
|
-
proto.
|
|
3905
|
-
const elVar = this.newElementVar();
|
|
3906
|
-
this._createLines.push(`${elVar} = document.createElement('${tag}');`);
|
|
3907
|
-
if (classes.length > 0) {
|
|
3908
|
-
this._createLines.push(`${elVar}.className = '${classes.join(" ")}';`);
|
|
3909
|
-
}
|
|
3949
|
+
proto.appendChildren = function(elVar, args) {
|
|
3910
3950
|
for (const arg of args) {
|
|
3911
|
-
if (
|
|
3951
|
+
if (this.is(arg, "->") || this.is(arg, "=>")) {
|
|
3912
3952
|
const block = arg[2];
|
|
3913
3953
|
if (this.is(block, "block")) {
|
|
3914
3954
|
for (const child of block.slice(1)) {
|
|
@@ -3921,29 +3961,18 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
3921
3961
|
}
|
|
3922
3962
|
} else if (this.is(arg, "object")) {
|
|
3923
3963
|
this.generateAttributes(elVar, arg);
|
|
3924
|
-
} else if (typeof arg === "string") {
|
|
3964
|
+
} else if (typeof arg === "string" || arg instanceof String) {
|
|
3925
3965
|
const textVar = this.newTextVar();
|
|
3926
|
-
if (arg.startsWith('"') || arg.startsWith("'") || arg.startsWith("`")) {
|
|
3927
|
-
this._createLines.push(`${textVar} = document.createTextNode(${arg});`);
|
|
3928
|
-
} else if (this.reactiveMembers && this.reactiveMembers.has(arg)) {
|
|
3929
|
-
this._createLines.push(`${textVar} = document.createTextNode('');`);
|
|
3930
|
-
this._setupLines.push(`__effect(() => { ${textVar}.data = this.${arg}.value; });`);
|
|
3931
|
-
} else if (this.componentMembers && this.componentMembers.has(arg)) {
|
|
3932
|
-
this._createLines.push(`${textVar} = document.createTextNode(String(this.${arg}));`);
|
|
3933
|
-
} else {
|
|
3934
|
-
this._createLines.push(`${textVar} = document.createTextNode(String(${arg}));`);
|
|
3935
|
-
}
|
|
3936
|
-
this._createLines.push(`${elVar}.appendChild(${textVar});`);
|
|
3937
|
-
} else if (arg instanceof String) {
|
|
3938
3966
|
const val = arg.valueOf();
|
|
3939
|
-
const textVar = this.newTextVar();
|
|
3940
3967
|
if (val.startsWith('"') || val.startsWith("'") || val.startsWith("`")) {
|
|
3941
3968
|
this._createLines.push(`${textVar} = document.createTextNode(${val});`);
|
|
3942
3969
|
} else if (this.reactiveMembers && this.reactiveMembers.has(val)) {
|
|
3943
3970
|
this._createLines.push(`${textVar} = document.createTextNode('');`);
|
|
3944
3971
|
this._setupLines.push(`__effect(() => { ${textVar}.data = this.${val}.value; });`);
|
|
3972
|
+
} else if (this.componentMembers && this.componentMembers.has(val)) {
|
|
3973
|
+
this._createLines.push(`${textVar} = document.createTextNode(String(this.${val}));`);
|
|
3945
3974
|
} else {
|
|
3946
|
-
this._createLines.push(`${textVar} = document.createTextNode(
|
|
3975
|
+
this._createLines.push(`${textVar} = document.createTextNode(${this.generateInComponent(arg, "value")});`);
|
|
3947
3976
|
}
|
|
3948
3977
|
this._createLines.push(`${elVar}.appendChild(${textVar});`);
|
|
3949
3978
|
} else if (arg) {
|
|
@@ -3951,6 +3980,17 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
3951
3980
|
this._createLines.push(`${elVar}.appendChild(${childVar});`);
|
|
3952
3981
|
}
|
|
3953
3982
|
}
|
|
3983
|
+
};
|
|
3984
|
+
proto.generateTag = function(tag, classes, args, id) {
|
|
3985
|
+
const elVar = this.newElementVar();
|
|
3986
|
+
this._createLines.push(`${elVar} = document.createElement('${tag}');`);
|
|
3987
|
+
if (id) {
|
|
3988
|
+
this._createLines.push(`${elVar}.id = '${id}';`);
|
|
3989
|
+
}
|
|
3990
|
+
if (classes.length > 0) {
|
|
3991
|
+
this._createLines.push(`${elVar}.className = '${classes.join(" ")}';`);
|
|
3992
|
+
}
|
|
3993
|
+
this.appendChildren(elVar, args);
|
|
3954
3994
|
return elVar;
|
|
3955
3995
|
};
|
|
3956
3996
|
proto.generateDynamicTag = function(tag, classExprs, children) {
|
|
@@ -3958,46 +3998,9 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
3958
3998
|
this._createLines.push(`${elVar} = document.createElement('${tag}');`);
|
|
3959
3999
|
if (classExprs.length > 0) {
|
|
3960
4000
|
const classArgs = classExprs.map((e) => this.generateInComponent(e, "value")).join(", ");
|
|
3961
|
-
|
|
3962
|
-
if (hasReactive) {
|
|
3963
|
-
this._setupLines.push(`__effect(() => { ${elVar}.className = __cx__(${classArgs}); });`);
|
|
3964
|
-
} else {
|
|
3965
|
-
this._createLines.push(`${elVar}.className = __cx__(${classArgs});`);
|
|
3966
|
-
}
|
|
3967
|
-
}
|
|
3968
|
-
for (const arg of children) {
|
|
3969
|
-
const argHead = Array.isArray(arg) ? arg[0] instanceof String ? arg[0].valueOf() : arg[0] : null;
|
|
3970
|
-
if (argHead === "->" || argHead === "=>") {
|
|
3971
|
-
const block = arg[2];
|
|
3972
|
-
const blockHead = Array.isArray(block) ? block[0] instanceof String ? block[0].valueOf() : block[0] : null;
|
|
3973
|
-
if (blockHead === "block") {
|
|
3974
|
-
for (const child of block.slice(1)) {
|
|
3975
|
-
const childVar = this.generateNode(child);
|
|
3976
|
-
this._createLines.push(`${elVar}.appendChild(${childVar});`);
|
|
3977
|
-
}
|
|
3978
|
-
} else if (block) {
|
|
3979
|
-
const childVar = this.generateNode(block);
|
|
3980
|
-
this._createLines.push(`${elVar}.appendChild(${childVar});`);
|
|
3981
|
-
}
|
|
3982
|
-
} else if (this.is(arg, "object")) {
|
|
3983
|
-
this.generateAttributes(elVar, arg);
|
|
3984
|
-
} else if (typeof arg === "string" || arg instanceof String) {
|
|
3985
|
-
const textVar = this.newTextVar();
|
|
3986
|
-
const argStr = arg.valueOf();
|
|
3987
|
-
if (argStr.startsWith('"') || argStr.startsWith("'") || argStr.startsWith("`")) {
|
|
3988
|
-
this._createLines.push(`${textVar} = document.createTextNode(${argStr});`);
|
|
3989
|
-
} else if (this.reactiveMembers && this.reactiveMembers.has(argStr)) {
|
|
3990
|
-
this._createLines.push(`${textVar} = document.createTextNode('');`);
|
|
3991
|
-
this._setupLines.push(`__effect(() => { ${textVar}.data = this.${argStr}.value; });`);
|
|
3992
|
-
} else {
|
|
3993
|
-
this._createLines.push(`${textVar} = document.createTextNode(${this.generateInComponent(arg, "value")});`);
|
|
3994
|
-
}
|
|
3995
|
-
this._createLines.push(`${elVar}.appendChild(${textVar});`);
|
|
3996
|
-
} else {
|
|
3997
|
-
const childVar = this.generateNode(arg);
|
|
3998
|
-
this._createLines.push(`${elVar}.appendChild(${childVar});`);
|
|
3999
|
-
}
|
|
4001
|
+
this._setupLines.push(`__effect(() => { ${elVar}.className = __clsx(${classArgs}); });`);
|
|
4000
4002
|
}
|
|
4003
|
+
this.appendChildren(elVar, children);
|
|
4001
4004
|
return elVar;
|
|
4002
4005
|
};
|
|
4003
4006
|
proto.generateAttributes = function(elVar, objExpr) {
|
|
@@ -4006,14 +4009,23 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
4006
4009
|
let [key, value] = objExpr[i];
|
|
4007
4010
|
if (this.is(key, ".") && key[1] === "this") {
|
|
4008
4011
|
const eventName = key[2];
|
|
4009
|
-
|
|
4010
|
-
|
|
4012
|
+
if (typeof value === "string" && this.componentMembers?.has(value)) {
|
|
4013
|
+
this._createLines.push(`${elVar}.addEventListener('${eventName}', (e) => this.${value}(e));`);
|
|
4014
|
+
} else {
|
|
4015
|
+
const handlerCode = this.generateInComponent(value, "value");
|
|
4016
|
+
this._createLines.push(`${elVar}.addEventListener('${eventName}', (e) => (${handlerCode})(e));`);
|
|
4017
|
+
}
|
|
4011
4018
|
continue;
|
|
4012
4019
|
}
|
|
4013
4020
|
if (typeof key === "string") {
|
|
4014
4021
|
if (key.startsWith('"') && key.endsWith('"')) {
|
|
4015
4022
|
key = key.slice(1, -1);
|
|
4016
4023
|
}
|
|
4024
|
+
if (key === "ref") {
|
|
4025
|
+
const refName = String(value).replace(/^["']|["']$/g, "");
|
|
4026
|
+
this._createLines.push(`this.${refName} = ${elVar};`);
|
|
4027
|
+
continue;
|
|
4028
|
+
}
|
|
4017
4029
|
if (key.startsWith(BIND_PREFIX) && key.endsWith(BIND_SUFFIX)) {
|
|
4018
4030
|
const prop = key.slice(BIND_PREFIX.length, -BIND_SUFFIX.length);
|
|
4019
4031
|
const valueCode2 = this.generateInComponent(value, "value");
|
|
@@ -4298,6 +4310,7 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
4298
4310
|
const { propsCode, childrenSetupLines } = this.buildComponentProps(args);
|
|
4299
4311
|
this._createLines.push(`${instVar} = new ${componentName}(${propsCode});`);
|
|
4300
4312
|
this._createLines.push(`${elVar} = ${instVar}._create();`);
|
|
4313
|
+
this._createLines.push(`(this._children || (this._children = [])).push(${instVar});`);
|
|
4301
4314
|
this._setupLines.push(`if (${instVar}._setup) ${instVar}._setup();`);
|
|
4302
4315
|
for (const line of childrenSetupLines) {
|
|
4303
4316
|
this._setupLines.push(line);
|
|
@@ -4313,7 +4326,10 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
4313
4326
|
for (let i = 1;i < arg.length; i++) {
|
|
4314
4327
|
const [key, value] = arg[i];
|
|
4315
4328
|
if (typeof key === "string") {
|
|
4329
|
+
const prevReactive = this.reactiveMembers;
|
|
4330
|
+
this.reactiveMembers = new Set;
|
|
4316
4331
|
const valueCode = this.generateInComponent(value, "value");
|
|
4332
|
+
this.reactiveMembers = prevReactive;
|
|
4317
4333
|
props.push(`${key}: ${valueCode}`);
|
|
4318
4334
|
}
|
|
4319
4335
|
}
|
|
@@ -4341,15 +4357,16 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
4341
4357
|
return { propsCode, childrenSetupLines };
|
|
4342
4358
|
};
|
|
4343
4359
|
proto.hasReactiveDeps = function(sexpr) {
|
|
4344
|
-
if (!this.reactiveMembers || this.reactiveMembers.size === 0)
|
|
4345
|
-
return false;
|
|
4346
4360
|
if (typeof sexpr === "string") {
|
|
4347
|
-
return this.reactiveMembers.has(sexpr);
|
|
4361
|
+
return !!(this.reactiveMembers && this.reactiveMembers.has(sexpr));
|
|
4348
4362
|
}
|
|
4349
4363
|
if (!Array.isArray(sexpr))
|
|
4350
4364
|
return false;
|
|
4351
4365
|
if (sexpr[0] === "." && sexpr[1] === "this" && typeof sexpr[2] === "string") {
|
|
4352
|
-
return this.reactiveMembers.has(sexpr[2]);
|
|
4366
|
+
return !!(this.reactiveMembers && this.reactiveMembers.has(sexpr[2]));
|
|
4367
|
+
}
|
|
4368
|
+
if (sexpr[0] === "." && this._rootsAtThis(sexpr[1])) {
|
|
4369
|
+
return true;
|
|
4353
4370
|
}
|
|
4354
4371
|
for (const child of sexpr) {
|
|
4355
4372
|
if (this.hasReactiveDeps(child))
|
|
@@ -4357,16 +4374,19 @@ ${blockFactoriesCode}return ${lines.join(`
|
|
|
4357
4374
|
}
|
|
4358
4375
|
return false;
|
|
4359
4376
|
};
|
|
4377
|
+
proto._rootsAtThis = function(sexpr) {
|
|
4378
|
+
if (typeof sexpr === "string")
|
|
4379
|
+
return sexpr === "this";
|
|
4380
|
+
if (!Array.isArray(sexpr) || sexpr[0] !== ".")
|
|
4381
|
+
return false;
|
|
4382
|
+
return this._rootsAtThis(sexpr[1]);
|
|
4383
|
+
};
|
|
4360
4384
|
proto.getComponentRuntime = function() {
|
|
4361
4385
|
return `
|
|
4362
4386
|
// ============================================================================
|
|
4363
4387
|
// Rip Component Runtime
|
|
4364
4388
|
// ============================================================================
|
|
4365
4389
|
|
|
4366
|
-
function isSignal(v) {
|
|
4367
|
-
return v != null && typeof v === 'object' && typeof v.read === 'function';
|
|
4368
|
-
}
|
|
4369
|
-
|
|
4370
4390
|
let __currentComponent = null;
|
|
4371
4391
|
|
|
4372
4392
|
function __pushComponent(component) {
|
|
@@ -4404,13 +4424,43 @@ function hasContext(key) {
|
|
|
4404
4424
|
return false;
|
|
4405
4425
|
}
|
|
4406
4426
|
|
|
4407
|
-
function
|
|
4427
|
+
function __clsx(...args) {
|
|
4408
4428
|
return args.filter(Boolean).join(' ');
|
|
4409
4429
|
}
|
|
4410
4430
|
|
|
4431
|
+
class __Component {
|
|
4432
|
+
constructor(props = {}) {
|
|
4433
|
+
Object.assign(this, props);
|
|
4434
|
+
const prev = __pushComponent(this);
|
|
4435
|
+
this._init(props);
|
|
4436
|
+
__popComponent(prev);
|
|
4437
|
+
}
|
|
4438
|
+
_init() {}
|
|
4439
|
+
mount(target) {
|
|
4440
|
+
if (typeof target === "string") target = document.querySelector(target);
|
|
4441
|
+
this._target = target;
|
|
4442
|
+
this._root = this._create();
|
|
4443
|
+
target.appendChild(this._root);
|
|
4444
|
+
if (this._setup) this._setup();
|
|
4445
|
+
if (this.mounted) this.mounted();
|
|
4446
|
+
return this;
|
|
4447
|
+
}
|
|
4448
|
+
unmount() {
|
|
4449
|
+
if (this._children) {
|
|
4450
|
+
for (const child of this._children) {
|
|
4451
|
+
child.unmount();
|
|
4452
|
+
}
|
|
4453
|
+
}
|
|
4454
|
+
if (this.unmounted) this.unmounted();
|
|
4455
|
+
if (this._root && this._root.parentNode) {
|
|
4456
|
+
this._root.parentNode.removeChild(this._root);
|
|
4457
|
+
}
|
|
4458
|
+
}
|
|
4459
|
+
}
|
|
4460
|
+
|
|
4411
4461
|
// Register on globalThis for runtime deduplication
|
|
4412
4462
|
if (typeof globalThis !== 'undefined') {
|
|
4413
|
-
globalThis.__ripComponent = {
|
|
4463
|
+
globalThis.__ripComponent = { __pushComponent, __popComponent, setContext, getContext, hasContext, __clsx, __Component };
|
|
4414
4464
|
}
|
|
4415
4465
|
|
|
4416
4466
|
`;
|
|
@@ -4742,9 +4792,7 @@ class CodeGenerator {
|
|
|
4742
4792
|
readonly: "generateReadonly",
|
|
4743
4793
|
effect: "generateEffect",
|
|
4744
4794
|
break: "generateBreak",
|
|
4745
|
-
"break-if": "generateBreakIf",
|
|
4746
4795
|
continue: "generateContinue",
|
|
4747
|
-
"continue-if": "generateContinueIf",
|
|
4748
4796
|
"?": "generateExistential",
|
|
4749
4797
|
"?:": "generateTernary",
|
|
4750
4798
|
"|>": "generatePipe",
|
|
@@ -4797,6 +4845,7 @@ class CodeGenerator {
|
|
|
4797
4845
|
this.programVars = new Set;
|
|
4798
4846
|
this.functionVars = new Map;
|
|
4799
4847
|
this.helpers = new Set;
|
|
4848
|
+
this.scopeStack = [];
|
|
4800
4849
|
this.collectProgramVariables(sexpr);
|
|
4801
4850
|
let code = this.generate(sexpr);
|
|
4802
4851
|
if (this.sourceMap)
|
|
@@ -4870,6 +4919,8 @@ class CodeGenerator {
|
|
|
4870
4919
|
}
|
|
4871
4920
|
if (head === "readonly")
|
|
4872
4921
|
return;
|
|
4922
|
+
if (head === "component")
|
|
4923
|
+
return;
|
|
4873
4924
|
if (CodeGenerator.ASSIGNMENT_OPS.has(head)) {
|
|
4874
4925
|
let [target, value] = rest;
|
|
4875
4926
|
if (typeof target === "string" || target instanceof String) {
|
|
@@ -5226,7 +5277,7 @@ class CodeGenerator {
|
|
|
5226
5277
|
}
|
|
5227
5278
|
if (this.usesTemplates && !skip) {
|
|
5228
5279
|
if (typeof globalThis !== "undefined" && globalThis.__ripComponent) {
|
|
5229
|
-
code += `const {
|
|
5280
|
+
code += `const { __pushComponent, __popComponent, setContext, getContext, hasContext, __clsx, __Component } = globalThis.__ripComponent;
|
|
5230
5281
|
`;
|
|
5231
5282
|
} else {
|
|
5232
5283
|
code += this.getComponentRuntime();
|
|
@@ -5418,10 +5469,15 @@ function _setDataSection() {
|
|
|
5418
5469
|
}
|
|
5419
5470
|
generatePropertyAccess(head, rest, context, sexpr) {
|
|
5420
5471
|
let [obj, prop] = rest;
|
|
5472
|
+
if (this._atParamMap && obj === "this") {
|
|
5473
|
+
let mapped = this._atParamMap.get(str(prop));
|
|
5474
|
+
if (mapped)
|
|
5475
|
+
return mapped;
|
|
5476
|
+
}
|
|
5421
5477
|
this.suppressReactiveUnwrap = true;
|
|
5422
5478
|
let objCode = this.generate(obj, "value");
|
|
5423
5479
|
this.suppressReactiveUnwrap = false;
|
|
5424
|
-
let needsParens = CodeGenerator.NUMBER_LITERAL_RE.test(objCode) ||
|
|
5480
|
+
let needsParens = CodeGenerator.NUMBER_LITERAL_RE.test(objCode) || objCode.startsWith("await ") || (this.is(obj, "object") || this.is(obj, "yield"));
|
|
5425
5481
|
let base = needsParens ? `(${objCode})` : objCode;
|
|
5426
5482
|
if (meta(prop, "await") === true)
|
|
5427
5483
|
return `await ${base}.${str(prop)}()`;
|
|
@@ -5608,15 +5664,9 @@ ${this.indent()}}`;
|
|
|
5608
5664
|
generateBreak() {
|
|
5609
5665
|
return "break";
|
|
5610
5666
|
}
|
|
5611
|
-
generateBreakIf(head, rest) {
|
|
5612
|
-
return `if (${this.generate(rest[0], "value")}) break`;
|
|
5613
|
-
}
|
|
5614
5667
|
generateContinue() {
|
|
5615
5668
|
return "continue";
|
|
5616
5669
|
}
|
|
5617
|
-
generateContinueIf(head, rest) {
|
|
5618
|
-
return `if (${this.generate(rest[0], "value")}) continue`;
|
|
5619
|
-
}
|
|
5620
5670
|
generateExistential(head, rest) {
|
|
5621
5671
|
return `(${this.generate(rest[0], "value")} != null)`;
|
|
5622
5672
|
}
|
|
@@ -6027,8 +6077,11 @@ ${this.indent()}}`;
|
|
|
6027
6077
|
keyCode = `[${this.generate(key[1], "value")}]`;
|
|
6028
6078
|
else if (this.is(key, "str"))
|
|
6029
6079
|
keyCode = `[${this.generate(key, "value")}]`;
|
|
6030
|
-
else
|
|
6080
|
+
else {
|
|
6081
|
+
this.suppressReactiveUnwrap = true;
|
|
6031
6082
|
keyCode = this.generate(key, "value");
|
|
6083
|
+
this.suppressReactiveUnwrap = false;
|
|
6084
|
+
}
|
|
6032
6085
|
let valCode = this.generate(value, "value");
|
|
6033
6086
|
if (operator === "=")
|
|
6034
6087
|
return `${keyCode} = ${valCode}`;
|
|
@@ -6180,6 +6233,52 @@ ${this.indent()}}`;
|
|
|
6180
6233
|
generateWhen() {
|
|
6181
6234
|
throw new Error("when clause should be handled by switch");
|
|
6182
6235
|
}
|
|
6236
|
+
_forInHeader(vars, iterable, step) {
|
|
6237
|
+
let va = Array.isArray(vars) ? vars : [vars];
|
|
6238
|
+
let noVar = va.length === 0;
|
|
6239
|
+
let [itemVar, indexVar] = noVar ? ["_i", null] : va;
|
|
6240
|
+
let ivp = this.is(itemVar, "array") || this.is(itemVar, "object") ? this.generateDestructuringPattern(itemVar) : itemVar;
|
|
6241
|
+
if (step && step !== null) {
|
|
6242
|
+
let ih = Array.isArray(iterable) && iterable[0];
|
|
6243
|
+
if (ih instanceof String)
|
|
6244
|
+
ih = str(ih);
|
|
6245
|
+
let isRange = ih === ".." || ih === "...";
|
|
6246
|
+
if (isRange) {
|
|
6247
|
+
let isExcl = ih === "...";
|
|
6248
|
+
let [s, e] = iterable.slice(1);
|
|
6249
|
+
let sc = this.generate(s, "value"), ec = this.generate(e, "value"), stc2 = this.generate(step, "value");
|
|
6250
|
+
return { header: `for (let ${ivp} = ${sc}; ${ivp} ${isExcl ? "<" : "<="} ${ec}; ${ivp} += ${stc2})`, setup: null };
|
|
6251
|
+
}
|
|
6252
|
+
let ic = this.generate(iterable, "value"), idxN = indexVar || "_i", stc = this.generate(step, "value");
|
|
6253
|
+
let isNeg = this.is(step, "-", 1);
|
|
6254
|
+
let isMinus1 = isNeg && (step[1] === "1" || step[1] === 1 || str(step[1]) === "1");
|
|
6255
|
+
let isPlus1 = !isNeg && (step === "1" || step === 1 || str(step) === "1");
|
|
6256
|
+
let update = isMinus1 ? `${idxN}--` : isPlus1 ? `${idxN}++` : `${idxN} += ${stc}`;
|
|
6257
|
+
let header = isNeg ? `for (let ${idxN} = ${ic}.length - 1; ${idxN} >= 0; ${update})` : `for (let ${idxN} = 0; ${idxN} < ${ic}.length; ${update})`;
|
|
6258
|
+
return { header, setup: noVar ? null : `const ${ivp} = ${ic}[${idxN}];` };
|
|
6259
|
+
}
|
|
6260
|
+
if (indexVar) {
|
|
6261
|
+
let ic = this.generate(iterable, "value");
|
|
6262
|
+
return {
|
|
6263
|
+
header: `for (let ${indexVar} = 0; ${indexVar} < ${ic}.length; ${indexVar}++)`,
|
|
6264
|
+
setup: `const ${ivp} = ${ic}[${indexVar}];`
|
|
6265
|
+
};
|
|
6266
|
+
}
|
|
6267
|
+
return { header: `for (const ${ivp} of ${this.generate(iterable, "value")})`, setup: null };
|
|
6268
|
+
}
|
|
6269
|
+
_forOfHeader(vars, iterable, own) {
|
|
6270
|
+
let va = Array.isArray(vars) ? vars : [vars];
|
|
6271
|
+
let [kv, vv] = va;
|
|
6272
|
+
let kvp = this.is(kv, "array") || this.is(kv, "object") ? this.generateDestructuringPattern(kv) : kv;
|
|
6273
|
+
let oc = this.generate(iterable, "value");
|
|
6274
|
+
return { header: `for (const ${kvp} in ${oc})`, own, vv, oc, kvp };
|
|
6275
|
+
}
|
|
6276
|
+
_forAsHeader(vars, iterable, isAwait) {
|
|
6277
|
+
let va = Array.isArray(vars) ? vars : [vars];
|
|
6278
|
+
let [fv] = va;
|
|
6279
|
+
let ivp = this.is(fv, "array") || this.is(fv, "object") ? this.generateDestructuringPattern(fv) : fv;
|
|
6280
|
+
return { header: `for ${isAwait ? "await " : ""}(const ${ivp} of ${this.generate(iterable, "value")})` };
|
|
6281
|
+
}
|
|
6183
6282
|
generateComprehension(head, rest, context) {
|
|
6184
6283
|
let [expr, iterators, guards] = rest;
|
|
6185
6284
|
if (context === "statement")
|
|
@@ -6196,53 +6295,16 @@ ${this.indent()}}`;
|
|
|
6196
6295
|
for (let iter of iterators) {
|
|
6197
6296
|
let [iterType, vars, iterable, stepOrOwn] = iter;
|
|
6198
6297
|
if (iterType === "for-in") {
|
|
6199
|
-
let
|
|
6200
|
-
|
|
6201
|
-
let noVar = va.length === 0;
|
|
6202
|
-
let [itemVar, indexVar] = noVar ? ["_i", null] : va;
|
|
6203
|
-
let ivp = this.is(itemVar, "array") || this.is(itemVar, "object") ? this.generateDestructuringPattern(itemVar) : itemVar;
|
|
6204
|
-
if (step && step !== null) {
|
|
6205
|
-
let ih = Array.isArray(iterable) && iterable[0];
|
|
6206
|
-
if (ih instanceof String)
|
|
6207
|
-
ih = str(ih);
|
|
6208
|
-
let isRange = ih === ".." || ih === "...";
|
|
6209
|
-
if (isRange) {
|
|
6210
|
-
let isExcl = ih === "...";
|
|
6211
|
-
let [s, e] = iterable.slice(1);
|
|
6212
|
-
let sc = this.generate(s, "value"), ec = this.generate(e, "value"), stc = this.generate(step, "value");
|
|
6213
|
-
code += this.indent() + `for (let ${ivp} = ${sc}; ${ivp} ${isExcl ? "<" : "<="} ${ec}; ${ivp} += ${stc}) {
|
|
6214
|
-
`;
|
|
6215
|
-
this.indentLevel++;
|
|
6216
|
-
} else {
|
|
6217
|
-
let ic = this.generate(iterable, "value"), idxN = indexVar || "_i", stc = this.generate(step, "value");
|
|
6218
|
-
let isNeg = this.is(step, "-", 1);
|
|
6219
|
-
code += isNeg ? this.indent() + `for (let ${idxN} = ${ic}.length - 1; ${idxN} >= 0; ${idxN} += ${stc}) {
|
|
6220
|
-
` : this.indent() + `for (let ${idxN} = 0; ${idxN} < ${ic}.length; ${idxN} += ${stc}) {
|
|
6298
|
+
let { header, setup } = this._forInHeader(vars, iterable, stepOrOwn);
|
|
6299
|
+
code += this.indent() + header + ` {
|
|
6221
6300
|
`;
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
`;
|
|
6226
|
-
}
|
|
6227
|
-
} else if (indexVar) {
|
|
6228
|
-
let ic = this.generate(iterable, "value");
|
|
6229
|
-
code += this.indent() + `for (let ${indexVar} = 0; ${indexVar} < ${ic}.length; ${indexVar}++) {
|
|
6230
|
-
`;
|
|
6231
|
-
this.indentLevel++;
|
|
6232
|
-
code += this.indent() + `const ${ivp} = ${ic}[${indexVar}];
|
|
6233
|
-
`;
|
|
6234
|
-
} else {
|
|
6235
|
-
code += this.indent() + `for (const ${ivp} of ${this.generate(iterable, "value")}) {
|
|
6301
|
+
this.indentLevel++;
|
|
6302
|
+
if (setup)
|
|
6303
|
+
code += this.indent() + setup + `
|
|
6236
6304
|
`;
|
|
6237
|
-
this.indentLevel++;
|
|
6238
|
-
}
|
|
6239
6305
|
} else if (iterType === "for-of") {
|
|
6240
|
-
let own = stepOrOwn;
|
|
6241
|
-
|
|
6242
|
-
let [kv, vv] = va;
|
|
6243
|
-
let kvp = this.is(kv, "array") || this.is(kv, "object") ? this.generateDestructuringPattern(kv) : kv;
|
|
6244
|
-
let oc = this.generate(iterable, "value");
|
|
6245
|
-
code += this.indent() + `for (const ${kvp} in ${oc}) {
|
|
6306
|
+
let { header, own, vv, oc, kvp } = this._forOfHeader(vars, iterable, stepOrOwn);
|
|
6307
|
+
code += this.indent() + header + ` {
|
|
6246
6308
|
`;
|
|
6247
6309
|
this.indentLevel++;
|
|
6248
6310
|
if (own)
|
|
@@ -6252,11 +6314,8 @@ ${this.indent()}}`;
|
|
|
6252
6314
|
code += this.indent() + `const ${vv} = ${oc}[${kvp}];
|
|
6253
6315
|
`;
|
|
6254
6316
|
} else if (iterType === "for-as") {
|
|
6255
|
-
let
|
|
6256
|
-
|
|
6257
|
-
let [fv] = va;
|
|
6258
|
-
let ivp = this.is(fv, "array") || this.is(fv, "object") ? this.generateDestructuringPattern(fv) : fv;
|
|
6259
|
-
code += this.indent() + `for ${isAwait ? "await " : ""}(const ${ivp} of ${this.generate(iterable, "value")}) {
|
|
6317
|
+
let { header } = this._forAsHeader(vars, iterable, iter[3]);
|
|
6318
|
+
code += this.indent() + header + ` {
|
|
6260
6319
|
`;
|
|
6261
6320
|
this.indentLevel++;
|
|
6262
6321
|
}
|
|
@@ -6271,7 +6330,7 @@ ${this.indent()}}`;
|
|
|
6271
6330
|
return true;
|
|
6272
6331
|
if (!Array.isArray(node))
|
|
6273
6332
|
return false;
|
|
6274
|
-
if (["break", "continue", "
|
|
6333
|
+
if (["break", "continue", "return", "throw"].includes(node[0]))
|
|
6275
6334
|
return true;
|
|
6276
6335
|
if (node[0] === "if" || node[0] === "unless")
|
|
6277
6336
|
return node.slice(1).some(hasCtrl);
|
|
@@ -6399,15 +6458,31 @@ ${this.indent()}}`;
|
|
|
6399
6458
|
let hasAwait = this.containsAwait(body), hasYield = this.containsYield(body);
|
|
6400
6459
|
let cleanParams = params, autoAssign = [];
|
|
6401
6460
|
if (mName === "constructor") {
|
|
6461
|
+
let isSubclass = !!parentClass;
|
|
6462
|
+
let atParamMap = isSubclass ? new Map : null;
|
|
6402
6463
|
cleanParams = params.map((p) => {
|
|
6403
6464
|
if (this.is(p, ".") && p[1] === "this") {
|
|
6404
|
-
|
|
6405
|
-
|
|
6465
|
+
let name = p[2];
|
|
6466
|
+
let param = isSubclass ? `_${name}` : name;
|
|
6467
|
+
autoAssign.push(`this.${name} = ${param}`);
|
|
6468
|
+
if (isSubclass)
|
|
6469
|
+
atParamMap.set(name, param);
|
|
6470
|
+
return param;
|
|
6471
|
+
}
|
|
6472
|
+
if (this.is(p, "default") && this.is(p[1], ".") && p[1][1] === "this") {
|
|
6473
|
+
let name = p[1][2];
|
|
6474
|
+
let param = isSubclass ? `_${name}` : name;
|
|
6475
|
+
autoAssign.push(`this.${name} = ${param}`);
|
|
6476
|
+
if (isSubclass)
|
|
6477
|
+
atParamMap.set(name, param);
|
|
6478
|
+
return ["default", param, p[2]];
|
|
6406
6479
|
}
|
|
6407
6480
|
return p;
|
|
6408
6481
|
});
|
|
6409
6482
|
for (let bm of boundMethods)
|
|
6410
6483
|
autoAssign.unshift(`this.${bm} = this.${bm}.bind(this)`);
|
|
6484
|
+
if (atParamMap?.size > 0)
|
|
6485
|
+
this._atParamMap = atParamMap;
|
|
6411
6486
|
}
|
|
6412
6487
|
let pList = this.generateParamList(cleanParams);
|
|
6413
6488
|
let prefix = (isStatic ? "static " : "") + (hasAwait ? "async " : "") + (hasYield ? "*" : "");
|
|
@@ -6415,6 +6490,7 @@ ${this.indent()}}`;
|
|
|
6415
6490
|
if (!isComputed)
|
|
6416
6491
|
this.currentMethodName = mName;
|
|
6417
6492
|
code += this.generateMethodBody(body, autoAssign, mName === "constructor", cleanParams);
|
|
6493
|
+
this._atParamMap = null;
|
|
6418
6494
|
this.currentMethodName = null;
|
|
6419
6495
|
code += `
|
|
6420
6496
|
`;
|
|
@@ -6699,9 +6775,10 @@ export default ${expr[1]}`;
|
|
|
6699
6775
|
if (Array.isArray(params))
|
|
6700
6776
|
params.forEach(extractPN);
|
|
6701
6777
|
let bodyVars = this.collectFunctionVariables(body);
|
|
6702
|
-
let newVars = new Set([...bodyVars].filter((v) => !this.programVars.has(v) && !this.reactiveVars?.has(v) && !paramNames.has(v)));
|
|
6778
|
+
let newVars = new Set([...bodyVars].filter((v) => !this.programVars.has(v) && !this.reactiveVars?.has(v) && !paramNames.has(v) && !this.scopeStack.some((s) => s.has(v))));
|
|
6703
6779
|
let noRetStmts = ["return", "throw", "break", "continue"];
|
|
6704
6780
|
let loopStmts = ["for-in", "for-of", "for-as", "while", "until", "loop"];
|
|
6781
|
+
this.scopeStack.push(new Set([...newVars, ...paramNames]));
|
|
6705
6782
|
if (this.is(body, "block")) {
|
|
6706
6783
|
let statements = this.unwrapBlock(body);
|
|
6707
6784
|
if (hasExpansionParams && this.expansionAfterParams?.length > 0) {
|
|
@@ -6801,17 +6878,27 @@ export default ${expr[1]}`;
|
|
|
6801
6878
|
}
|
|
6802
6879
|
this.indentLevel--;
|
|
6803
6880
|
code += this.indent() + "}";
|
|
6881
|
+
this.scopeStack.pop();
|
|
6804
6882
|
this.sideEffectOnly = prevSEO;
|
|
6805
6883
|
return code;
|
|
6806
6884
|
}
|
|
6807
6885
|
this.sideEffectOnly = prevSEO;
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6886
|
+
let result;
|
|
6887
|
+
if (isConstructor && autoAssignments.length > 0) {
|
|
6888
|
+
let isSuper = Array.isArray(body) && body[0] === "super";
|
|
6889
|
+
let bodyCode = this.generate(body, "statement");
|
|
6890
|
+
let assigns = autoAssignments.map((a) => `${a};`).join(" ");
|
|
6891
|
+
result = isSuper ? `{ ${bodyCode}; ${assigns} }` : `{ ${assigns} ${bodyCode}; }`;
|
|
6892
|
+
} else if (isConstructor || this.hasExplicitControlFlow(body))
|
|
6893
|
+
result = `{ ${this.generate(body, "statement")}; }`;
|
|
6894
|
+
else if (Array.isArray(body) && (noRetStmts.includes(body[0]) || loopStmts.includes(body[0])))
|
|
6895
|
+
result = `{ ${this.generate(body, "statement")}; }`;
|
|
6896
|
+
else if (sideEffectOnly)
|
|
6897
|
+
result = `{ ${this.generate(body, "statement")}; return; }`;
|
|
6898
|
+
else
|
|
6899
|
+
result = `{ return ${this.generate(body, "value")}; }`;
|
|
6900
|
+
this.scopeStack.pop();
|
|
6901
|
+
return result;
|
|
6815
6902
|
}
|
|
6816
6903
|
generateFunctionBody(body, params = [], sideEffectOnly = false) {
|
|
6817
6904
|
return this.generateBodyWithReturns(body, params, { sideEffectOnly, hasExpansionParams: this.expansionAfterParams?.length > 0 });
|
|
@@ -6886,37 +6973,13 @@ ${this.indent()}}`;
|
|
|
6886
6973
|
if (iterators.length === 1) {
|
|
6887
6974
|
let [iterType, vars, iterable, stepOrOwn] = iterators[0];
|
|
6888
6975
|
if (iterType === "for-in") {
|
|
6889
|
-
let
|
|
6890
|
-
|
|
6891
|
-
let noVar = va.length === 0;
|
|
6892
|
-
let [itemVar, indexVar] = noVar ? ["_i", null] : va;
|
|
6893
|
-
let ivp = this.is(itemVar, "array") || this.is(itemVar, "object") ? this.generateDestructuringPattern(itemVar) : itemVar;
|
|
6894
|
-
if (step && step !== null) {
|
|
6895
|
-
let ih = Array.isArray(iterable) && iterable[0];
|
|
6896
|
-
if (ih instanceof String)
|
|
6897
|
-
ih = str(ih);
|
|
6898
|
-
let isRange = ih === ".." || ih === "...";
|
|
6899
|
-
if (isRange) {
|
|
6900
|
-
let isExcl = ih === "...";
|
|
6901
|
-
let [s, e] = iterable.slice(1);
|
|
6902
|
-
code += this.indent() + `for (let ${ivp} = ${this.generate(s, "value")}; ${ivp} ${isExcl ? "<" : "<="} ${this.generate(e, "value")}; ${ivp} += ${this.generate(step, "value")}) {
|
|
6903
|
-
`;
|
|
6904
|
-
} else {
|
|
6905
|
-
let ic = this.generate(iterable, "value"), idxN = indexVar || "_i", stc = this.generate(step, "value");
|
|
6906
|
-
let isNeg = this.is(step, "-", 1);
|
|
6907
|
-
code += isNeg ? this.indent() + `for (let ${idxN} = ${ic}.length - 1; ${idxN} >= 0; ${idxN} += ${stc}) {
|
|
6908
|
-
` : this.indent() + `for (let ${idxN} = 0; ${idxN} < ${ic}.length; ${idxN} += ${stc}) {
|
|
6909
|
-
`;
|
|
6910
|
-
this.indentLevel++;
|
|
6911
|
-
if (!noVar)
|
|
6912
|
-
code += this.indent() + `const ${ivp} = ${ic}[${idxN}];
|
|
6913
|
-
`;
|
|
6914
|
-
}
|
|
6915
|
-
} else {
|
|
6916
|
-
code += this.indent() + `for (const ${ivp} of ${this.generate(iterable, "value")}) {
|
|
6976
|
+
let { header, setup } = this._forInHeader(vars, iterable, stepOrOwn);
|
|
6977
|
+
code += this.indent() + header + ` {
|
|
6917
6978
|
`;
|
|
6918
|
-
}
|
|
6919
6979
|
this.indentLevel++;
|
|
6980
|
+
if (setup)
|
|
6981
|
+
code += this.indent() + setup + `
|
|
6982
|
+
`;
|
|
6920
6983
|
if (guards && guards.length > 0) {
|
|
6921
6984
|
code += this.indent() + `if (${guards.map((g) => this.generate(g, "value")).join(" && ")}) {
|
|
6922
6985
|
`;
|
|
@@ -6940,229 +7003,59 @@ ${this.indent()}}`;
|
|
|
6940
7003
|
}
|
|
6941
7004
|
generateComprehensionAsLoop(expr, iterators, guards) {
|
|
6942
7005
|
let code = "";
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
if (
|
|
6946
|
-
|
|
6947
|
-
let va = Array.isArray(vars) ? vars : [vars];
|
|
6948
|
-
let noVar = va.length === 0;
|
|
6949
|
-
let [itemVar, indexVar] = noVar ? ["_i", null] : va;
|
|
6950
|
-
let ivp = this.is(itemVar, "array") || this.is(itemVar, "object") ? this.generateDestructuringPattern(itemVar) : itemVar;
|
|
6951
|
-
if (step && step !== null) {
|
|
6952
|
-
let ih = Array.isArray(iterable) && iterable[0];
|
|
6953
|
-
if (ih instanceof String)
|
|
6954
|
-
ih = str(ih);
|
|
6955
|
-
let isRange = ih === ".." || ih === "...";
|
|
6956
|
-
if (isRange) {
|
|
6957
|
-
let isExcl = ih === "...";
|
|
6958
|
-
let [s, e] = iterable.slice(1);
|
|
6959
|
-
code += `for (let ${ivp} = ${this.generate(s, "value")}; ${ivp} ${isExcl ? "<" : "<="} ${this.generate(e, "value")}; ${ivp} += ${this.generate(step, "value")}) `;
|
|
6960
|
-
} else {
|
|
6961
|
-
let ic = this.generate(iterable, "value"), idxN = indexVar || "_i", stc = this.generate(step, "value");
|
|
6962
|
-
let isNeg = this.is(step, "-", 1);
|
|
6963
|
-
let isMinus1 = isNeg && (step[1] === "1" || step[1] === 1 || str(step[1]) === "1");
|
|
6964
|
-
let isPlus1 = !isNeg && (step === "1" || step === 1 || str(step) === "1");
|
|
6965
|
-
if (isMinus1)
|
|
6966
|
-
code += `for (let ${idxN} = ${ic}.length - 1; ${idxN} >= 0; ${idxN}--) `;
|
|
6967
|
-
else if (isPlus1)
|
|
6968
|
-
code += `for (let ${idxN} = 0; ${idxN} < ${ic}.length; ${idxN}++) `;
|
|
6969
|
-
else if (isNeg)
|
|
6970
|
-
code += `for (let ${idxN} = ${ic}.length - 1; ${idxN} >= 0; ${idxN} += ${stc}) `;
|
|
6971
|
-
else
|
|
6972
|
-
code += `for (let ${idxN} = 0; ${idxN} < ${ic}.length; ${idxN} += ${stc}) `;
|
|
6973
|
-
code += `{
|
|
6974
|
-
`;
|
|
6975
|
-
this.indentLevel++;
|
|
6976
|
-
if (!noVar)
|
|
6977
|
-
code += this.indent() + `const ${ivp} = ${ic}[${idxN}];
|
|
6978
|
-
`;
|
|
6979
|
-
}
|
|
6980
|
-
if (guards?.length) {
|
|
6981
|
-
if (!isRange)
|
|
6982
|
-
code += this.indent();
|
|
6983
|
-
code += `{
|
|
6984
|
-
`;
|
|
6985
|
-
this.indentLevel++;
|
|
6986
|
-
code += this.indent() + `if (${guards.map((g) => this.generate(g, "value")).join(" && ")}) {
|
|
6987
|
-
`;
|
|
6988
|
-
this.indentLevel++;
|
|
6989
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
6990
|
-
`;
|
|
6991
|
-
this.indentLevel--;
|
|
6992
|
-
code += this.indent() + `}
|
|
6993
|
-
`;
|
|
6994
|
-
this.indentLevel--;
|
|
6995
|
-
code += this.indent() + "}";
|
|
6996
|
-
} else {
|
|
6997
|
-
if (!isRange)
|
|
6998
|
-
code += this.indent();
|
|
6999
|
-
code += `{
|
|
7000
|
-
`;
|
|
7001
|
-
this.indentLevel++;
|
|
7002
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7003
|
-
`;
|
|
7004
|
-
this.indentLevel--;
|
|
7005
|
-
code += this.indent() + "}";
|
|
7006
|
-
}
|
|
7007
|
-
if (!isRange) {
|
|
7008
|
-
this.indentLevel--;
|
|
7009
|
-
code += `
|
|
7010
|
-
` + this.indent() + "}";
|
|
7011
|
-
}
|
|
7012
|
-
return code;
|
|
7013
|
-
}
|
|
7014
|
-
if (indexVar) {
|
|
7015
|
-
let ic = this.generate(iterable, "value");
|
|
7016
|
-
code += `for (let ${indexVar} = 0; ${indexVar} < ${ic}.length; ${indexVar}++) `;
|
|
7017
|
-
code += `{
|
|
7006
|
+
let guardCond = guards?.length ? guards.map((g) => this.generate(g, "value")).join(" && ") : null;
|
|
7007
|
+
let emitBody = () => {
|
|
7008
|
+
if (guardCond) {
|
|
7009
|
+
code += this.indent() + `if (${guardCond}) {
|
|
7018
7010
|
`;
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
`;
|
|
7022
|
-
} else {
|
|
7023
|
-
code += `for (const ${ivp} of ${this.generate(iterable, "value")}) `;
|
|
7024
|
-
if (guards?.length) {
|
|
7025
|
-
code += `{
|
|
7026
|
-
`;
|
|
7027
|
-
this.indentLevel++;
|
|
7028
|
-
code += this.indent() + `if (${guards.map((g) => this.generate(g, "value")).join(" && ")}) {
|
|
7029
|
-
`;
|
|
7030
|
-
this.indentLevel++;
|
|
7031
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7032
|
-
`;
|
|
7033
|
-
this.indentLevel--;
|
|
7034
|
-
code += this.indent() + `}
|
|
7035
|
-
`;
|
|
7036
|
-
this.indentLevel--;
|
|
7037
|
-
code += this.indent() + "}";
|
|
7038
|
-
} else {
|
|
7039
|
-
code += `{
|
|
7040
|
-
`;
|
|
7041
|
-
this.indentLevel++;
|
|
7042
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7011
|
+
this.indentLevel++;
|
|
7012
|
+
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7043
7013
|
`;
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
}
|
|
7047
|
-
return code;
|
|
7048
|
-
}
|
|
7049
|
-
if (guards?.length) {
|
|
7050
|
-
code += this.indent() + `if (${guards.map((g) => this.generate(g, "value")).join(" && ")}) {
|
|
7014
|
+
this.indentLevel--;
|
|
7015
|
+
code += this.indent() + `}
|
|
7051
7016
|
`;
|
|
7052
|
-
|
|
7053
|
-
|
|
7017
|
+
} else {
|
|
7018
|
+
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7054
7019
|
`;
|
|
7055
|
-
|
|
7056
|
-
|
|
7020
|
+
}
|
|
7021
|
+
};
|
|
7022
|
+
if (iterators.length === 1) {
|
|
7023
|
+
let [iterType, vars, iterable, stepOrOwn] = iterators[0];
|
|
7024
|
+
if (iterType === "for-in") {
|
|
7025
|
+
let { header, setup } = this._forInHeader(vars, iterable, stepOrOwn);
|
|
7026
|
+
code += header + ` {
|
|
7057
7027
|
`;
|
|
7058
|
-
|
|
7059
|
-
|
|
7028
|
+
this.indentLevel++;
|
|
7029
|
+
if (setup)
|
|
7030
|
+
code += this.indent() + setup + `
|
|
7060
7031
|
`;
|
|
7061
|
-
|
|
7032
|
+
emitBody();
|
|
7062
7033
|
this.indentLevel--;
|
|
7063
7034
|
code += this.indent() + "}";
|
|
7064
7035
|
return code;
|
|
7065
7036
|
}
|
|
7066
7037
|
if (iterType === "for-as") {
|
|
7067
|
-
let
|
|
7068
|
-
|
|
7069
|
-
let ivp = this.is(fv, "array") || this.is(fv, "object") ? this.generateDestructuringPattern(fv) : fv;
|
|
7070
|
-
code += `for (const ${ivp} of ${this.generate(iterable, "value")}) `;
|
|
7071
|
-
if (guards?.length) {
|
|
7072
|
-
code += `{
|
|
7038
|
+
let { header } = this._forAsHeader(vars, iterable, stepOrOwn);
|
|
7039
|
+
code += header + ` {
|
|
7073
7040
|
`;
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7079
|
-
`;
|
|
7080
|
-
this.indentLevel--;
|
|
7081
|
-
code += this.indent() + `}
|
|
7082
|
-
`;
|
|
7083
|
-
this.indentLevel--;
|
|
7084
|
-
code += this.indent() + "}";
|
|
7085
|
-
} else {
|
|
7086
|
-
code += `{
|
|
7087
|
-
`;
|
|
7088
|
-
this.indentLevel++;
|
|
7089
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7090
|
-
`;
|
|
7091
|
-
this.indentLevel--;
|
|
7092
|
-
code += this.indent() + "}";
|
|
7093
|
-
}
|
|
7041
|
+
this.indentLevel++;
|
|
7042
|
+
emitBody();
|
|
7043
|
+
this.indentLevel--;
|
|
7044
|
+
code += this.indent() + "}";
|
|
7094
7045
|
return code;
|
|
7095
7046
|
}
|
|
7096
7047
|
if (iterType === "for-of") {
|
|
7097
|
-
let
|
|
7098
|
-
|
|
7099
|
-
let own = stepOrOwn;
|
|
7100
|
-
let oc = this.generate(iterable, "value");
|
|
7101
|
-
code += `for (const ${kv} in ${oc}) {
|
|
7048
|
+
let { header, own, vv, oc, kvp } = this._forOfHeader(vars, iterable, stepOrOwn);
|
|
7049
|
+
code += header + ` {
|
|
7102
7050
|
`;
|
|
7103
7051
|
this.indentLevel++;
|
|
7104
|
-
if (own
|
|
7105
|
-
code += this.indent() + `if (!Object.hasOwn(${oc}, ${
|
|
7106
|
-
`;
|
|
7107
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7108
|
-
`;
|
|
7109
|
-
} else if (own && vv && guards?.length) {
|
|
7110
|
-
code += this.indent() + `if (Object.hasOwn(${oc}, ${kv})) {
|
|
7111
|
-
`;
|
|
7112
|
-
this.indentLevel++;
|
|
7113
|
-
code += this.indent() + `const ${vv} = ${oc}[${kv}];
|
|
7114
|
-
`;
|
|
7115
|
-
code += this.indent() + `if (${guards.map((g) => this.generate(g, "value")).join(" && ")}) {
|
|
7116
|
-
`;
|
|
7117
|
-
this.indentLevel++;
|
|
7118
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7119
|
-
`;
|
|
7120
|
-
this.indentLevel--;
|
|
7121
|
-
code += this.indent() + `}
|
|
7122
|
-
`;
|
|
7123
|
-
this.indentLevel--;
|
|
7124
|
-
code += this.indent() + `}
|
|
7125
|
-
`;
|
|
7126
|
-
} else if (own && vv) {
|
|
7127
|
-
code += this.indent() + `if (Object.hasOwn(${oc}, ${kv})) {
|
|
7128
|
-
`;
|
|
7129
|
-
this.indentLevel++;
|
|
7130
|
-
code += this.indent() + `const ${vv} = ${oc}[${kv}];
|
|
7131
|
-
`;
|
|
7132
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7133
|
-
`;
|
|
7134
|
-
this.indentLevel--;
|
|
7135
|
-
code += this.indent() + `}
|
|
7136
|
-
`;
|
|
7137
|
-
} else if (vv && guards?.length) {
|
|
7138
|
-
code += this.indent() + `const ${vv} = ${oc}[${kv}];
|
|
7139
|
-
`;
|
|
7140
|
-
code += this.indent() + `if (${guards.map((g) => this.generate(g, "value")).join(" && ")}) {
|
|
7141
|
-
`;
|
|
7142
|
-
this.indentLevel++;
|
|
7143
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7144
|
-
`;
|
|
7145
|
-
this.indentLevel--;
|
|
7146
|
-
code += this.indent() + `}
|
|
7147
|
-
`;
|
|
7148
|
-
} else if (vv) {
|
|
7149
|
-
code += this.indent() + `const ${vv} = ${oc}[${kv}];
|
|
7150
|
-
`;
|
|
7151
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7152
|
-
`;
|
|
7153
|
-
} else if (guards?.length) {
|
|
7154
|
-
code += this.indent() + `if (${guards.map((g) => this.generate(g, "value")).join(" && ")}) {
|
|
7155
|
-
`;
|
|
7156
|
-
this.indentLevel++;
|
|
7157
|
-
code += this.indent() + this.generate(expr, "statement") + `;
|
|
7158
|
-
`;
|
|
7159
|
-
this.indentLevel--;
|
|
7160
|
-
code += this.indent() + `}
|
|
7052
|
+
if (own)
|
|
7053
|
+
code += this.indent() + `if (!Object.hasOwn(${oc}, ${kvp})) continue;
|
|
7161
7054
|
`;
|
|
7162
|
-
|
|
7163
|
-
code += this.indent() +
|
|
7055
|
+
if (vv)
|
|
7056
|
+
code += this.indent() + `const ${vv} = ${oc}[${kvp}];
|
|
7164
7057
|
`;
|
|
7165
|
-
|
|
7058
|
+
emitBody();
|
|
7166
7059
|
this.indentLevel--;
|
|
7167
7060
|
code += this.indent() + "}";
|
|
7168
7061
|
return code;
|
|
@@ -7747,6 +7640,7 @@ const __primitiveCoercion = {
|
|
|
7747
7640
|
};
|
|
7748
7641
|
|
|
7749
7642
|
function __state(initialValue) {
|
|
7643
|
+
if (initialValue != null && typeof initialValue === 'object' && typeof initialValue.read === 'function') return initialValue;
|
|
7750
7644
|
let value = initialValue;
|
|
7751
7645
|
const subscribers = new Set();
|
|
7752
7646
|
let notifying = false;
|
|
@@ -7846,14 +7740,19 @@ function __effect(fn) {
|
|
|
7846
7740
|
dependencies: new Set(),
|
|
7847
7741
|
|
|
7848
7742
|
run() {
|
|
7743
|
+
if (effect._cleanup) { effect._cleanup(); effect._cleanup = null; }
|
|
7849
7744
|
for (const dep of effect.dependencies) dep.delete(effect);
|
|
7850
7745
|
effect.dependencies.clear();
|
|
7851
7746
|
const prev = __currentEffect;
|
|
7852
7747
|
__currentEffect = effect;
|
|
7853
|
-
try {
|
|
7748
|
+
try {
|
|
7749
|
+
const result = fn();
|
|
7750
|
+
if (typeof result === 'function') effect._cleanup = result;
|
|
7751
|
+
} finally { __currentEffect = prev; }
|
|
7854
7752
|
},
|
|
7855
7753
|
|
|
7856
7754
|
dispose() {
|
|
7755
|
+
if (effect._cleanup) { effect._cleanup(); effect._cleanup = null; }
|
|
7857
7756
|
for (const dep of effect.dependencies) dep.delete(effect);
|
|
7858
7757
|
effect.dependencies.clear();
|
|
7859
7758
|
}
|
|
@@ -8041,8 +7940,8 @@ function getComponentRuntime() {
|
|
|
8041
7940
|
return new CodeGenerator({}).getComponentRuntime();
|
|
8042
7941
|
}
|
|
8043
7942
|
// src/browser.js
|
|
8044
|
-
var VERSION = "3.
|
|
8045
|
-
var BUILD_DATE = "2026-02-
|
|
7943
|
+
var VERSION = "3.8.8";
|
|
7944
|
+
var BUILD_DATE = "2026-02-16@19:03:24GMT";
|
|
8046
7945
|
if (typeof globalThis !== "undefined" && !globalThis.__rip) {
|
|
8047
7946
|
new Function(getReactiveRuntime())();
|
|
8048
7947
|
}
|
|
@@ -8057,25 +7956,34 @@ async function processRipScripts() {
|
|
|
8057
7956
|
if (script.hasAttribute("data-rip-processed"))
|
|
8058
7957
|
continue;
|
|
8059
7958
|
try {
|
|
8060
|
-
|
|
8061
|
-
|
|
7959
|
+
let ripCode;
|
|
7960
|
+
if (script.src) {
|
|
7961
|
+
const response = await fetch(script.src);
|
|
7962
|
+
if (!response.ok) {
|
|
7963
|
+
console.error(`Rip: failed to fetch ${script.src} (${response.status})`);
|
|
7964
|
+
continue;
|
|
7965
|
+
}
|
|
7966
|
+
ripCode = await response.text();
|
|
7967
|
+
} else {
|
|
7968
|
+
ripCode = dedent(script.textContent);
|
|
7969
|
+
}
|
|
7970
|
+
let jsCode;
|
|
7971
|
+
try {
|
|
7972
|
+
jsCode = compileToJS(ripCode);
|
|
7973
|
+
} catch (compileError) {
|
|
7974
|
+
console.error("Rip compile error:", compileError.message);
|
|
7975
|
+
console.error("Source:", ripCode);
|
|
7976
|
+
continue;
|
|
7977
|
+
}
|
|
8062
7978
|
await (0, eval)(`(async()=>{
|
|
8063
7979
|
${jsCode}
|
|
8064
7980
|
})()`);
|
|
8065
7981
|
script.setAttribute("data-rip-processed", "true");
|
|
8066
7982
|
} catch (error) {
|
|
8067
|
-
console.error("
|
|
8068
|
-
console.error("Script content:", script.textContent);
|
|
7983
|
+
console.error("Rip runtime error:", error);
|
|
8069
7984
|
}
|
|
8070
7985
|
}
|
|
8071
7986
|
}
|
|
8072
|
-
if (typeof document !== "undefined") {
|
|
8073
|
-
if (document.readyState === "loading") {
|
|
8074
|
-
document.addEventListener("DOMContentLoaded", processRipScripts);
|
|
8075
|
-
} else {
|
|
8076
|
-
processRipScripts();
|
|
8077
|
-
}
|
|
8078
|
-
}
|
|
8079
7987
|
async function importRip(url) {
|
|
8080
7988
|
const source = await fetch(url).then((r) => {
|
|
8081
7989
|
if (!r.ok)
|
|
@@ -8118,6 +8026,16 @@ if (typeof globalThis !== "undefined") {
|
|
|
8118
8026
|
globalThis.rip = rip;
|
|
8119
8027
|
globalThis.importRip = importRip;
|
|
8120
8028
|
globalThis.compileToJS = compileToJS;
|
|
8029
|
+
globalThis.__ripExports = { compile, compileToJS, formatSExpr, VERSION, BUILD_DATE, getReactiveRuntime, getComponentRuntime };
|
|
8030
|
+
}
|
|
8031
|
+
if (typeof document !== "undefined") {
|
|
8032
|
+
if (document.readyState === "loading") {
|
|
8033
|
+
globalThis.__ripScriptsReady = new Promise((resolve) => {
|
|
8034
|
+
document.addEventListener("DOMContentLoaded", () => processRipScripts().then(resolve));
|
|
8035
|
+
});
|
|
8036
|
+
} else {
|
|
8037
|
+
globalThis.__ripScriptsReady = processRipScripts();
|
|
8038
|
+
}
|
|
8121
8039
|
}
|
|
8122
8040
|
export {
|
|
8123
8041
|
rip,
|