tw-framework 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/dist/hydration-runtime.js +21 -3
- 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 +226 -35
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,54 @@ 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.2]
|
|
8
|
+
|
|
9
|
+
A patch release: bug fixes only. No new features, no breaking changes, and no
|
|
10
|
+
public API changes -- 2.0.2 is a drop-in replacement for 2.0.1.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **Runtime -- store getters over array state.** The documented cart pattern
|
|
15
|
+
(`getters: { count: (state) => state.items.length }` with
|
|
16
|
+
`add(item) { this.items.push(item) }`) returned a stale count: mutating an
|
|
17
|
+
array in place keeps the same identity, so nothing downstream was notified.
|
|
18
|
+
The state proxy now reports in-place mutation (`push`, `pop`, `splice`, `sort`,
|
|
19
|
+
and so on) back to its reactive value, so a getter over it recomputes.
|
|
20
|
+
- **Runtime -- `VirtualList.getFirstVisibleIndex()`.** It was clamped to the item
|
|
21
|
+
count rather than the last index, so a `scrollTop` past the content returned
|
|
22
|
+
`100` for a 100-item list instead of `99`.
|
|
23
|
+
- **Compiler -- the live-list template.** A loop rendered on an interactive page
|
|
24
|
+
carries its template in an attribute, which is decoded once when the page is
|
|
25
|
+
parsed and parsed again by the runtime. Only the quotes were escaped, so an
|
|
26
|
+
expression inside the template (`data-tw-if="it == "b""`) lost its
|
|
27
|
+
value at the first quote and evaluated to `it == `. The template now survives
|
|
28
|
+
that first decode intact.
|
|
29
|
+
- **Compiler -- `TW098`.** The warning fired on a call to an imported helper,
|
|
30
|
+
which the build does resolve and render correctly. Names from the page's own
|
|
31
|
+
imports are now treated as evaluable, so only a genuinely unknown callee is
|
|
32
|
+
flagged.
|
|
33
|
+
- **Runtime -- a conditional inside a live list.** The page-wide conditional
|
|
34
|
+
pass re-evaluated `data-tw-if` / `data-tw-not` inside a live list with the loop
|
|
35
|
+
variable out of scope, overwriting the per-item result and hiding the right
|
|
36
|
+
branch for every item. Elements owned by a list are skipped now; the list
|
|
37
|
+
itself still evaluates them with the variable bound.
|
|
38
|
+
- **Plugins -- `@tw/plugin-sitemap`.** An unconfigured `siteUrl` answered
|
|
39
|
+
`/sitemap.xml` with `500`, which reads as a server fault. It answers `503`
|
|
40
|
+
("not configured") now; the message is unchanged.
|
|
41
|
+
|
|
42
|
+
- **Build — the server-only boundary.** Importing a server module into a page the
|
|
43
|
+
documented way (`import { query } from "../../lib/db"`) was never rejected: the
|
|
44
|
+
walker only recognised the `lib/`-prefixed and `.server.ts` forms, so a
|
|
45
|
+
relative path into `lib/` was treated as an ordinary local module. Such an
|
|
46
|
+
import now fails the build with `TW1007`, and a `.server` module is recognised
|
|
47
|
+
with or without its extension. `lib/` is also copied into the output directory
|
|
48
|
+
only after that check passes, so a rejected build no longer leaves the server
|
|
49
|
+
source there.
|
|
50
|
+
- **Diagnostics — the SSRF lint (`TW117`).** It only matched a request-derived
|
|
51
|
+
name written directly inside `fetch(...)`, so the ordinary shape
|
|
52
|
+
(`const url = query.u; await fetch(url)`) passed silently. Assignments are now
|
|
53
|
+
followed, so a request-derived value stays request-derived through them.
|
|
54
|
+
|
|
7
55
|
## [2.0.1]
|
|
8
56
|
|
|
9
57
|
A patch release: bug fixes only. No new features, no breaking changes, and no
|
|
@@ -56,9 +56,15 @@
|
|
|
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"));
|
|
63
69
|
var show = !!val && val !== "false" && val !== "0" && val !== "";
|
|
64
70
|
el.style.display = show ? "" : "none";
|
|
@@ -66,6 +72,7 @@
|
|
|
66
72
|
var nots = (scope || document).querySelectorAll("[data-tw-not]");
|
|
67
73
|
for (var j = 0; j < nots.length; j++) {
|
|
68
74
|
var el2 = nots[j];
|
|
75
|
+
if (ownedByLoop(el2)) continue;
|
|
69
76
|
var val2 = evalExpr(el2.getAttribute("data-tw-not"));
|
|
70
77
|
var hide = !!val2 && val2 !== "false" && val2 !== "0" && val2 !== "";
|
|
71
78
|
el2.style.display = hide ? "none" : "";
|
|
@@ -90,12 +97,16 @@
|
|
|
90
97
|
var ifAttr = el.getAttribute && el.getAttribute("data-tw-if");
|
|
91
98
|
if (ifAttr !== null && ifAttr !== undefined && el.hasAttribute("data-tw-if")) {
|
|
92
99
|
var v1 = evalExpr(ifAttr);
|
|
93
|
-
|
|
100
|
+
// `undefined` means the expression could not be evaluated here (a name
|
|
101
|
+
// out of scope). Forcing "none" then hid a branch the build had already
|
|
102
|
+
// resolved correctly, so the whole list showed the wrong branch. Leave
|
|
103
|
+
// the markup alone when there is no answer.
|
|
104
|
+
if (v1 !== undefined) el.style.display = (v1 && v1 !== "false" && v1 !== "0" && v1 !== "") ? "" : "none";
|
|
94
105
|
}
|
|
95
106
|
var notAttr = el.getAttribute("data-tw-not");
|
|
96
107
|
if (notAttr !== null && notAttr !== undefined && el.hasAttribute("data-tw-not")) {
|
|
97
108
|
var v2 = evalExpr(notAttr);
|
|
98
|
-
el.style.display = (v2 && v2 !== "false" && v2 !== "0" && v2 !== "") ? "none" : "";
|
|
109
|
+
if (v2 !== undefined) el.style.display = (v2 && v2 !== "false" && v2 !== "0" && v2 !== "") ? "none" : "";
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
|
|
@@ -165,7 +176,14 @@
|
|
|
165
176
|
try { applyActiveClass(); } catch (e) { /* non-DOM context */ }
|
|
166
177
|
try { scanPrefetch(); } catch (e) { /* non-DOM context */ }
|
|
167
178
|
var spans = document.querySelectorAll("[data-tw-i]");
|
|
168
|
-
for (var i = 0; i < spans.length; i++)
|
|
179
|
+
for (var i = 0; i < spans.length; i++) {
|
|
180
|
+
// A span inside a live list belongs to that list: its expression uses the
|
|
181
|
+
// loop variable, which is only bound while the list renders. Evaluating it
|
|
182
|
+
// here (with the variable out of scope) blanked the text the build had
|
|
183
|
+
// already produced correctly.
|
|
184
|
+
if (spans[i].closest && spans[i].closest("tw-for")) continue;
|
|
185
|
+
setSpanText(spans[i], spans[i].getAttribute("data-tw-i"));
|
|
186
|
+
}
|
|
169
187
|
var inputs = document.querySelectorAll("[data-tw-model]");
|
|
170
188
|
for (var j = 0; j < inputs.length; j++) {
|
|
171
189
|
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.2";
|
|
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() {
|
package/dist/tw-server.mjs
CHANGED
|
@@ -228137,7 +228137,7 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
228137
228137
|
const after2 = cursor.peek(1);
|
|
228138
228138
|
if (after2 && after2.type === "COLON") break;
|
|
228139
228139
|
}
|
|
228140
|
-
if (ct.type === "IDENT" && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
228140
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
228141
228141
|
break;
|
|
228142
228142
|
}
|
|
228143
228143
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -228169,7 +228169,7 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
228169
228169
|
const after2 = cursor.peek(1);
|
|
228170
228170
|
if (after2 && after2.type === "COLON") break;
|
|
228171
228171
|
}
|
|
228172
|
-
if (ct.type === "IDENT" && !nextPrevMinus && nextClass.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
228172
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !nextPrevMinus && nextClass.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
228173
228173
|
break;
|
|
228174
228174
|
}
|
|
228175
228175
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -237242,7 +237242,7 @@ var init_types4 = __esm({
|
|
|
237242
237242
|
var TW_VERSION, TW_GENERATOR_META;
|
|
237243
237243
|
var init_version = __esm({
|
|
237244
237244
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
237245
|
-
TW_VERSION = "2.0.
|
|
237245
|
+
TW_VERSION = "2.0.2";
|
|
237246
237246
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
237247
237247
|
}
|
|
237248
237248
|
});
|
|
@@ -240013,6 +240013,11 @@ function generateElement(el, ctx) {
|
|
|
240013
240013
|
}
|
|
240014
240014
|
function renderAttrs(el, ctx) {
|
|
240015
240015
|
const parts = [];
|
|
240016
|
+
const classAttrs = el.attrs.filter((a) => a.name === "class" && !a.isInterpolated && typeof a.value === "string");
|
|
240017
|
+
if (classAttrs.length > 1) {
|
|
240018
|
+
const merged = classAttrs.map((a) => String(a.value).trim()).filter(Boolean).join(" ");
|
|
240019
|
+
el = { ...el, attrs: el.attrs.filter((a) => a.name !== "class").concat([{ ...classAttrs[0], value: merged }]) };
|
|
240020
|
+
}
|
|
240016
240021
|
for (let attr of el.attrs) {
|
|
240017
240022
|
if (attr.name === "class" && typeof attr.value === "string" && !attr.isInterpolated) {
|
|
240018
240023
|
const scoped = ctx.scopedClasses;
|
|
@@ -240312,7 +240317,7 @@ function generateFor(node, ctx) {
|
|
|
240312
240317
|
tplSource = node.body.map((c) => generateNode(c, childCtx)).join("");
|
|
240313
240318
|
}
|
|
240314
240319
|
const listExpr = String(node.iterable ?? "").replace(/^\{/, "").replace(/\}$/, "");
|
|
240315
|
-
const tpl = tplSource.replace(/"/g, """);
|
|
240320
|
+
const tpl = tplSource.replace(/&/g, "&").replace(/"/g, """);
|
|
240316
240321
|
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>`;
|
|
240317
240322
|
}
|
|
240318
240323
|
return html;
|
|
@@ -244722,6 +244727,8 @@ var init_codes = __esm({
|
|
|
244722
244727
|
TW117: { message: "fetch() with a request-derived URL (SSRF lint)", severity: "warning", category: "semantic" },
|
|
244723
244728
|
TW118: { message: "A deferred server block cannot redirect() or notFound() -- the response has already begun", severity: "error", category: "semantic" },
|
|
244724
244729
|
TW119: { message: "A deferred server block cannot be used on a cached page -- cache { } serves one HTML to every request", severity: "error", category: "semantic" },
|
|
244730
|
+
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
244731
|
+
TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
|
|
244725
244732
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
244726
244733
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
244727
244734
|
// carries no code of its own.
|
|
@@ -245115,6 +245122,14 @@ function checkUnknownStateVars(program, filePath, diags) {
|
|
|
245115
245122
|
if (d && d.type === "ServerBlock" && Array.isArray(d.declaredNames)) {
|
|
245116
245123
|
for (const n of d.declaredNames) known.add(n);
|
|
245117
245124
|
}
|
|
245125
|
+
if (d && d.type === "ImportDirective" && !d.isTypeOnly) {
|
|
245126
|
+
if (d.defaultImport) known.add(String(d.defaultImport));
|
|
245127
|
+
if (d.namespaceImport) known.add(String(d.namespaceImport));
|
|
245128
|
+
for (const it of d.items ?? []) {
|
|
245129
|
+
const nm = String(it).split(/\s+as\s+/).pop()?.trim();
|
|
245130
|
+
if (nm) known.add(nm);
|
|
245131
|
+
}
|
|
245132
|
+
}
|
|
245118
245133
|
}
|
|
245119
245134
|
const texts = [];
|
|
245120
245135
|
forEachNode(program, (node) => {
|
|
@@ -245257,6 +245272,27 @@ function checkDeprecatedImports(program, filePath, diags) {
|
|
|
245257
245272
|
}
|
|
245258
245273
|
}
|
|
245259
245274
|
}
|
|
245275
|
+
function checkDuplicateDefaultSlots(program, filePath, diags) {
|
|
245276
|
+
let count = 0;
|
|
245277
|
+
let first = null;
|
|
245278
|
+
forEachNode(program, (node) => {
|
|
245279
|
+
if (!node || node.type !== "Slot") return;
|
|
245280
|
+
const name = String(node.name ?? "default");
|
|
245281
|
+
if (name !== "default") return;
|
|
245282
|
+
count++;
|
|
245283
|
+
if (!first) first = node;
|
|
245284
|
+
});
|
|
245285
|
+
if (count > 1 && first) {
|
|
245286
|
+
diags.push(createDiagnostic(
|
|
245287
|
+
"TW122",
|
|
245288
|
+
first.line ?? 1,
|
|
245289
|
+
first.col ?? 1,
|
|
245290
|
+
filePath,
|
|
245291
|
+
`${count} default slots`,
|
|
245292
|
+
["Keep one default slot -- a caller's default content has no defined destination with two"]
|
|
245293
|
+
));
|
|
245294
|
+
}
|
|
245295
|
+
}
|
|
245260
245296
|
var HTML_ELEMENTS2, HTML_ATTRIBUTES2, GLOBAL_ATTRIBUTES2, CSS_PROPERTIES2, CSS_ALIASES2, EVENT_TYPES2, ARIA_ROLES2, ARIA_ATTRIBUTES2, BUILTIN_COMPONENT_TAGS, DEPRECATED_IMPORTS;
|
|
245261
245297
|
var init_rules = __esm({
|
|
245262
245298
|
"../../packages/compiler/tw/diagnostics/rules.ts"() {
|
|
@@ -246165,6 +246201,7 @@ function diagnose(program, filePath) {
|
|
|
246165
246201
|
checkLoopIterables(program, filePath, diagnostics);
|
|
246166
246202
|
checkUnknownStateVars(program, filePath, diagnostics);
|
|
246167
246203
|
checkWhileComparisons(program, filePath, diagnostics);
|
|
246204
|
+
checkDuplicateDefaultSlots(program, filePath, diagnostics);
|
|
246168
246205
|
return diagnostics;
|
|
246169
246206
|
}
|
|
246170
246207
|
var RuleEngine;
|
|
@@ -248521,6 +248558,28 @@ function lintSsrf(body) {
|
|
|
248521
248558
|
while (m = re.exec(body)) out.push("fetch(<dynamic url>)");
|
|
248522
248559
|
const concat = /fetch\s*\(\s*[^,)]*\b(params|query|headers|cookies)\b[^,)]*\+/g;
|
|
248523
248560
|
while (m = concat.exec(body)) out.push("fetch(<concatenated url>)");
|
|
248561
|
+
const TAINTED_ROOT = /\b(params|query|headers|cookies)\b/;
|
|
248562
|
+
const tainted = /* @__PURE__ */ new Set();
|
|
248563
|
+
for (let pass = 0; pass < 5; pass++) {
|
|
248564
|
+
let grew = false;
|
|
248565
|
+
const assign = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*([^;\n]+)/g;
|
|
248566
|
+
let a;
|
|
248567
|
+
while (a = assign.exec(body)) {
|
|
248568
|
+
const [, name, rhs] = a;
|
|
248569
|
+
if (tainted.has(name)) continue;
|
|
248570
|
+
const fromRoot = TAINTED_ROOT.test(rhs);
|
|
248571
|
+
const fromTainted = [...tainted].some((t3) => new RegExp("\\b" + t3 + "\\b").test(rhs));
|
|
248572
|
+
if (fromRoot || fromTainted) {
|
|
248573
|
+
tainted.add(name);
|
|
248574
|
+
grew = true;
|
|
248575
|
+
}
|
|
248576
|
+
}
|
|
248577
|
+
if (!grew) break;
|
|
248578
|
+
}
|
|
248579
|
+
for (const name of tainted) {
|
|
248580
|
+
const use = new RegExp("fetch\\s*\\(\\s*[^,)]*\\b" + name + "\\b[^,)]*[,)]", "g");
|
|
248581
|
+
if (use.test(body)) out.push("fetch(<request-derived url>)");
|
|
248582
|
+
}
|
|
248524
248583
|
return out;
|
|
248525
248584
|
}
|
|
248526
248585
|
var ts2, ServerSerializationError, MAX_DEPTH;
|
|
@@ -248623,6 +248682,36 @@ function serverStateCollisions(program) {
|
|
|
248623
248682
|
}
|
|
248624
248683
|
return out;
|
|
248625
248684
|
}
|
|
248685
|
+
function checkDeclarationConflicts(program, paramNames = []) {
|
|
248686
|
+
const out = [];
|
|
248687
|
+
const params = new Set(paramNames);
|
|
248688
|
+
const seen = /* @__PURE__ */ new Set();
|
|
248689
|
+
for (const d of program.directives ?? []) {
|
|
248690
|
+
if (d.type !== "StateDirective") continue;
|
|
248691
|
+
for (const decl of d.declarations ?? []) {
|
|
248692
|
+
const name = String(decl.name ?? "");
|
|
248693
|
+
if (!name) continue;
|
|
248694
|
+
if (params.has(name)) {
|
|
248695
|
+
out.push({
|
|
248696
|
+
code: "TW102",
|
|
248697
|
+
message: `state declares '${name}', which collides with the route param '${name}' -- the param overwrites the state value`,
|
|
248698
|
+
line: decl.line ?? d.line ?? 1,
|
|
248699
|
+
col: decl.col ?? d.col ?? 1
|
|
248700
|
+
});
|
|
248701
|
+
}
|
|
248702
|
+
if (seen.has(name)) {
|
|
248703
|
+
out.push({
|
|
248704
|
+
code: "TW121",
|
|
248705
|
+
message: `'${name}' is declared by more than one state { } block -- the earlier declaration wins and this one is dead`,
|
|
248706
|
+
line: decl.line ?? d.line ?? 1,
|
|
248707
|
+
col: decl.col ?? d.col ?? 1
|
|
248708
|
+
});
|
|
248709
|
+
}
|
|
248710
|
+
seen.add(name);
|
|
248711
|
+
}
|
|
248712
|
+
}
|
|
248713
|
+
return out;
|
|
248714
|
+
}
|
|
248626
248715
|
function serverRouteParamCollisions(blocks, paramNames) {
|
|
248627
248716
|
const params = new Set(paramNames);
|
|
248628
248717
|
const out = [];
|
|
@@ -248860,7 +248949,14 @@ function checkServerBlocks(program, opts = {}) {
|
|
|
248860
248949
|
const blocks = collectServerBlocks(program);
|
|
248861
248950
|
if (!blocks.length) return [];
|
|
248862
248951
|
const out = [];
|
|
248863
|
-
const push = (code, message, line, col) => out.push({
|
|
248952
|
+
const push = (code, message, line, col) => out.push({
|
|
248953
|
+
severity: ERROR_CODES[code]?.severity === "warning" ? "warning" : "error",
|
|
248954
|
+
code,
|
|
248955
|
+
message,
|
|
248956
|
+
line,
|
|
248957
|
+
col,
|
|
248958
|
+
category: "semantic"
|
|
248959
|
+
});
|
|
248864
248960
|
if (opts.isLayout) {
|
|
248865
248961
|
for (const b of blocks) push("TW105", "server blocks in layouts are not supported yet", b.line, b.col);
|
|
248866
248962
|
return out;
|
|
@@ -249038,6 +249134,7 @@ function parsePageCache(source) {
|
|
|
249038
249134
|
var ts3, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS;
|
|
249039
249135
|
var init_server_blocks = __esm({
|
|
249040
249136
|
"../../packages/compiler/tw/server-blocks/index.ts"() {
|
|
249137
|
+
init_codes();
|
|
249041
249138
|
init_serialize();
|
|
249042
249139
|
ts3 = __toESM(require_typescript(), 1);
|
|
249043
249140
|
REQUEST_IDENTIFIERS = /* @__PURE__ */ new Set(["headers", "cookies", "query", "params"]);
|
|
@@ -255758,6 +255855,7 @@ __export(tw_exports2, {
|
|
|
255758
255855
|
canonicalVaryQuery: () => canonicalVaryQuery,
|
|
255759
255856
|
charCode: () => charCode,
|
|
255760
255857
|
check: () => check,
|
|
255858
|
+
checkDeclarationConflicts: () => checkDeclarationConflicts,
|
|
255761
255859
|
checkServerBlocks: () => checkServerBlocks,
|
|
255762
255860
|
chunksToHTML: () => chunksToHTML,
|
|
255763
255861
|
clearComponentRegistry: () => clearComponentRegistry,
|
|
@@ -268395,9 +268493,41 @@ function defineStore(idOrDefinition, maybeDefinition) {
|
|
|
268395
268493
|
return () => set.delete(cb);
|
|
268396
268494
|
}
|
|
268397
268495
|
};
|
|
268496
|
+
const MUTATORS = /* @__PURE__ */ new Set(["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"]);
|
|
268497
|
+
const tracking = /* @__PURE__ */ new WeakMap();
|
|
268498
|
+
const track2 = (value, prop) => {
|
|
268499
|
+
if (value === null || typeof value !== "object") return value;
|
|
268500
|
+
const existing2 = tracking.get(value);
|
|
268501
|
+
if (existing2) return existing2;
|
|
268502
|
+
const wrapped = new Proxy(value, {
|
|
268503
|
+
get(t3, key2, recv) {
|
|
268504
|
+
const v = Reflect.get(t3, key2, recv);
|
|
268505
|
+
if (typeof v === "function" && MUTATORS.has(String(key2))) {
|
|
268506
|
+
return (...args) => {
|
|
268507
|
+
const out = v.apply(t3, args);
|
|
268508
|
+
reactiveState[prop]?.touch();
|
|
268509
|
+
return out;
|
|
268510
|
+
};
|
|
268511
|
+
}
|
|
268512
|
+
return v;
|
|
268513
|
+
},
|
|
268514
|
+
set(t3, key2, v) {
|
|
268515
|
+
const ok2 = Reflect.set(t3, key2, v);
|
|
268516
|
+
reactiveState[prop]?.touch();
|
|
268517
|
+
return ok2;
|
|
268518
|
+
},
|
|
268519
|
+
deleteProperty(t3, key2) {
|
|
268520
|
+
const ok2 = Reflect.deleteProperty(t3, key2);
|
|
268521
|
+
reactiveState[prop]?.touch();
|
|
268522
|
+
return ok2;
|
|
268523
|
+
}
|
|
268524
|
+
});
|
|
268525
|
+
tracking.set(value, wrapped);
|
|
268526
|
+
return wrapped;
|
|
268527
|
+
};
|
|
268398
268528
|
const stateProxy = new Proxy({}, {
|
|
268399
268529
|
get(_target, prop) {
|
|
268400
|
-
return reactiveState[prop]?.value;
|
|
268530
|
+
return track2(reactiveState[prop]?.value, prop);
|
|
268401
268531
|
},
|
|
268402
268532
|
set(_target, prop, value) {
|
|
268403
268533
|
if (reactiveState[prop]) {
|
|
@@ -268518,6 +268648,14 @@ var init_store = __esm({
|
|
|
268518
268648
|
update(updater) {
|
|
268519
268649
|
this.set(updater(this._value));
|
|
268520
268650
|
}
|
|
268651
|
+
/**
|
|
268652
|
+
* Re-notify subscribers without replacing the value. An array or object that
|
|
268653
|
+
* was mutated in place (`this.items.push(x)`) has the same identity, so
|
|
268654
|
+
* `set()` short-circuits and nothing downstream hears about it.
|
|
268655
|
+
*/
|
|
268656
|
+
touch() {
|
|
268657
|
+
this._notify();
|
|
268658
|
+
}
|
|
268521
268659
|
subscribe(listener) {
|
|
268522
268660
|
this._listeners.add(listener);
|
|
268523
268661
|
return () => {
|
|
@@ -269534,7 +269672,7 @@ var init_virtual_list = __esm({
|
|
|
269534
269672
|
return this.container.scrollTop;
|
|
269535
269673
|
}
|
|
269536
269674
|
getFirstVisibleIndex() {
|
|
269537
|
-
const last = Math.max(0, this.options?.itemCount ?? 0 - 1);
|
|
269675
|
+
const last = Math.max(0, (this.options?.itemCount ?? 0) - 1);
|
|
269538
269676
|
return Math.min(Math.max(this.visibleRange.start, 0), last);
|
|
269539
269677
|
}
|
|
269540
269678
|
getLastVisibleIndex() {
|
|
@@ -286916,6 +287054,17 @@ var init_tw10 = __esm({
|
|
|
286916
287054
|
cfgIn.redirects = normalizedRedirects.filter(Boolean);
|
|
286917
287055
|
}
|
|
286918
287056
|
}
|
|
287057
|
+
if (Array.isArray(cfgIn.redirects)) {
|
|
287058
|
+
const seenFrom = /* @__PURE__ */ new Set();
|
|
287059
|
+
for (const r of cfgIn.redirects) {
|
|
287060
|
+
const from = r && typeof r.from === "string" ? r.from : null;
|
|
287061
|
+
if (!from) continue;
|
|
287062
|
+
if (seenFrom.has(from)) {
|
|
287063
|
+
console.warn("[tw] redirects: '" + from + "' is listed more than once -- the first entry wins, the later one never runs");
|
|
287064
|
+
}
|
|
287065
|
+
seenFrom.add(from);
|
|
287066
|
+
}
|
|
287067
|
+
}
|
|
286919
287068
|
if (cfgIn.headers && !Array.isArray(cfgIn.headers)) {
|
|
286920
287069
|
const entries = Object.entries(cfgIn.headers);
|
|
286921
287070
|
cfgIn.headers = entries.map(([source, headers]) => ({ source, headers }));
|
package/dist/tw.mjs
CHANGED
|
@@ -1542,10 +1542,10 @@ var init_request_context = __esm({
|
|
|
1542
1542
|
throw new Error(`Environment variable ${name} is not valid JSON`);
|
|
1543
1543
|
}
|
|
1544
1544
|
}
|
|
1545
|
-
list(name,
|
|
1545
|
+
list(name, sep3 = ",") {
|
|
1546
1546
|
const v = this.source[name];
|
|
1547
1547
|
if (!v) return [];
|
|
1548
|
-
return v.split(
|
|
1548
|
+
return v.split(sep3).map((s) => s.trim()).filter(Boolean);
|
|
1549
1549
|
}
|
|
1550
1550
|
/**
|
|
1551
1551
|
* Validate a whole set at once -- call it at startup and every problem is
|
|
@@ -3332,10 +3332,10 @@ function printTable(headers, rows) {
|
|
|
3332
3332
|
return Math.max(h3.length, maxRowLen);
|
|
3333
3333
|
});
|
|
3334
3334
|
const formatRow = (cells) => " " + cells.map((cell, i) => String(cell).padEnd(widths[i])).join(" ") + " ";
|
|
3335
|
-
const
|
|
3335
|
+
const sep3 = "-".repeat(widths.reduce((a, b) => a + b + 2, 0) + 1);
|
|
3336
3336
|
process.stderr.write(`${ANSI.bold}${formatRow(headers)}${ANSI.reset}
|
|
3337
3337
|
`);
|
|
3338
|
-
process.stderr.write(`${ANSI.dim}${
|
|
3338
|
+
process.stderr.write(`${ANSI.dim}${sep3}${ANSI.reset}
|
|
3339
3339
|
`);
|
|
3340
3340
|
for (const row of rows) {
|
|
3341
3341
|
process.stderr.write(formatRow(row.map(String)) + "\n");
|
|
@@ -63414,11 +63414,11 @@ ${lanes.join("\n")}
|
|
|
63414
63414
|
if (i < rootLength) {
|
|
63415
63415
|
return void 0;
|
|
63416
63416
|
}
|
|
63417
|
-
const
|
|
63418
|
-
if (
|
|
63417
|
+
const sep3 = directory.lastIndexOf(directorySeparator, i - 1);
|
|
63418
|
+
if (sep3 === -1) {
|
|
63419
63419
|
return void 0;
|
|
63420
63420
|
}
|
|
63421
|
-
return directory.substr(0, Math.max(
|
|
63421
|
+
return directory.substr(0, Math.max(sep3, rootLength));
|
|
63422
63422
|
}
|
|
63423
63423
|
}
|
|
63424
63424
|
}
|
|
@@ -227222,7 +227222,7 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
227222
227222
|
const after2 = cursor.peek(1);
|
|
227223
227223
|
if (after2 && after2.type === "COLON") break;
|
|
227224
227224
|
}
|
|
227225
|
-
if (ct.type === "IDENT" && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227225
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227226
227226
|
break;
|
|
227227
227227
|
}
|
|
227228
227228
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -227254,7 +227254,7 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
227254
227254
|
const after2 = cursor.peek(1);
|
|
227255
227255
|
if (after2 && after2.type === "COLON") break;
|
|
227256
227256
|
}
|
|
227257
|
-
if (ct.type === "IDENT" && !nextPrevMinus && nextClass.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227257
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !nextPrevMinus && nextClass.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227258
227258
|
break;
|
|
227259
227259
|
}
|
|
227260
227260
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -233652,8 +233652,8 @@ var init_constant_folding = __esm({
|
|
|
233652
233652
|
return { type: "string", value: str2.substring(start, end) };
|
|
233653
233653
|
}
|
|
233654
233654
|
case "split": {
|
|
233655
|
-
const
|
|
233656
|
-
const parts =
|
|
233655
|
+
const sep3 = args[0]?.type === "string" ? args[0].value : "";
|
|
233656
|
+
const parts = sep3 ? str2.split(sep3) : [str2];
|
|
233657
233657
|
return { type: "array", elements: parts.map((p) => ({ type: "string", value: p })) };
|
|
233658
233658
|
}
|
|
233659
233659
|
case "replace": {
|
|
@@ -233721,8 +233721,8 @@ var init_constant_folding = __esm({
|
|
|
233721
233721
|
case "length":
|
|
233722
233722
|
return { type: "number", value: elements.length };
|
|
233723
233723
|
case "join": {
|
|
233724
|
-
const
|
|
233725
|
-
return { type: "string", value: elements.map((e) => this.constToJSString(e)).join(
|
|
233724
|
+
const sep3 = args[0]?.type === "string" ? args[0].value : ",";
|
|
233725
|
+
return { type: "string", value: elements.map((e) => this.constToJSString(e)).join(sep3) };
|
|
233726
233726
|
}
|
|
233727
233727
|
case "indexOf": {
|
|
233728
233728
|
if (!args[0]) return null;
|
|
@@ -236327,7 +236327,7 @@ var init_types4 = __esm({
|
|
|
236327
236327
|
var TW_VERSION, TW_GENERATOR_META;
|
|
236328
236328
|
var init_version = __esm({
|
|
236329
236329
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
236330
|
-
TW_VERSION = "2.0.
|
|
236330
|
+
TW_VERSION = "2.0.2";
|
|
236331
236331
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
236332
236332
|
}
|
|
236333
236333
|
});
|
|
@@ -239421,6 +239421,11 @@ function generateElement(el, ctx) {
|
|
|
239421
239421
|
}
|
|
239422
239422
|
function renderAttrs(el, ctx) {
|
|
239423
239423
|
const parts = [];
|
|
239424
|
+
const classAttrs = el.attrs.filter((a) => a.name === "class" && !a.isInterpolated && typeof a.value === "string");
|
|
239425
|
+
if (classAttrs.length > 1) {
|
|
239426
|
+
const merged = classAttrs.map((a) => String(a.value).trim()).filter(Boolean).join(" ");
|
|
239427
|
+
el = { ...el, attrs: el.attrs.filter((a) => a.name !== "class").concat([{ ...classAttrs[0], value: merged }]) };
|
|
239428
|
+
}
|
|
239424
239429
|
for (let attr of el.attrs) {
|
|
239425
239430
|
if (attr.name === "class" && typeof attr.value === "string" && !attr.isInterpolated) {
|
|
239426
239431
|
const scoped = ctx.scopedClasses;
|
|
@@ -239720,7 +239725,7 @@ function generateFor(node, ctx) {
|
|
|
239720
239725
|
tplSource = node.body.map((c) => generateNode(c, childCtx)).join("");
|
|
239721
239726
|
}
|
|
239722
239727
|
const listExpr = String(node.iterable ?? "").replace(/^\{/, "").replace(/\}$/, "");
|
|
239723
|
-
const tpl = tplSource.replace(/"/g, """);
|
|
239728
|
+
const tpl = tplSource.replace(/&/g, "&").replace(/"/g, """);
|
|
239724
239729
|
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>`;
|
|
239725
239730
|
}
|
|
239726
239731
|
return html;
|
|
@@ -244130,6 +244135,8 @@ var init_codes = __esm({
|
|
|
244130
244135
|
TW117: { message: "fetch() with a request-derived URL (SSRF lint)", severity: "warning", category: "semantic" },
|
|
244131
244136
|
TW118: { message: "A deferred server block cannot redirect() or notFound() -- the response has already begun", severity: "error", category: "semantic" },
|
|
244132
244137
|
TW119: { message: "A deferred server block cannot be used on a cached page -- cache { } serves one HTML to every request", severity: "error", category: "semantic" },
|
|
244138
|
+
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
244139
|
+
TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
|
|
244133
244140
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
244134
244141
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
244135
244142
|
// carries no code of its own.
|
|
@@ -244523,6 +244530,14 @@ function checkUnknownStateVars(program, filePath, diags) {
|
|
|
244523
244530
|
if (d && d.type === "ServerBlock" && Array.isArray(d.declaredNames)) {
|
|
244524
244531
|
for (const n of d.declaredNames) known.add(n);
|
|
244525
244532
|
}
|
|
244533
|
+
if (d && d.type === "ImportDirective" && !d.isTypeOnly) {
|
|
244534
|
+
if (d.defaultImport) known.add(String(d.defaultImport));
|
|
244535
|
+
if (d.namespaceImport) known.add(String(d.namespaceImport));
|
|
244536
|
+
for (const it of d.items ?? []) {
|
|
244537
|
+
const nm = String(it).split(/\s+as\s+/).pop()?.trim();
|
|
244538
|
+
if (nm) known.add(nm);
|
|
244539
|
+
}
|
|
244540
|
+
}
|
|
244526
244541
|
}
|
|
244527
244542
|
const texts = [];
|
|
244528
244543
|
forEachNode(program, (node) => {
|
|
@@ -244665,6 +244680,27 @@ function checkDeprecatedImports(program, filePath, diags) {
|
|
|
244665
244680
|
}
|
|
244666
244681
|
}
|
|
244667
244682
|
}
|
|
244683
|
+
function checkDuplicateDefaultSlots(program, filePath, diags) {
|
|
244684
|
+
let count = 0;
|
|
244685
|
+
let first = null;
|
|
244686
|
+
forEachNode(program, (node) => {
|
|
244687
|
+
if (!node || node.type !== "Slot") return;
|
|
244688
|
+
const name = String(node.name ?? "default");
|
|
244689
|
+
if (name !== "default") return;
|
|
244690
|
+
count++;
|
|
244691
|
+
if (!first) first = node;
|
|
244692
|
+
});
|
|
244693
|
+
if (count > 1 && first) {
|
|
244694
|
+
diags.push(createDiagnostic(
|
|
244695
|
+
"TW122",
|
|
244696
|
+
first.line ?? 1,
|
|
244697
|
+
first.col ?? 1,
|
|
244698
|
+
filePath,
|
|
244699
|
+
`${count} default slots`,
|
|
244700
|
+
["Keep one default slot -- a caller's default content has no defined destination with two"]
|
|
244701
|
+
));
|
|
244702
|
+
}
|
|
244703
|
+
}
|
|
244668
244704
|
var HTML_ELEMENTS2, HTML_ATTRIBUTES2, GLOBAL_ATTRIBUTES2, CSS_PROPERTIES2, CSS_ALIASES2, EVENT_TYPES2, ARIA_ROLES2, ARIA_ATTRIBUTES2, BUILTIN_COMPONENT_TAGS, DEPRECATED_IMPORTS;
|
|
244669
244705
|
var init_rules = __esm({
|
|
244670
244706
|
"../../packages/compiler/tw/diagnostics/rules.ts"() {
|
|
@@ -245573,6 +245609,7 @@ function diagnose(program, filePath) {
|
|
|
245573
245609
|
checkLoopIterables(program, filePath, diagnostics);
|
|
245574
245610
|
checkUnknownStateVars(program, filePath, diagnostics);
|
|
245575
245611
|
checkWhileComparisons(program, filePath, diagnostics);
|
|
245612
|
+
checkDuplicateDefaultSlots(program, filePath, diagnostics);
|
|
245576
245613
|
return diagnostics;
|
|
245577
245614
|
}
|
|
245578
245615
|
var RuleEngine;
|
|
@@ -247929,6 +247966,28 @@ function lintSsrf(body) {
|
|
|
247929
247966
|
while (m = re.exec(body)) out.push("fetch(<dynamic url>)");
|
|
247930
247967
|
const concat = /fetch\s*\(\s*[^,)]*\b(params|query|headers|cookies)\b[^,)]*\+/g;
|
|
247931
247968
|
while (m = concat.exec(body)) out.push("fetch(<concatenated url>)");
|
|
247969
|
+
const TAINTED_ROOT = /\b(params|query|headers|cookies)\b/;
|
|
247970
|
+
const tainted = /* @__PURE__ */ new Set();
|
|
247971
|
+
for (let pass = 0; pass < 5; pass++) {
|
|
247972
|
+
let grew = false;
|
|
247973
|
+
const assign = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*([^;\n]+)/g;
|
|
247974
|
+
let a;
|
|
247975
|
+
while (a = assign.exec(body)) {
|
|
247976
|
+
const [, name, rhs] = a;
|
|
247977
|
+
if (tainted.has(name)) continue;
|
|
247978
|
+
const fromRoot = TAINTED_ROOT.test(rhs);
|
|
247979
|
+
const fromTainted = [...tainted].some((t3) => new RegExp("\\b" + t3 + "\\b").test(rhs));
|
|
247980
|
+
if (fromRoot || fromTainted) {
|
|
247981
|
+
tainted.add(name);
|
|
247982
|
+
grew = true;
|
|
247983
|
+
}
|
|
247984
|
+
}
|
|
247985
|
+
if (!grew) break;
|
|
247986
|
+
}
|
|
247987
|
+
for (const name of tainted) {
|
|
247988
|
+
const use = new RegExp("fetch\\s*\\(\\s*[^,)]*\\b" + name + "\\b[^,)]*[,)]", "g");
|
|
247989
|
+
if (use.test(body)) out.push("fetch(<request-derived url>)");
|
|
247990
|
+
}
|
|
247932
247991
|
return out;
|
|
247933
247992
|
}
|
|
247934
247993
|
var ts2, ServerSerializationError, MAX_DEPTH;
|
|
@@ -248031,6 +248090,36 @@ function serverStateCollisions(program) {
|
|
|
248031
248090
|
}
|
|
248032
248091
|
return out;
|
|
248033
248092
|
}
|
|
248093
|
+
function checkDeclarationConflicts(program, paramNames = []) {
|
|
248094
|
+
const out = [];
|
|
248095
|
+
const params = new Set(paramNames);
|
|
248096
|
+
const seen = /* @__PURE__ */ new Set();
|
|
248097
|
+
for (const d of program.directives ?? []) {
|
|
248098
|
+
if (d.type !== "StateDirective") continue;
|
|
248099
|
+
for (const decl of d.declarations ?? []) {
|
|
248100
|
+
const name = String(decl.name ?? "");
|
|
248101
|
+
if (!name) continue;
|
|
248102
|
+
if (params.has(name)) {
|
|
248103
|
+
out.push({
|
|
248104
|
+
code: "TW102",
|
|
248105
|
+
message: `state declares '${name}', which collides with the route param '${name}' -- the param overwrites the state value`,
|
|
248106
|
+
line: decl.line ?? d.line ?? 1,
|
|
248107
|
+
col: decl.col ?? d.col ?? 1
|
|
248108
|
+
});
|
|
248109
|
+
}
|
|
248110
|
+
if (seen.has(name)) {
|
|
248111
|
+
out.push({
|
|
248112
|
+
code: "TW121",
|
|
248113
|
+
message: `'${name}' is declared by more than one state { } block -- the earlier declaration wins and this one is dead`,
|
|
248114
|
+
line: decl.line ?? d.line ?? 1,
|
|
248115
|
+
col: decl.col ?? d.col ?? 1
|
|
248116
|
+
});
|
|
248117
|
+
}
|
|
248118
|
+
seen.add(name);
|
|
248119
|
+
}
|
|
248120
|
+
}
|
|
248121
|
+
return out;
|
|
248122
|
+
}
|
|
248034
248123
|
function serverRouteParamCollisions(blocks, paramNames) {
|
|
248035
248124
|
const params = new Set(paramNames);
|
|
248036
248125
|
const out = [];
|
|
@@ -248268,7 +248357,14 @@ function checkServerBlocks(program, opts = {}) {
|
|
|
248268
248357
|
const blocks = collectServerBlocks(program);
|
|
248269
248358
|
if (!blocks.length) return [];
|
|
248270
248359
|
const out = [];
|
|
248271
|
-
const push = (code, message, line, col) => out.push({
|
|
248360
|
+
const push = (code, message, line, col) => out.push({
|
|
248361
|
+
severity: ERROR_CODES[code]?.severity === "warning" ? "warning" : "error",
|
|
248362
|
+
code,
|
|
248363
|
+
message,
|
|
248364
|
+
line,
|
|
248365
|
+
col,
|
|
248366
|
+
category: "semantic"
|
|
248367
|
+
});
|
|
248272
248368
|
if (opts.isLayout) {
|
|
248273
248369
|
for (const b of blocks) push("TW105", "server blocks in layouts are not supported yet", b.line, b.col);
|
|
248274
248370
|
return out;
|
|
@@ -248446,6 +248542,7 @@ function parsePageCache(source) {
|
|
|
248446
248542
|
var ts3, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS;
|
|
248447
248543
|
var init_server_blocks = __esm({
|
|
248448
248544
|
"../../packages/compiler/tw/server-blocks/index.ts"() {
|
|
248545
|
+
init_codes();
|
|
248449
248546
|
init_serialize();
|
|
248450
248547
|
ts3 = __toESM(require_typescript(), 1);
|
|
248451
248548
|
REQUEST_IDENTIFIERS = /* @__PURE__ */ new Set(["headers", "cookies", "query", "params"]);
|
|
@@ -255166,6 +255263,7 @@ __export(tw_exports3, {
|
|
|
255166
255263
|
canonicalVaryQuery: () => canonicalVaryQuery,
|
|
255167
255264
|
charCode: () => charCode,
|
|
255168
255265
|
check: () => check,
|
|
255266
|
+
checkDeclarationConflicts: () => checkDeclarationConflicts,
|
|
255169
255267
|
checkServerBlocks: () => checkServerBlocks,
|
|
255170
255268
|
chunksToHTML: () => chunksToHTML,
|
|
255171
255269
|
clearComponentRegistry: () => clearComponentRegistry,
|
|
@@ -273421,6 +273519,17 @@ var init_tw10 = __esm({
|
|
|
273421
273519
|
cfgIn.redirects = normalizedRedirects.filter(Boolean);
|
|
273422
273520
|
}
|
|
273423
273521
|
}
|
|
273522
|
+
if (Array.isArray(cfgIn.redirects)) {
|
|
273523
|
+
const seenFrom = /* @__PURE__ */ new Set();
|
|
273524
|
+
for (const r of cfgIn.redirects) {
|
|
273525
|
+
const from = r && typeof r.from === "string" ? r.from : null;
|
|
273526
|
+
if (!from) continue;
|
|
273527
|
+
if (seenFrom.has(from)) {
|
|
273528
|
+
console.warn("[tw] redirects: '" + from + "' is listed more than once -- the first entry wins, the later one never runs");
|
|
273529
|
+
}
|
|
273530
|
+
seenFrom.add(from);
|
|
273531
|
+
}
|
|
273532
|
+
}
|
|
273424
273533
|
if (cfgIn.headers && !Array.isArray(cfgIn.headers)) {
|
|
273425
273534
|
const entries = Object.entries(cfgIn.headers);
|
|
273426
273535
|
cfgIn.headers = entries.map(([source, headers]) => ({ source, headers }));
|
|
@@ -285603,9 +285712,41 @@ function defineStore(idOrDefinition, maybeDefinition) {
|
|
|
285603
285712
|
return () => set.delete(cb);
|
|
285604
285713
|
}
|
|
285605
285714
|
};
|
|
285715
|
+
const MUTATORS = /* @__PURE__ */ new Set(["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"]);
|
|
285716
|
+
const tracking = /* @__PURE__ */ new WeakMap();
|
|
285717
|
+
const track2 = (value, prop) => {
|
|
285718
|
+
if (value === null || typeof value !== "object") return value;
|
|
285719
|
+
const existing2 = tracking.get(value);
|
|
285720
|
+
if (existing2) return existing2;
|
|
285721
|
+
const wrapped = new Proxy(value, {
|
|
285722
|
+
get(t3, key2, recv) {
|
|
285723
|
+
const v = Reflect.get(t3, key2, recv);
|
|
285724
|
+
if (typeof v === "function" && MUTATORS.has(String(key2))) {
|
|
285725
|
+
return (...args) => {
|
|
285726
|
+
const out = v.apply(t3, args);
|
|
285727
|
+
reactiveState[prop]?.touch();
|
|
285728
|
+
return out;
|
|
285729
|
+
};
|
|
285730
|
+
}
|
|
285731
|
+
return v;
|
|
285732
|
+
},
|
|
285733
|
+
set(t3, key2, v) {
|
|
285734
|
+
const ok3 = Reflect.set(t3, key2, v);
|
|
285735
|
+
reactiveState[prop]?.touch();
|
|
285736
|
+
return ok3;
|
|
285737
|
+
},
|
|
285738
|
+
deleteProperty(t3, key2) {
|
|
285739
|
+
const ok3 = Reflect.deleteProperty(t3, key2);
|
|
285740
|
+
reactiveState[prop]?.touch();
|
|
285741
|
+
return ok3;
|
|
285742
|
+
}
|
|
285743
|
+
});
|
|
285744
|
+
tracking.set(value, wrapped);
|
|
285745
|
+
return wrapped;
|
|
285746
|
+
};
|
|
285606
285747
|
const stateProxy = new Proxy({}, {
|
|
285607
285748
|
get(_target, prop) {
|
|
285608
|
-
return reactiveState[prop]?.value;
|
|
285749
|
+
return track2(reactiveState[prop]?.value, prop);
|
|
285609
285750
|
},
|
|
285610
285751
|
set(_target, prop, value) {
|
|
285611
285752
|
if (reactiveState[prop]) {
|
|
@@ -285726,6 +285867,14 @@ var init_store = __esm({
|
|
|
285726
285867
|
update(updater) {
|
|
285727
285868
|
this.set(updater(this._value));
|
|
285728
285869
|
}
|
|
285870
|
+
/**
|
|
285871
|
+
* Re-notify subscribers without replacing the value. An array or object that
|
|
285872
|
+
* was mutated in place (`this.items.push(x)`) has the same identity, so
|
|
285873
|
+
* `set()` short-circuits and nothing downstream hears about it.
|
|
285874
|
+
*/
|
|
285875
|
+
touch() {
|
|
285876
|
+
this._notify();
|
|
285877
|
+
}
|
|
285729
285878
|
subscribe(listener) {
|
|
285730
285879
|
this._listeners.add(listener);
|
|
285731
285880
|
return () => {
|
|
@@ -286742,7 +286891,7 @@ var init_virtual_list = __esm({
|
|
|
286742
286891
|
return this.container.scrollTop;
|
|
286743
286892
|
}
|
|
286744
286893
|
getFirstVisibleIndex() {
|
|
286745
|
-
const last = Math.max(0, this.options?.itemCount ?? 0 - 1);
|
|
286894
|
+
const last = Math.max(0, (this.options?.itemCount ?? 0) - 1);
|
|
286746
286895
|
return Math.min(Math.max(this.visibleRange.start, 0), last);
|
|
286747
286896
|
}
|
|
286748
286897
|
getLastVisibleIndex() {
|
|
@@ -289735,7 +289884,7 @@ __export(server_boundary_exports, {
|
|
|
289735
289884
|
walkClientGraph: () => walkClientGraph
|
|
289736
289885
|
});
|
|
289737
289886
|
import { readFileSync as readFileSync17, existsSync as existsSync25 } from "node:fs";
|
|
289738
|
-
import { dirname as dirname12, resolve as resolve7, extname as extname9, relative as relative2 } from "node:path";
|
|
289887
|
+
import { dirname as dirname12, resolve as resolve7, extname as extname9, relative as relative2, sep as sep2 } from "node:path";
|
|
289739
289888
|
function collectModuleImports(src) {
|
|
289740
289889
|
const out = [];
|
|
289741
289890
|
if (!src.trim()) return out;
|
|
@@ -289772,7 +289921,7 @@ function matchesOnlyPackages(spec, only) {
|
|
|
289772
289921
|
return false;
|
|
289773
289922
|
}
|
|
289774
289923
|
function isServerOnlyByName(spec) {
|
|
289775
|
-
return /\.server\.(ts|js)
|
|
289924
|
+
return /\.server(\.(ts|js|mjs|cjs))?$/.test(spec);
|
|
289776
289925
|
}
|
|
289777
289926
|
function packageName(spec) {
|
|
289778
289927
|
if (spec.startsWith("@")) return spec.split("/").slice(0, 2).join("/");
|
|
@@ -289803,8 +289952,13 @@ function walkClientGraph(entryFiles, opts = {}) {
|
|
|
289803
289952
|
const spec = imp.specifier;
|
|
289804
289953
|
let layer = null;
|
|
289805
289954
|
if (isServerOnlyByName(spec)) layer = "name";
|
|
289806
|
-
else if (isLocal(spec))
|
|
289807
|
-
|
|
289955
|
+
else if (isLocal(spec)) {
|
|
289956
|
+
const resolvedLocal = resolveLocal(spec, dirname12(file));
|
|
289957
|
+
const libRoot = opts.rootDir ? resolve7(opts.rootDir, "lib") : null;
|
|
289958
|
+
if (resolvedLocal && libRoot && (resolvedLocal === libRoot || resolvedLocal.startsWith(libRoot + sep2))) {
|
|
289959
|
+
layer = "lib";
|
|
289960
|
+
}
|
|
289961
|
+
} else if (spec === SERVER_ONLY_MARKER) layer = "L4";
|
|
289808
289962
|
else if (spec.startsWith("node:") || DENY_NODE_BUILTINS.has(spec)) layer = "L1";
|
|
289809
289963
|
else if (matchesOnlyPackages(spec, only)) layer = "L3";
|
|
289810
289964
|
else if (DEFAULT_DENY_PACKAGES.includes(packageName(spec))) layer = "L2";
|
|
@@ -290560,6 +290714,30 @@ async function buildCommand() {
|
|
|
290560
290714
|
console.log(" index.tw wins this route -- delete one of them");
|
|
290561
290715
|
}
|
|
290562
290716
|
}
|
|
290717
|
+
{
|
|
290718
|
+
const shapes = /* @__PURE__ */ new Map();
|
|
290719
|
+
for (const pf of pageFiles) {
|
|
290720
|
+
const dir = dirname13(pf);
|
|
290721
|
+
if (existsSync26(join30(dir, "page.twm"))) {
|
|
290722
|
+
console.log(" \x1B[33m!\x1B[0m " + dir.replace(homeDir, "").replace(/^\//, "") + "/ has BOTH page.tw and page.twm");
|
|
290723
|
+
console.log(" the .twm handler never runs -- delete one of them");
|
|
290724
|
+
}
|
|
290725
|
+
const rel = pf.replace(homeDir, "").replace(/^\//, "");
|
|
290726
|
+
const segs = rel.split("/").slice(0, -1).filter((seg) => !/^\(.*\)$/.test(seg));
|
|
290727
|
+
const parent = segs.slice(0, -1).join("/");
|
|
290728
|
+
const shape = segs.map((seg) => seg.startsWith("[") ? "[*]" : seg).join("/");
|
|
290729
|
+
if (!segs.length) continue;
|
|
290730
|
+
const key2 = parent + "\0" + shape;
|
|
290731
|
+
const prev = shapes.get(key2);
|
|
290732
|
+
if (prev && prev !== dir) {
|
|
290733
|
+
console.log(" \x1B[31m\u2717\x1B[0m two dynamic routes match the same URL: " + prev.replace(homeDir, "") + " and " + dir.replace(homeDir, ""));
|
|
290734
|
+
console.log(" rename one of the params -- only one of these pages can ever render");
|
|
290735
|
+
errorCount++;
|
|
290736
|
+
} else if (!prev) {
|
|
290737
|
+
shapes.set(key2, dir);
|
|
290738
|
+
}
|
|
290739
|
+
}
|
|
290740
|
+
}
|
|
290563
290741
|
begin("compile", pageFiles.length);
|
|
290564
290742
|
await runBuildHook("pages:discover", { pages: pageFiles, rootDir });
|
|
290565
290743
|
await runBuildHook("before:build", { pages: pageFiles, rootDir, outDir });
|
|
@@ -290625,6 +290803,16 @@ async function buildCommand() {
|
|
|
290625
290803
|
}
|
|
290626
290804
|
}
|
|
290627
290805
|
const renderMode = extractRenderMode2(readFileSync18(pageFile, "utf8"));
|
|
290806
|
+
try {
|
|
290807
|
+
const { parseWithDetails: _pd, checkDeclarationConflicts: checkDeclarationConflicts2 } = _compilerMod;
|
|
290808
|
+
const _prog = _pd(readFileSync18(pageFile, "utf-8"), { filePath: pageFile, cache: false }).program;
|
|
290809
|
+
const _paramNames = routePath.split("/").filter((seg) => seg.startsWith("[")).map((seg) => seg.replace(/^\[+/, "").replace(/\]+$/, "").replace(/^\.\.\./, ""));
|
|
290810
|
+
for (const c of checkDeclarationConflicts2(_prog, _paramNames)) {
|
|
290811
|
+
console.error(" \x1B[33m!\x1B[0m " + pageFile.replace(rootDir + "/", "") + ":" + c.line + " " + c.code + " " + c.message);
|
|
290812
|
+
errorCount++;
|
|
290813
|
+
}
|
|
290814
|
+
} catch {
|
|
290815
|
+
}
|
|
290628
290816
|
{
|
|
290629
290817
|
const pageSrc = readFileSync18(pageFile, "utf-8");
|
|
290630
290818
|
const { extractCacheDirective: extractCacheDirective2, resolveCache: resolveCache2 } = await Promise.resolve().then(() => (init_tw(), tw_exports));
|
|
@@ -290679,8 +290867,11 @@ async function buildCommand() {
|
|
|
290679
290867
|
hasVary: extractVary2(src).length > 0,
|
|
290680
290868
|
referenced: collectReferencedNames3(src)
|
|
290681
290869
|
});
|
|
290682
|
-
for (const p of problems)
|
|
290683
|
-
|
|
290870
|
+
for (const p of problems) {
|
|
290871
|
+
const warn2 = p.severity === "warning";
|
|
290872
|
+
console.error(" " + (warn2 ? "\x1B[33m!\x1B[0m" : "\x1B[31m\u2717\x1B[0m") + " " + pageFile.replace(rootDir + "/", "") + ":" + p.line + " " + p.code + " " + p.message);
|
|
290873
|
+
if (!warn2) errorCount++;
|
|
290874
|
+
}
|
|
290684
290875
|
}
|
|
290685
290876
|
} catch {
|
|
290686
290877
|
}
|
|
@@ -291009,10 +291200,6 @@ async function buildCommand() {
|
|
|
291009
291200
|
apiCount++;
|
|
291010
291201
|
}
|
|
291011
291202
|
}
|
|
291012
|
-
if (existsSync26(libDir)) {
|
|
291013
|
-
copyDir2(libDir, join30(outDir, "lib"));
|
|
291014
|
-
console.log(" \x1B[32mOK\x1B[0m lib/");
|
|
291015
|
-
}
|
|
291016
291203
|
if (existsSync26(publicDir)) {
|
|
291017
291204
|
copyDir2(publicDir, outDir);
|
|
291018
291205
|
console.log(" \x1B[32mOK\x1B[0m public/");
|
|
@@ -291030,6 +291217,10 @@ async function buildCommand() {
|
|
|
291030
291217
|
}
|
|
291031
291218
|
process.exit(1);
|
|
291032
291219
|
}
|
|
291220
|
+
if (existsSync26(libDir)) {
|
|
291221
|
+
copyDir2(libDir, join30(outDir, "lib"));
|
|
291222
|
+
console.log(" \x1B[32mOK\x1B[0m lib/");
|
|
291223
|
+
}
|
|
291033
291224
|
if (clientChunkUrls.size > 0) {
|
|
291034
291225
|
console.log(" \x1B[36m\u26A1\x1B[0m client modules: " + clientChunkUrls.size + " shared chunk" + (clientChunkUrls.size === 1 ? "" : "s") + " (content-hashed, tree-shaken)");
|
|
291035
291226
|
}
|
|
@@ -294176,10 +294367,10 @@ if (typeof globalThis.Bun === "undefined") {
|
|
|
294176
294367
|
const parts = bodyStr.split(boundary);
|
|
294177
294368
|
for (let i = 1; i < parts.length - 1; i++) {
|
|
294178
294369
|
const raw = parts[i];
|
|
294179
|
-
const
|
|
294180
|
-
if (
|
|
294181
|
-
const head = raw.slice(0,
|
|
294182
|
-
let data = raw.slice(
|
|
294370
|
+
const sep3 = raw.indexOf("\r\n\r\n");
|
|
294371
|
+
if (sep3 < 0) continue;
|
|
294372
|
+
const head = raw.slice(0, sep3);
|
|
294373
|
+
let data = raw.slice(sep3 + 4);
|
|
294183
294374
|
if (data.endsWith("\r\n")) data = data.slice(0, -2);
|
|
294184
294375
|
const nameM = /name="([^"]*)"/.exec(head);
|
|
294185
294376
|
if (!nameM) continue;
|
|
@@ -294484,7 +294675,7 @@ async function createPackageJson(dir, name) {
|
|
|
294484
294675
|
ship: "tw ship"
|
|
294485
294676
|
},
|
|
294486
294677
|
dependencies: {
|
|
294487
|
-
"tw-framework": "^2.0.
|
|
294678
|
+
"tw-framework": "^2.0.2"
|
|
294488
294679
|
},
|
|
294489
294680
|
devDependencies: {
|
|
294490
294681
|
typescript: "^5.4.0",
|
|
@@ -294571,7 +294762,7 @@ dist/
|
|
|
294571
294762
|
async function createReadme(dir, name) {
|
|
294572
294763
|
const content = `# ${name}
|
|
294573
294764
|
|
|
294574
|
-
Built with TW Framework 2.0.
|
|
294765
|
+
Built with TW Framework 2.0.2.
|
|
294575
294766
|
|
|
294576
294767
|
## Getting Started
|
|
294577
294768
|
|
|
@@ -297113,7 +297304,7 @@ function ensureTestingShim(rootDir) {
|
|
|
297113
297304
|
if (existsSync32(marker)) return;
|
|
297114
297305
|
const { mkdirSync: mkdirSync12, writeFileSync: writeFileSync14 } = _require("node:fs");
|
|
297115
297306
|
mkdirSync12(join37(shimPkgDir, "tw"), { recursive: true });
|
|
297116
|
-
writeFileSync14(marker, JSON.stringify({ name: "@tw/server", version: "2.0.
|
|
297307
|
+
writeFileSync14(marker, JSON.stringify({ name: "@tw/server", version: "2.0.2", private: true }, null, 2));
|
|
297117
297308
|
let testingBundle = null;
|
|
297118
297309
|
try {
|
|
297119
297310
|
const here = new URL(".", import.meta.url).pathname;
|
package/package.json
CHANGED