@torpor/view 0.4.13 → 0.4.14

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.
Files changed (87) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/{Cleanup-BGQ5zaxE.d.cts → Cleanup-CYsytTEc.d.cts} +1 -1
  3. package/dist/Cleanup-CYsytTEc.d.cts.map +1 -0
  4. package/dist/{Cleanup-Ca8IspaG.d.ts → Cleanup-CgjyN0lW.d.mts} +1 -1
  5. package/dist/Cleanup-CgjyN0lW.d.mts.map +1 -0
  6. package/dist/{Component-BDUCwkBQ.d.cts → Component-DmWGMgak.d.mts} +1 -1
  7. package/dist/{Component-BDUCwkBQ.d.cts.map → Component-DmWGMgak.d.mts.map} +1 -1
  8. package/dist/{Component-JVwSemf-.d.ts → Component-kGLRFYg2.d.cts} +1 -1
  9. package/dist/Component-kGLRFYg2.d.cts.map +1 -0
  10. package/dist/{Region-BrsZLZUe.d.ts → Region-Bb6HAb-F.d.cts} +2 -2
  11. package/dist/{Region-Cf7OeBIQ.d.cts.map → Region-Bb6HAb-F.d.cts.map} +1 -1
  12. package/dist/{Region-Cf7OeBIQ.d.cts → Region-CTchywkr.d.mts} +2 -2
  13. package/dist/Region-CTchywkr.d.mts.map +1 -0
  14. package/dist/compile.cjs +239 -71
  15. package/dist/compile.d.cts +1 -1
  16. package/dist/{compile.d.ts → compile.d.mts} +2 -2
  17. package/dist/compile.d.mts.map +1 -0
  18. package/dist/{compile.js → compile.mjs} +239 -70
  19. package/dist/compile.mjs.map +1 -0
  20. package/dist/dev.cjs +1 -2
  21. package/dist/dev.d.cts +2 -2
  22. package/dist/{dev.d.ts → dev.d.mts} +3 -3
  23. package/dist/dev.d.mts.map +1 -0
  24. package/dist/{dev.js → dev.mjs} +2 -2
  25. package/dist/{dev.cjs.map → dev.mjs.map} +1 -1
  26. package/dist/devContext-B3yskfhA.cjs +1 -2
  27. package/dist/{devContext-CevrTlUO.js → devContext-CQ8RhBX-.mjs} +1 -1
  28. package/dist/{devContext-B3yskfhA.cjs.map → devContext-CQ8RhBX-.mjs.map} +1 -1
  29. package/dist/{formatText-Ck04q8_X.cjs → formatText--9zsK5Nq.cjs} +4 -4
  30. package/dist/{formatText-OyD8MNAM.js → formatText-B8u71S_K.mjs} +4 -3
  31. package/dist/formatText-B8u71S_K.mjs.map +1 -0
  32. package/dist/{formatText-BlLF3PPm.d.ts → formatText-BNP3P38F.d.cts} +3 -3
  33. package/dist/formatText-BNP3P38F.d.cts.map +1 -0
  34. package/dist/{formatText-Bcb1JvW5.d.cts → formatText-D6Ov8Ub0.d.mts} +3 -3
  35. package/dist/formatText-D6Ov8Ub0.d.mts.map +1 -0
  36. package/dist/index.cjs +2 -3
  37. package/dist/index.d.cts +4 -4
  38. package/dist/{index.d.ts → index.d.mts} +5 -5
  39. package/dist/index.d.mts.map +1 -0
  40. package/dist/{index.js → index.mjs} +3 -3
  41. package/dist/{index.cjs.map → index.mjs.map} +1 -1
  42. package/dist/ssr.cjs +2 -3
  43. package/dist/ssr.d.cts +2 -2
  44. package/dist/{ssr.d.ts → ssr.d.mts} +3 -3
  45. package/dist/ssr.d.mts.map +1 -0
  46. package/dist/{ssr.js → ssr.mjs} +2 -2
  47. package/dist/{ssr.cjs.map → ssr.mjs.map} +1 -1
  48. package/package.json +17 -17
  49. package/scripts/copyToRepl.ts +6 -6
  50. package/src/compile/build/client/addMappedTextWithOffsets.ts +31 -0
  51. package/src/compile/build/client/buildAddFragment.ts +11 -11
  52. package/src/compile/build/client/buildComponentNode.ts +123 -29
  53. package/src/compile/build/client/buildElementNode.ts +65 -8
  54. package/src/compile/build/client/buildIfNode.ts +1 -1
  55. package/src/compile/build/client/buildSwitchNode.ts +1 -1
  56. package/src/compile/build/client/buildTextNode.ts +13 -6
  57. package/src/compile/build/client/getAttributeOffsets.ts +90 -0
  58. package/src/compile/build/client/stashRunWithOffsets.ts +7 -1
  59. package/src/compile/build/server/buildServerElementNode.ts +1 -1
  60. package/src/compile/parse/parseTag.ts +1 -7
  61. package/src/compile/parse/parseText.ts +1 -1
  62. package/src/render/buildClasses.ts +1 -1
  63. package/src/render/buildStyles.ts +3 -1
  64. package/src/types/ClassValue.ts +6 -1
  65. package/src/types/StyleValue.ts +6 -1
  66. package/test/source-maps/interpolated.test.ts +88 -0
  67. package/test/source-maps/parse.test.ts +1 -1
  68. package/tsdown.config.ts +2 -9
  69. package/vitest.config.ts +3 -3
  70. package/dist/Cleanup-BGQ5zaxE.d.cts.map +0 -1
  71. package/dist/Cleanup-Ca8IspaG.d.ts.map +0 -1
  72. package/dist/Component-JVwSemf-.d.ts.map +0 -1
  73. package/dist/Region-BrsZLZUe.d.ts.map +0 -1
  74. package/dist/compile.cjs.map +0 -1
  75. package/dist/compile.d.ts.map +0 -1
  76. package/dist/compile.js.map +0 -1
  77. package/dist/dev.d.ts.map +0 -1
  78. package/dist/dev.js.map +0 -1
  79. package/dist/devContext-CevrTlUO.js.map +0 -1
  80. package/dist/formatText-Bcb1JvW5.d.cts.map +0 -1
  81. package/dist/formatText-BlLF3PPm.d.ts.map +0 -1
  82. package/dist/formatText-Ck04q8_X.cjs.map +0 -1
  83. package/dist/formatText-OyD8MNAM.js.map +0 -1
  84. package/dist/index.d.ts.map +0 -1
  85. package/dist/index.js.map +0 -1
  86. package/dist/ssr.d.ts.map +0 -1
  87. package/dist/ssr.js.map +0 -1
