tw-framework 2.0.1 → 2.0.3
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 +69 -0
- package/dist/hydration-runtime.js +35 -4
- package/dist/testing.cjs +156 -7
- package/dist/tw-runtime-client.mjs +45 -2
- package/dist/tw-server.mjs +156 -7
- package/dist/tw.mjs +230 -36
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,75 @@ Notable changes to TW Framework. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/), and the project uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [2.0.3]
|
|
8
|
+
|
|
9
|
+
A patch release: bug fixes only, no breaking changes, no public API changes.
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **Runtime -- hydration no longer discards server-rendered values.** A value
|
|
14
|
+
that comes from a page's `server { }` block is never serialised into
|
|
15
|
+
`__tw_state`, so the client runtime saw it as missing: a `for` loop over such a
|
|
16
|
+
value was emptied, an interpolation reading one was blanked, and an `if`
|
|
17
|
+
testing one was hidden -- after the server had already rendered them correctly.
|
|
18
|
+
An expression that evaluates to `undefined` is now treated as "not client
|
|
19
|
+
state" and the server's markup is left alone. Real client state stays reactive.
|
|
20
|
+
- **`tw dev` -- `strategies.hydration.mode: "none"` is honoured.** The dev server
|
|
21
|
+
injected the hydration runtime unconditionally, so there was no way to look at
|
|
22
|
+
a page without hydration while building it.
|
|
23
|
+
- **CLI -- the `tw-framework` bin alias.** The package declared only a `tw` bin,
|
|
24
|
+
so `bunx tw-framework dev` and a `"build": "tw-framework build"` script both
|
|
25
|
+
failed with "not found" even though the README documents that form. Both names
|
|
26
|
+
resolve to the same entry point now.
|
|
27
|
+
|
|
28
|
+
## [2.0.2]
|
|
29
|
+
|
|
30
|
+
A patch release: bug fixes only. No new features, no breaking changes, and no
|
|
31
|
+
public API changes -- 2.0.2 is a drop-in replacement for 2.0.1.
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- **Runtime -- store getters over array state.** The documented cart pattern
|
|
36
|
+
(`getters: { count: (state) => state.items.length }` with
|
|
37
|
+
`add(item) { this.items.push(item) }`) returned a stale count: mutating an
|
|
38
|
+
array in place keeps the same identity, so nothing downstream was notified.
|
|
39
|
+
The state proxy now reports in-place mutation (`push`, `pop`, `splice`, `sort`,
|
|
40
|
+
and so on) back to its reactive value, so a getter over it recomputes.
|
|
41
|
+
- **Runtime -- `VirtualList.getFirstVisibleIndex()`.** It was clamped to the item
|
|
42
|
+
count rather than the last index, so a `scrollTop` past the content returned
|
|
43
|
+
`100` for a 100-item list instead of `99`.
|
|
44
|
+
- **Compiler -- the live-list template.** A loop rendered on an interactive page
|
|
45
|
+
carries its template in an attribute, which is decoded once when the page is
|
|
46
|
+
parsed and parsed again by the runtime. Only the quotes were escaped, so an
|
|
47
|
+
expression inside the template (`data-tw-if="it == "b""`) lost its
|
|
48
|
+
value at the first quote and evaluated to `it == `. The template now survives
|
|
49
|
+
that first decode intact.
|
|
50
|
+
- **Compiler -- `TW098`.** The warning fired on a call to an imported helper,
|
|
51
|
+
which the build does resolve and render correctly. Names from the page's own
|
|
52
|
+
imports are now treated as evaluable, so only a genuinely unknown callee is
|
|
53
|
+
flagged.
|
|
54
|
+
- **Runtime -- a conditional inside a live list.** The page-wide conditional
|
|
55
|
+
pass re-evaluated `data-tw-if` / `data-tw-not` inside a live list with the loop
|
|
56
|
+
variable out of scope, overwriting the per-item result and hiding the right
|
|
57
|
+
branch for every item. Elements owned by a list are skipped now; the list
|
|
58
|
+
itself still evaluates them with the variable bound.
|
|
59
|
+
- **Plugins -- `@tw/plugin-sitemap`.** An unconfigured `siteUrl` answered
|
|
60
|
+
`/sitemap.xml` with `500`, which reads as a server fault. It answers `503`
|
|
61
|
+
("not configured") now; the message is unchanged.
|
|
62
|
+
|
|
63
|
+
- **Build — the server-only boundary.** Importing a server module into a page the
|
|
64
|
+
documented way (`import { query } from "../../lib/db"`) was never rejected: the
|
|
65
|
+
walker only recognised the `lib/`-prefixed and `.server.ts` forms, so a
|
|
66
|
+
relative path into `lib/` was treated as an ordinary local module. Such an
|
|
67
|
+
import now fails the build with `TW1007`, and a `.server` module is recognised
|
|
68
|
+
with or without its extension. `lib/` is also copied into the output directory
|
|
69
|
+
only after that check passes, so a rejected build no longer leaves the server
|
|
70
|
+
source there.
|
|
71
|
+
- **Diagnostics — the SSRF lint (`TW117`).** It only matched a request-derived
|
|
72
|
+
name written directly inside `fetch(...)`, so the ordinary shape
|
|
73
|
+
(`const url = query.u; await fetch(url)`) passed silently. Assignments are now
|
|
74
|
+
followed, so a request-derived value stays request-derived through them.
|
|
75
|
+
|
|
7
76
|
## [2.0.1]
|
|
8
77
|
|
|
9
78
|
A patch release: bug fixes only. No new features, no breaking changes, and no
|
|
@@ -56,17 +56,27 @@
|
|
|
56
56
|
// --- Conditional blocks -----------------------------------------------------
|
|
57
57
|
|
|
58
58
|
function refreshIfs(scope) {
|
|
59
|
+
// A conditional inside a live list belongs to that list: its expression uses
|
|
60
|
+
// the loop variable, which is bound only while the list renders. Evaluating
|
|
61
|
+
// it here (variable out of scope) hid the correct branch for every item, so
|
|
62
|
+
// the whole list showed the else branch.
|
|
63
|
+
var ownedByLoop = function (el) { return !!(el.closest && el.closest("tw-for")); };
|
|
59
64
|
var ifs = (scope || document).querySelectorAll("[data-tw-if]");
|
|
60
65
|
for (var i = 0; i < ifs.length; i++) {
|
|
61
66
|
var el = ifs[i];
|
|
67
|
+
if (ownedByLoop(el)) continue;
|
|
62
68
|
var val = evalExpr(el.getAttribute("data-tw-if"));
|
|
69
|
+
// Not client state (a server { } value): keep the branch the server chose.
|
|
70
|
+
if (val === undefined) continue;
|
|
63
71
|
var show = !!val && val !== "false" && val !== "0" && val !== "";
|
|
64
72
|
el.style.display = show ? "" : "none";
|
|
65
73
|
}
|
|
66
74
|
var nots = (scope || document).querySelectorAll("[data-tw-not]");
|
|
67
75
|
for (var j = 0; j < nots.length; j++) {
|
|
68
76
|
var el2 = nots[j];
|
|
77
|
+
if (ownedByLoop(el2)) continue;
|
|
69
78
|
var val2 = evalExpr(el2.getAttribute("data-tw-not"));
|
|
79
|
+
if (val2 === undefined) continue;
|
|
70
80
|
var hide = !!val2 && val2 !== "false" && val2 !== "0" && val2 !== "";
|
|
71
81
|
el2.style.display = hide ? "none" : "";
|
|
72
82
|
}
|
|
@@ -81,7 +91,10 @@
|
|
|
81
91
|
var holder = document.createElement("tw-render");
|
|
82
92
|
holder.innerHTML = tpl;
|
|
83
93
|
var spans = holder.querySelectorAll("[data-tw-i]");
|
|
84
|
-
for (var i = 0; i < spans.length; i++)
|
|
94
|
+
for (var i = 0; i < spans.length; i++) {
|
|
95
|
+
if (evalExpr(spans[i].getAttribute("data-tw-i")) === undefined) continue;
|
|
96
|
+
setSpanText(spans[i], spans[i].getAttribute("data-tw-i"));
|
|
97
|
+
}
|
|
85
98
|
|
|
86
99
|
// Nested if/not inside the loop body (evaluated while loopVar is bound)
|
|
87
100
|
var all = holder.querySelectorAll("*");
|
|
@@ -90,12 +103,16 @@
|
|
|
90
103
|
var ifAttr = el.getAttribute && el.getAttribute("data-tw-if");
|
|
91
104
|
if (ifAttr !== null && ifAttr !== undefined && el.hasAttribute("data-tw-if")) {
|
|
92
105
|
var v1 = evalExpr(ifAttr);
|
|
93
|
-
|
|
106
|
+
// `undefined` means the expression could not be evaluated here (a name
|
|
107
|
+
// out of scope). Forcing "none" then hid a branch the build had already
|
|
108
|
+
// resolved correctly, so the whole list showed the wrong branch. Leave
|
|
109
|
+
// the markup alone when there is no answer.
|
|
110
|
+
if (v1 !== undefined) el.style.display = (v1 && v1 !== "false" && v1 !== "0" && v1 !== "") ? "" : "none";
|
|
94
111
|
}
|
|
95
112
|
var notAttr = el.getAttribute("data-tw-not");
|
|
96
113
|
if (notAttr !== null && notAttr !== undefined && el.hasAttribute("data-tw-not")) {
|
|
97
114
|
var v2 = evalExpr(notAttr);
|
|
98
|
-
el.style.display = (v2 && v2 !== "false" && v2 !== "0" && v2 !== "") ? "none" : "";
|
|
115
|
+
if (v2 !== undefined) el.style.display = (v2 && v2 !== "false" && v2 !== "0" && v2 !== "") ? "none" : "";
|
|
99
116
|
}
|
|
100
117
|
}
|
|
101
118
|
|
|
@@ -128,6 +145,10 @@
|
|
|
128
145
|
for (var i = 0; i < loops.length; i++) {
|
|
129
146
|
var el = loops[i];
|
|
130
147
|
var arr = evalExpr(el.getAttribute("data-tw-list"));
|
|
148
|
+
// `undefined` means the name is not client state -- a value a server { }
|
|
149
|
+
// block produced, which is never serialised into __tw_state. Treating it
|
|
150
|
+
// as [] wiped the items the server had already rendered.
|
|
151
|
+
if (arr === undefined) continue;
|
|
131
152
|
var v = el.getAttribute("data-tw-var");
|
|
132
153
|
var tpl = el.getAttribute("data-tw-tpl") || "";
|
|
133
154
|
if (!Array.isArray(arr)) arr = [];
|
|
@@ -165,7 +186,17 @@
|
|
|
165
186
|
try { applyActiveClass(); } catch (e) { /* non-DOM context */ }
|
|
166
187
|
try { scanPrefetch(); } catch (e) { /* non-DOM context */ }
|
|
167
188
|
var spans = document.querySelectorAll("[data-tw-i]");
|
|
168
|
-
for (var i = 0; i < spans.length; i++)
|
|
189
|
+
for (var i = 0; i < spans.length; i++) {
|
|
190
|
+
// A span inside a live list belongs to that list: its expression uses the
|
|
191
|
+
// loop variable, which is only bound while the list renders. Evaluating it
|
|
192
|
+
// here (with the variable out of scope) blanked the text the build had
|
|
193
|
+
// already produced correctly.
|
|
194
|
+
if (spans[i].closest && spans[i].closest("tw-for")) continue;
|
|
195
|
+
// Same rule: an expression that is not client state leaves the
|
|
196
|
+
// server-rendered text alone instead of blanking it.
|
|
197
|
+
if (evalExpr(spans[i].getAttribute("data-tw-i")) === undefined) continue;
|
|
198
|
+
setSpanText(spans[i], spans[i].getAttribute("data-tw-i"));
|
|
199
|
+
}
|
|
169
200
|
var inputs = document.querySelectorAll("[data-tw-model]");
|
|
170
201
|
for (var j = 0; j < inputs.length; j++) {
|
|
171
202
|
var key = inputs[j].getAttribute("data-tw-model");
|
package/dist/testing.cjs
CHANGED
|
@@ -227066,7 +227066,7 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
227066
227066
|
const after2 = cursor.peek(1);
|
|
227067
227067
|
if (after2 && after2.type === "COLON") break;
|
|
227068
227068
|
}
|
|
227069
|
-
if (ct.type === "IDENT" && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227069
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227070
227070
|
break;
|
|
227071
227071
|
}
|
|
227072
227072
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -227098,7 +227098,7 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
227098
227098
|
const after2 = cursor.peek(1);
|
|
227099
227099
|
if (after2 && after2.type === "COLON") break;
|
|
227100
227100
|
}
|
|
227101
|
-
if (ct.type === "IDENT" && !nextPrevMinus && nextClass.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227101
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !nextPrevMinus && nextClass.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227102
227102
|
break;
|
|
227103
227103
|
}
|
|
227104
227104
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -236171,7 +236171,7 @@ var init_types4 = __esm({
|
|
|
236171
236171
|
var TW_VERSION, TW_GENERATOR_META;
|
|
236172
236172
|
var init_version = __esm({
|
|
236173
236173
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
236174
|
-
TW_VERSION = "2.0.
|
|
236174
|
+
TW_VERSION = "2.0.3";
|
|
236175
236175
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
236176
236176
|
}
|
|
236177
236177
|
});
|
|
@@ -239256,6 +239256,11 @@ function generateElement(el, ctx) {
|
|
|
239256
239256
|
}
|
|
239257
239257
|
function renderAttrs(el, ctx) {
|
|
239258
239258
|
const parts = [];
|
|
239259
|
+
const classAttrs = el.attrs.filter((a) => a.name === "class" && !a.isInterpolated && typeof a.value === "string");
|
|
239260
|
+
if (classAttrs.length > 1) {
|
|
239261
|
+
const merged = classAttrs.map((a) => String(a.value).trim()).filter(Boolean).join(" ");
|
|
239262
|
+
el = { ...el, attrs: el.attrs.filter((a) => a.name !== "class").concat([{ ...classAttrs[0], value: merged }]) };
|
|
239263
|
+
}
|
|
239259
239264
|
for (let attr of el.attrs) {
|
|
239260
239265
|
if (attr.name === "class" && typeof attr.value === "string" && !attr.isInterpolated) {
|
|
239261
239266
|
const scoped = ctx.scopedClasses;
|
|
@@ -239555,7 +239560,7 @@ function generateFor(node, ctx) {
|
|
|
239555
239560
|
tplSource = node.body.map((c) => generateNode(c, childCtx)).join("");
|
|
239556
239561
|
}
|
|
239557
239562
|
const listExpr = String(node.iterable ?? "").replace(/^\{/, "").replace(/\}$/, "");
|
|
239558
|
-
const tpl = tplSource.replace(/"/g, """);
|
|
239563
|
+
const tpl = tplSource.replace(/&/g, "&").replace(/"/g, """);
|
|
239559
239564
|
return `<tw-for data-tw-var="${node.varName}"${node.indexName ? ` data-tw-index="${node.indexName}"` : ""} data-tw-list="${listExpr}" data-tw-tpl="${tpl}">${html}</tw-for>`;
|
|
239560
239565
|
}
|
|
239561
239566
|
return html;
|
|
@@ -243968,6 +243973,8 @@ var init_codes = __esm({
|
|
|
243968
243973
|
TW117: { message: "fetch() with a request-derived URL (SSRF lint)", severity: "warning", category: "semantic" },
|
|
243969
243974
|
TW118: { message: "A deferred server block cannot redirect() or notFound() -- the response has already begun", severity: "error", category: "semantic" },
|
|
243970
243975
|
TW119: { message: "A deferred server block cannot be used on a cached page -- cache { } serves one HTML to every request", severity: "error", category: "semantic" },
|
|
243976
|
+
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
243977
|
+
TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
|
|
243971
243978
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
243972
243979
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
243973
243980
|
// carries no code of its own.
|
|
@@ -244361,6 +244368,14 @@ function checkUnknownStateVars(program, filePath, diags) {
|
|
|
244361
244368
|
if (d && d.type === "ServerBlock" && Array.isArray(d.declaredNames)) {
|
|
244362
244369
|
for (const n of d.declaredNames) known.add(n);
|
|
244363
244370
|
}
|
|
244371
|
+
if (d && d.type === "ImportDirective" && !d.isTypeOnly) {
|
|
244372
|
+
if (d.defaultImport) known.add(String(d.defaultImport));
|
|
244373
|
+
if (d.namespaceImport) known.add(String(d.namespaceImport));
|
|
244374
|
+
for (const it of d.items ?? []) {
|
|
244375
|
+
const nm = String(it).split(/\s+as\s+/).pop()?.trim();
|
|
244376
|
+
if (nm) known.add(nm);
|
|
244377
|
+
}
|
|
244378
|
+
}
|
|
244364
244379
|
}
|
|
244365
244380
|
const texts = [];
|
|
244366
244381
|
forEachNode(program, (node) => {
|
|
@@ -244503,6 +244518,27 @@ function checkDeprecatedImports(program, filePath, diags) {
|
|
|
244503
244518
|
}
|
|
244504
244519
|
}
|
|
244505
244520
|
}
|
|
244521
|
+
function checkDuplicateDefaultSlots(program, filePath, diags) {
|
|
244522
|
+
let count = 0;
|
|
244523
|
+
let first = null;
|
|
244524
|
+
forEachNode(program, (node) => {
|
|
244525
|
+
if (!node || node.type !== "Slot") return;
|
|
244526
|
+
const name = String(node.name ?? "default");
|
|
244527
|
+
if (name !== "default") return;
|
|
244528
|
+
count++;
|
|
244529
|
+
if (!first) first = node;
|
|
244530
|
+
});
|
|
244531
|
+
if (count > 1 && first) {
|
|
244532
|
+
diags.push(createDiagnostic(
|
|
244533
|
+
"TW122",
|
|
244534
|
+
first.line ?? 1,
|
|
244535
|
+
first.col ?? 1,
|
|
244536
|
+
filePath,
|
|
244537
|
+
`${count} default slots`,
|
|
244538
|
+
["Keep one default slot -- a caller's default content has no defined destination with two"]
|
|
244539
|
+
));
|
|
244540
|
+
}
|
|
244541
|
+
}
|
|
244506
244542
|
var HTML_ELEMENTS2, HTML_ATTRIBUTES2, GLOBAL_ATTRIBUTES2, CSS_PROPERTIES2, CSS_ALIASES2, EVENT_TYPES2, ARIA_ROLES2, ARIA_ATTRIBUTES2, BUILTIN_COMPONENT_TAGS, DEPRECATED_IMPORTS;
|
|
244507
244543
|
var init_rules = __esm({
|
|
244508
244544
|
"../../packages/compiler/tw/diagnostics/rules.ts"() {
|
|
@@ -245411,6 +245447,7 @@ function diagnose(program, filePath) {
|
|
|
245411
245447
|
checkLoopIterables(program, filePath, diagnostics);
|
|
245412
245448
|
checkUnknownStateVars(program, filePath, diagnostics);
|
|
245413
245449
|
checkWhileComparisons(program, filePath, diagnostics);
|
|
245450
|
+
checkDuplicateDefaultSlots(program, filePath, diagnostics);
|
|
245414
245451
|
return diagnostics;
|
|
245415
245452
|
}
|
|
245416
245453
|
var RuleEngine;
|
|
@@ -247767,6 +247804,28 @@ function lintSsrf(body) {
|
|
|
247767
247804
|
while (m = re.exec(body)) out.push("fetch(<dynamic url>)");
|
|
247768
247805
|
const concat = /fetch\s*\(\s*[^,)]*\b(params|query|headers|cookies)\b[^,)]*\+/g;
|
|
247769
247806
|
while (m = concat.exec(body)) out.push("fetch(<concatenated url>)");
|
|
247807
|
+
const TAINTED_ROOT = /\b(params|query|headers|cookies)\b/;
|
|
247808
|
+
const tainted = /* @__PURE__ */ new Set();
|
|
247809
|
+
for (let pass = 0; pass < 5; pass++) {
|
|
247810
|
+
let grew = false;
|
|
247811
|
+
const assign = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*([^;\n]+)/g;
|
|
247812
|
+
let a;
|
|
247813
|
+
while (a = assign.exec(body)) {
|
|
247814
|
+
const [, name, rhs] = a;
|
|
247815
|
+
if (tainted.has(name)) continue;
|
|
247816
|
+
const fromRoot = TAINTED_ROOT.test(rhs);
|
|
247817
|
+
const fromTainted = [...tainted].some((t3) => new RegExp("\\b" + t3 + "\\b").test(rhs));
|
|
247818
|
+
if (fromRoot || fromTainted) {
|
|
247819
|
+
tainted.add(name);
|
|
247820
|
+
grew = true;
|
|
247821
|
+
}
|
|
247822
|
+
}
|
|
247823
|
+
if (!grew) break;
|
|
247824
|
+
}
|
|
247825
|
+
for (const name of tainted) {
|
|
247826
|
+
const use = new RegExp("fetch\\s*\\(\\s*[^,)]*\\b" + name + "\\b[^,)]*[,)]", "g");
|
|
247827
|
+
if (use.test(body)) out.push("fetch(<request-derived url>)");
|
|
247828
|
+
}
|
|
247770
247829
|
return out;
|
|
247771
247830
|
}
|
|
247772
247831
|
var ts2, ServerSerializationError, MAX_DEPTH;
|
|
@@ -247870,6 +247929,36 @@ function serverStateCollisions(program) {
|
|
|
247870
247929
|
}
|
|
247871
247930
|
return out;
|
|
247872
247931
|
}
|
|
247932
|
+
function checkDeclarationConflicts(program, paramNames = []) {
|
|
247933
|
+
const out = [];
|
|
247934
|
+
const params = new Set(paramNames);
|
|
247935
|
+
const seen = /* @__PURE__ */ new Set();
|
|
247936
|
+
for (const d of program.directives ?? []) {
|
|
247937
|
+
if (d.type !== "StateDirective") continue;
|
|
247938
|
+
for (const decl of d.declarations ?? []) {
|
|
247939
|
+
const name = String(decl.name ?? "");
|
|
247940
|
+
if (!name) continue;
|
|
247941
|
+
if (params.has(name)) {
|
|
247942
|
+
out.push({
|
|
247943
|
+
code: "TW102",
|
|
247944
|
+
message: `state declares '${name}', which collides with the route param '${name}' -- the param overwrites the state value`,
|
|
247945
|
+
line: decl.line ?? d.line ?? 1,
|
|
247946
|
+
col: decl.col ?? d.col ?? 1
|
|
247947
|
+
});
|
|
247948
|
+
}
|
|
247949
|
+
if (seen.has(name)) {
|
|
247950
|
+
out.push({
|
|
247951
|
+
code: "TW121",
|
|
247952
|
+
message: `'${name}' is declared by more than one state { } block -- the earlier declaration wins and this one is dead`,
|
|
247953
|
+
line: decl.line ?? d.line ?? 1,
|
|
247954
|
+
col: decl.col ?? d.col ?? 1
|
|
247955
|
+
});
|
|
247956
|
+
}
|
|
247957
|
+
seen.add(name);
|
|
247958
|
+
}
|
|
247959
|
+
}
|
|
247960
|
+
return out;
|
|
247961
|
+
}
|
|
247873
247962
|
function serverRouteParamCollisions(blocks, paramNames) {
|
|
247874
247963
|
const params = new Set(paramNames);
|
|
247875
247964
|
const out = [];
|
|
@@ -248107,7 +248196,14 @@ function checkServerBlocks(program, opts = {}) {
|
|
|
248107
248196
|
const blocks = collectServerBlocks(program);
|
|
248108
248197
|
if (!blocks.length) return [];
|
|
248109
248198
|
const out = [];
|
|
248110
|
-
const push = (code, message, line, col) => out.push({
|
|
248199
|
+
const push = (code, message, line, col) => out.push({
|
|
248200
|
+
severity: ERROR_CODES[code]?.severity === "warning" ? "warning" : "error",
|
|
248201
|
+
code,
|
|
248202
|
+
message,
|
|
248203
|
+
line,
|
|
248204
|
+
col,
|
|
248205
|
+
category: "semantic"
|
|
248206
|
+
});
|
|
248111
248207
|
if (opts.isLayout) {
|
|
248112
248208
|
for (const b of blocks) push("TW105", "server blocks in layouts are not supported yet", b.line, b.col);
|
|
248113
248209
|
return out;
|
|
@@ -248285,6 +248381,7 @@ function parsePageCache(source) {
|
|
|
248285
248381
|
var ts3, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS;
|
|
248286
248382
|
var init_server_blocks = __esm({
|
|
248287
248383
|
"../../packages/compiler/tw/server-blocks/index.ts"() {
|
|
248384
|
+
init_codes();
|
|
248288
248385
|
init_serialize();
|
|
248289
248386
|
ts3 = __toESM(require_typescript(), 1);
|
|
248290
248387
|
REQUEST_IDENTIFIERS = /* @__PURE__ */ new Set(["headers", "cookies", "query", "params"]);
|
|
@@ -255005,6 +255102,7 @@ __export(tw_exports2, {
|
|
|
255005
255102
|
canonicalVaryQuery: () => canonicalVaryQuery,
|
|
255006
255103
|
charCode: () => charCode,
|
|
255007
255104
|
check: () => check,
|
|
255105
|
+
checkDeclarationConflicts: () => checkDeclarationConflicts,
|
|
255008
255106
|
checkServerBlocks: () => checkServerBlocks,
|
|
255009
255107
|
chunksToHTML: () => chunksToHTML,
|
|
255010
255108
|
clearComponentRegistry: () => clearComponentRegistry,
|
|
@@ -271592,6 +271690,17 @@ var init_tw9 = __esm({
|
|
|
271592
271690
|
cfgIn.redirects = normalizedRedirects.filter(Boolean);
|
|
271593
271691
|
}
|
|
271594
271692
|
}
|
|
271693
|
+
if (Array.isArray(cfgIn.redirects)) {
|
|
271694
|
+
const seenFrom = /* @__PURE__ */ new Set();
|
|
271695
|
+
for (const r of cfgIn.redirects) {
|
|
271696
|
+
const from = r && typeof r.from === "string" ? r.from : null;
|
|
271697
|
+
if (!from) continue;
|
|
271698
|
+
if (seenFrom.has(from)) {
|
|
271699
|
+
console.warn("[tw] redirects: '" + from + "' is listed more than once -- the first entry wins, the later one never runs");
|
|
271700
|
+
}
|
|
271701
|
+
seenFrom.add(from);
|
|
271702
|
+
}
|
|
271703
|
+
}
|
|
271595
271704
|
if (cfgIn.headers && !Array.isArray(cfgIn.headers)) {
|
|
271596
271705
|
const entries = Object.entries(cfgIn.headers);
|
|
271597
271706
|
cfgIn.headers = entries.map(([source, headers]) => ({ source, headers }));
|
|
@@ -283774,9 +283883,41 @@ function defineStore(idOrDefinition, maybeDefinition) {
|
|
|
283774
283883
|
return () => set.delete(cb);
|
|
283775
283884
|
}
|
|
283776
283885
|
};
|
|
283886
|
+
const MUTATORS = /* @__PURE__ */ new Set(["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"]);
|
|
283887
|
+
const tracking = /* @__PURE__ */ new WeakMap();
|
|
283888
|
+
const track2 = (value, prop) => {
|
|
283889
|
+
if (value === null || typeof value !== "object") return value;
|
|
283890
|
+
const existing2 = tracking.get(value);
|
|
283891
|
+
if (existing2) return existing2;
|
|
283892
|
+
const wrapped = new Proxy(value, {
|
|
283893
|
+
get(t3, key2, recv) {
|
|
283894
|
+
const v = Reflect.get(t3, key2, recv);
|
|
283895
|
+
if (typeof v === "function" && MUTATORS.has(String(key2))) {
|
|
283896
|
+
return (...args) => {
|
|
283897
|
+
const out = v.apply(t3, args);
|
|
283898
|
+
reactiveState[prop]?.touch();
|
|
283899
|
+
return out;
|
|
283900
|
+
};
|
|
283901
|
+
}
|
|
283902
|
+
return v;
|
|
283903
|
+
},
|
|
283904
|
+
set(t3, key2, v) {
|
|
283905
|
+
const ok2 = Reflect.set(t3, key2, v);
|
|
283906
|
+
reactiveState[prop]?.touch();
|
|
283907
|
+
return ok2;
|
|
283908
|
+
},
|
|
283909
|
+
deleteProperty(t3, key2) {
|
|
283910
|
+
const ok2 = Reflect.deleteProperty(t3, key2);
|
|
283911
|
+
reactiveState[prop]?.touch();
|
|
283912
|
+
return ok2;
|
|
283913
|
+
}
|
|
283914
|
+
});
|
|
283915
|
+
tracking.set(value, wrapped);
|
|
283916
|
+
return wrapped;
|
|
283917
|
+
};
|
|
283777
283918
|
const stateProxy = new Proxy({}, {
|
|
283778
283919
|
get(_target, prop) {
|
|
283779
|
-
return reactiveState[prop]?.value;
|
|
283920
|
+
return track2(reactiveState[prop]?.value, prop);
|
|
283780
283921
|
},
|
|
283781
283922
|
set(_target, prop, value) {
|
|
283782
283923
|
if (reactiveState[prop]) {
|
|
@@ -283897,6 +284038,14 @@ var init_store = __esm({
|
|
|
283897
284038
|
update(updater) {
|
|
283898
284039
|
this.set(updater(this._value));
|
|
283899
284040
|
}
|
|
284041
|
+
/**
|
|
284042
|
+
* Re-notify subscribers without replacing the value. An array or object that
|
|
284043
|
+
* was mutated in place (`this.items.push(x)`) has the same identity, so
|
|
284044
|
+
* `set()` short-circuits and nothing downstream hears about it.
|
|
284045
|
+
*/
|
|
284046
|
+
touch() {
|
|
284047
|
+
this._notify();
|
|
284048
|
+
}
|
|
283900
284049
|
subscribe(listener) {
|
|
283901
284050
|
this._listeners.add(listener);
|
|
283902
284051
|
return () => {
|
|
@@ -284913,7 +285062,7 @@ var init_virtual_list = __esm({
|
|
|
284913
285062
|
return this.container.scrollTop;
|
|
284914
285063
|
}
|
|
284915
285064
|
getFirstVisibleIndex() {
|
|
284916
|
-
const last = Math.max(0, this.options?.itemCount ?? 0 - 1);
|
|
285065
|
+
const last = Math.max(0, (this.options?.itemCount ?? 0) - 1);
|
|
284917
285066
|
return Math.min(Math.max(this.visibleRange.start, 0), last);
|
|
284918
285067
|
}
|
|
284919
285068
|
getLastVisibleIndex() {
|
|
@@ -11023,6 +11023,14 @@ var ReactiveValue = class {
|
|
|
11023
11023
|
update(updater) {
|
|
11024
11024
|
this.set(updater(this._value));
|
|
11025
11025
|
}
|
|
11026
|
+
/**
|
|
11027
|
+
* Re-notify subscribers without replacing the value. An array or object that
|
|
11028
|
+
* was mutated in place (`this.items.push(x)`) has the same identity, so
|
|
11029
|
+
* `set()` short-circuits and nothing downstream hears about it.
|
|
11030
|
+
*/
|
|
11031
|
+
touch() {
|
|
11032
|
+
this._notify();
|
|
11033
|
+
}
|
|
11026
11034
|
subscribe(listener) {
|
|
11027
11035
|
this._listeners.add(listener);
|
|
11028
11036
|
return () => {
|
|
@@ -11108,10 +11116,45 @@ function defineStore(idOrDefinition, maybeDefinition) {
|
|
|
11108
11116
|
return () => set.delete(cb);
|
|
11109
11117
|
}
|
|
11110
11118
|
};
|
|
11119
|
+
const MUTATORS = /* @__PURE__ */ new Set(["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"]);
|
|
11120
|
+
const tracking = /* @__PURE__ */ new WeakMap();
|
|
11121
|
+
const track = (value, prop) => {
|
|
11122
|
+
if (value === null || typeof value !== "object") return value;
|
|
11123
|
+
const existing2 = tracking.get(value);
|
|
11124
|
+
if (existing2) return existing2;
|
|
11125
|
+
const wrapped = new Proxy(value, {
|
|
11126
|
+
get(t2, key, recv) {
|
|
11127
|
+
const v = Reflect.get(t2, key, recv);
|
|
11128
|
+
if (typeof v === "function" && MUTATORS.has(String(key))) {
|
|
11129
|
+
return (...args) => {
|
|
11130
|
+
var _a2;
|
|
11131
|
+
const out = v.apply(t2, args);
|
|
11132
|
+
(_a2 = reactiveState[prop]) == null ? void 0 : _a2.touch();
|
|
11133
|
+
return out;
|
|
11134
|
+
};
|
|
11135
|
+
}
|
|
11136
|
+
return v;
|
|
11137
|
+
},
|
|
11138
|
+
set(t2, key, v) {
|
|
11139
|
+
var _a2;
|
|
11140
|
+
const ok = Reflect.set(t2, key, v);
|
|
11141
|
+
(_a2 = reactiveState[prop]) == null ? void 0 : _a2.touch();
|
|
11142
|
+
return ok;
|
|
11143
|
+
},
|
|
11144
|
+
deleteProperty(t2, key) {
|
|
11145
|
+
var _a2;
|
|
11146
|
+
const ok = Reflect.deleteProperty(t2, key);
|
|
11147
|
+
(_a2 = reactiveState[prop]) == null ? void 0 : _a2.touch();
|
|
11148
|
+
return ok;
|
|
11149
|
+
}
|
|
11150
|
+
});
|
|
11151
|
+
tracking.set(value, wrapped);
|
|
11152
|
+
return wrapped;
|
|
11153
|
+
};
|
|
11111
11154
|
const stateProxy = new Proxy({}, {
|
|
11112
11155
|
get(_target, prop) {
|
|
11113
11156
|
var _a2;
|
|
11114
|
-
return (_a2 = reactiveState[prop]) == null ? void 0 : _a2.value;
|
|
11157
|
+
return track((_a2 = reactiveState[prop]) == null ? void 0 : _a2.value, prop);
|
|
11115
11158
|
},
|
|
11116
11159
|
set(_target, prop, value) {
|
|
11117
11160
|
if (reactiveState[prop]) {
|
|
@@ -12197,7 +12240,7 @@ var VirtualList = class {
|
|
|
12197
12240
|
}
|
|
12198
12241
|
getFirstVisibleIndex() {
|
|
12199
12242
|
var _a, _b;
|
|
12200
|
-
const last = Math.max(0, (_b = (_a = this.options) == null ? void 0 : _a.itemCount) != null ? _b : 0 - 1);
|
|
12243
|
+
const last = Math.max(0, ((_b = (_a = this.options) == null ? void 0 : _a.itemCount) != null ? _b : 0) - 1);
|
|
12201
12244
|
return Math.min(Math.max(this.visibleRange.start, 0), last);
|
|
12202
12245
|
}
|
|
12203
12246
|
getLastVisibleIndex() {
|