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.
@@ -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.1";
237245
+ TW_VERSION = "2.0.3";
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, "&#34;");
240320
+ const tpl = tplSource.replace(/&/g, "&amp;").replace(/"/g, "&#34;");
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({ severity: "error", code, message, line, col, category: "semantic" });
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 }));