@@ -2,7 +2,6 @@ import type Attribute from "../types/nodes/Attribute";
2
2
  import type ElementNode from "../types/nodes/ElementNode";
3
3
  import isFullyReactive from "../utils/isFullyReactive";
4
4
  import isReactive from "../utils/isReactive";
5
- import trimQuotes from "../utils/trimQuotes";
6
5
  import type ParseStatus from "./ParseStatus";
7
6
  import parseInlineScript from "./parseInlineScript";
8
7
  import accept from "./utils/accept";
@@ -17,7 +16,7 @@ export default function parseTag(status: ParseStatus): ElementNode {
17
16
 
18
17
  consumeSpace(status);
19
18
 
20
- let tagStart = status.i;
19
+ let tagStart = status.i + 1;
21
20
  let snailed = accept("@", status);
22
21
  let tagName = consumeAlphaNumeric(status);
23
22
  let tagEnd = status.i;
@@ -109,11 +108,6 @@ function parseAttribute(status: ParseStatus): Attribute {
109
108
  value = value.substring(1, value.length - 1);
110
109
  valueStart++;
111
110
  valueEnd--;
112
- } else if (reactive) {
113
- // TODO: Ranges etc, like text nodes -- I think we would need to
114
- // leave things reactive (or fully reactive) and check it when
115
- // building instead
116
- value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
117
111
  }
118
112
  } else if (name.startsWith("{") && name.endsWith("}")) {
119
113
  // It's a shortcut attribute. It could be e.g. {width} or it could be
@@ -84,7 +84,7 @@ export default function parseText(status: ParseStatus, element: ElementNode): vo
84
84
  const text: TextNode = {
85
85
  type: "text",
86
86
  content: content + spaceContent,
87
- spans: spans,
87
+ spans,
88
88
  };
89
89
  element.children.push(text);
90
90
  }
@@ -16,7 +16,7 @@ export default function buildClasses(value: ClassValue, styleHash?: string): str
16
16
  }
17
17
  }
18
18
 
19
- function gatherNames(name: string, value: ClassValue, classes: string[]) {
19
+ function gatherNames(name: string, value: unknown, classes: string[]) {
20
20
  if (value) {
21
21
  if (Array.isArray(value)) {
22
22
  for (let v of value) {
@@ -8,7 +8,9 @@ export default function buildStyles(value: StyleValue): string {
8
8
  if (value) {
9
9
  if (Array.isArray(value)) {
10
10
  for (let v of value) {
11
- styles.push(v);
11
+ if (v) {
12
+ styles.push(v);
13
+ }
12
14
  }
13
15
  } else if (typeof value === "object") {
14
16
  for (let [n, v] of Object.entries(value)) {
@@ -1,3 +1,8 @@
1
- type ClassValue = string | Record<string, string> | undefined | Array<ClassValue>;
1
+ type ClassValue =
2
+ | string
3
+ | Record<string, boolean | null | undefined>
4
+ | Array<ClassValue>
5
+ | null
6
+ | undefined;
2
7
 
3
8
  export default ClassValue;
@@ -1,3 +1,8 @@
1
- type StyleValue = string | Record<string, string> | Array<string> | undefined;
1
+ type StyleValue =
2
+ | string
3
+ | Record<string, string | null | undefined>
4
+ | Array<string | null | undefined>
5
+ | null
6
+ | undefined;
2
7
 
3
8
  export default StyleValue;
@@ -0,0 +1,88 @@
1
+ import { expect, test } from "vitest";
2
+ import { build } from "../../src/compile";
3
+ import parse from "../../src/compile/parse";
4
+
5
+ test("source maps with interpolated attributes in element", () => {
6
+ const input = `
7
+ export default function Source() {
8
+ @render {
9
+ <div id="{a}-{bc}-{d}"></div>
10
+ }
11
+ }
12
+ `.trim();
13
+
14
+ const parsed = parse(input);
15
+ const built = build(parsed.template!, { mapped: true });
16
+
17
+ //console.log(built.code);
18
+ //console.log(built.map);
19
+
20
+ const matches = built.map.filter(
21
+ (m) => m.script === 't_attribute(t_div_1, "id", `${a}-${bc}-${d}`);',
22
+ );
23
+ expect(matches.length).toBe(3);
24
+
25
+ expect(matches[0].source.start).toBe(input.indexOf("{a}") + 1);
26
+ expect(matches[0].compiled.start).toBe(built.code.indexOf("{a}") + 1);
27
+ expect(matches[1].source.start).toBe(input.indexOf("{bc}") + 1);
28
+ expect(matches[1].compiled.start).toBe(built.code.indexOf("{bc}") + 1);
29
+ expect(matches[2].source.start).toBe(input.indexOf("{d}") + 1);
30
+ expect(matches[2].compiled.start).toBe(built.code.indexOf("{d}") + 1);
31
+ });
32
+
33
+ test("source maps with interpolated attributes in component", () => {
34
+ const input = `
35
+ export default function Source() {
36
+ @render {
37
+ <Child id="{a}-{bc}-{d}" />
38
+ }
39
+ }
40
+ `.trim();
41
+
42
+ const parsed = parse(input);
43
+ const built = build(parsed.template!, { mapped: true });
44
+
45
+ //console.log(built.code);
46
+ //console.log(built.map);
47
+
48
+ const matches = built.map.filter((m) => m.script === "id: `${a}-${bc}-${d}`,");
49
+ expect(matches.length).toBe(3);
50
+
51
+ expect(matches[0].source.start).toBe(input.indexOf("{a}") + 1);
52
+ expect(matches[0].compiled.start).toBe(built.code.indexOf("{a}") + 1);
53
+ expect(matches[1].source.start).toBe(input.indexOf("{bc}") + 1);
54
+ expect(matches[1].compiled.start).toBe(built.code.indexOf("{bc}") + 1);
55
+ expect(matches[2].source.start).toBe(input.indexOf("{d}") + 1);
56
+ expect(matches[2].compiled.start).toBe(built.code.indexOf("{d}") + 1);
57
+ });
58
+
59
+ test("source maps with interpolated text", () => {
60
+ const input = `
61
+ export default function Source() {
62
+ @render {
63
+ <div>
64
+ id={a}
65
+ and {bc}, {d}
66
+ </div>
67
+ }
68
+ }
69
+ `.trim();
70
+
71
+ const parsed = parse(input);
72
+ const built = build(parsed.template!, { mapped: true });
73
+
74
+ //console.log(built.code);
75
+ //console.log(built.map);
76
+
77
+ const matches = built.map.filter(
78
+ (m) => m.script === "t_text_1.textContent = ` id=${t_fmt(a)} and ${t_fmt(bc)}, ${t_fmt(d)} `;",
79
+ );
80
+ expect(matches.length).toBe(3);
81
+
82
+ expect(matches[0].source.start).toBe(input.indexOf("{a}") + 1);
83
+ expect(matches[0].compiled.start).toBe(built.code.indexOf("(a)") + 1);
84
+ expect(matches[1].source.start).toBe(input.indexOf("{bc}") + 1);
85
+ expect(matches[1].compiled.start).toBe(built.code.indexOf("(bc)") + 1);
86
+ expect(matches[2].source.start).toBe(input.indexOf("{d}") + 1);
87
+ expect(matches[2].compiled.start).toBe(built.code.indexOf("(d)") + 1);
88
+ });
@@ -2,7 +2,7 @@ import { assert, expect, test } from "vitest";
2
2
  import { build } from "../../src/compile";
3
3
  import parse from "../../src/compile/parse";
4
4
 
5
- test("source maps", () => {
5
+ test("parse source maps", () => {
6
6
  const input = `
7
7
  export default function Source($props: { counter: number }) {
8
8
  const x = 5;
package/tsdown.config.ts CHANGED
@@ -1,13 +1,6 @@
1
- import { type Options, defineConfig } from "tsdown";
2
-
3
- type Config =
4
- | Options
5
- | Options[]
6
- | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
1
+ import { type UserConfig, defineConfig } from "tsdown";
7
2
 
8
3
  export default defineConfig({
9
4
  entry: ["src/index.ts", "src/compile.ts", "src/ssr.ts", "src/dev.ts"],
10
5
  format: ["esm", "cjs"],
11
- dts: true,
12
- sourcemap: true,
13
- }) satisfies Config as Config;
6
+ }) satisfies UserConfig as UserConfig;
package/vitest.config.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type UserConfigFnObject, defineConfig } from "vitest/config";
2
- import torpor from "../unplugin/dist/vite";
1
+ import { type ViteUserConfigFnObject, defineConfig } from "vitest/config";
2
+ import torpor from "../unplugin/dist/vite.mjs";
3
3
 
4
4
  export default defineConfig(({ mode }) => ({
5
5
  plugins: [torpor()],
@@ -10,4 +10,4 @@ export default defineConfig(({ mode }) => ({
10
10
  environment: "jsdom",
11
11
  globalSetup: "./test/globalSetup.ts",
12
12
  },
13
- })) satisfies UserConfigFnObject as UserConfigFnObject;
13
+ })) satisfies ViteUserConfigFnObject as ViteUserConfigFnObject;
@@ -1 +0,0 @@
1
- {"version":3,"file":"Cleanup-BGQ5zaxE.d.cts","names":[],"sources":["../src/types/Cleanup.ts"],"sourcesContent":[],"mappings":";;;;;KAIK,OAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Cleanup-Ca8IspaG.d.ts","names":[],"sources":["../src/types/Cleanup.ts"],"sourcesContent":[],"mappings":";;;;;KAIK,OAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Component-JVwSemf-.d.ts","names":[],"sources":["../src/types/SlotRender.ts","../src/types/Component.ts"],"sourcesContent":[],"mappings":";KAAK,UAAA,cACM,sBACA,uBACA,OAAO,8BACN,OAAO;;;;;;KCCd,SAAA,GDFa,CAAA,OAAA,ECGR,UDHQ,EAAA,OAAA,ECIR,IDJQ,GAAA,IAAA,EAAA,MAAA,CAAA,ECKR,MDLQ,CCKD,WDLC,EAAA,GAAA,CAAA,EAAA,QAAA,CAAA,ECMN,MDNM,CCMC,WDND,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,ECOR,MDPQ,CAAA,MAAA,ECOO,UDPP,CAAA,EAAA,GAAA,IAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Region-BrsZLZUe.d.ts","names":[],"sources":["../src/types/constants.ts","../src/types/Computed.ts","../src/types/ProxySignal.ts","../src/types/Subscription.ts","../src/types/Effect.ts","../src/types/Region.ts"],"sourcesContent":[],"mappings":";;;;;;AAGa,cAAA,WAAA,GAAA,CAAA;AAKb;AAKA;;cALa,aAAA;;ACPiB;;AAgBtB,cDJK,WAAA,GCIL,CAAA;;;;ADdR;AAKA;AAKA;;UCLyB;;AAPK;;EAgBtB,IAAA,EAAA,OALM,aAKN;EAKI;;;EAiCD,KAAA,EAtCH,CAsCG;EAAA;;;aAjCC;ECrBgB;;;EAoBP,WAAA,EDMP,YCNO,GAAA,IAAA;EAAA;;;eDWP;EE9Be;;;;;;EA2BhB,MAAA,EAAA,OAAA;EAQI;;;;;ACnCW;;EAehB,QAAA,EAAA,OAAA;EAKF;;;EAoBQ,QAAA,EHaP,YGbO,GAAA,IAAA;EAAA;;;;;;;;AJvClB;AAKA;AAKA;UENyB,WAAA;;;ADNK;EAWhB,IAAA,EAAA,OCDA,WDCA;EAKN;;;EAeM,WAAA,EChBA,YDgBA,GAAA,IAAA;EAuBH;;;sBClCU;;AApBO;;EAed,IAAA,CAAA,EAAA,MAAA;;;;AFbd;AAKA;AAKA;;UGLyB,YAAA;;AFPK;;EAgBtB,MAAA,EELC,WFKD,GELe,QFKf;EAKI;;;EAiCD,MAAA,EEtCF,QFsCE,GEtCS,MFsCT;EAAA;;;;ECtDiB,UAMH,ECgBZ,YDhBY,GAAA,IAAA;EAIX;;;;cCkBD;;;AA3BgB;;;;EAeT,cAAA,EAoBH,YApBG,GAAA,IAAA;EAMP;;;;;;;ACrBe;;;EAoBlB,MAAA,EAAA,OAAA;EAKI;;;EAeI,IAAA,CAAA,EAAA,MAAA;;;;AJvClB;AAKA;AAKA;UINyB,MAAA;;;AHNK;EAWhB,IAAA,EAAA,OGDA,WHCA;EAKN;;;;EAsCG,GAAA,EAAA,GAAA,GGtCC,OHsCD,GAAA,IAAA;EAAA;;;WGjCD;EFrBkB;;;EAoBP,WAAA,EEMP,YFNO,GAAA,IAAA;EAAA,UAAA,EEWR,MFXQ,GAAA,IAAA;;;;ECnBQ,MAMJ,EAAA,MAAA;EAIhB;;;EAKW,eAAA,ECyBF,MDzBE,GAAA,IAAA;EAMP;;;EAcI,QAAA,EAAA,OAAA;;;;ECnCW,IAKH,CAAA,EAAA,MAAA;;;;UCPA,MAAA;aACb;WACF;ELCV,cAAa,EKCI,MLDJ,GAAA,IAAA;EAKb,UAAa,EKHA,MLGA,GAAA,IAAA;EAKb,KAAa,EAAA,MAAA;;;;ACZiB;EAWhB,UAAA,EIAD,GJAC,CIAG,SJAH,CAAA,GAAA,IAAA;EAKN;;;EAeM,IAAA,CAAA,EAAA,MAAA"}