@praxisjs/jsx 0.3.1 → 0.3.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @praxisjs/jsx
2
2
 
3
+ ## 0.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - @praxisjs/runtime@0.2.3
8
+
3
9
  ## 0.3.1
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=jsx-runtime.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/jsx-runtime.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,69 @@
1
+ // @vitest-environment jsdom
2
+ import { describe, it, expect } from "vitest";
3
+ import { Scope, runInScope } from "@praxisjs/runtime";
4
+ import { jsx, jsxs, jsxDEV, Fragment } from "../jsx-runtime";
5
+ function withScope(fn) {
6
+ const scope = new Scope();
7
+ return runInScope(scope, fn);
8
+ }
9
+ describe("Fragment", () => {
10
+ it("is a unique Symbol", () => {
11
+ expect(typeof Fragment).toBe("symbol");
12
+ });
13
+ it("returns [] when no children are provided", () => {
14
+ const result = withScope(() => jsx(Fragment, {}));
15
+ expect(result).toEqual([]);
16
+ });
17
+ it("returns [] when children is empty array", () => {
18
+ const result = withScope(() => jsx(Fragment, { children: [] }));
19
+ expect(Array.isArray(result)).toBe(true);
20
+ });
21
+ it("wraps a single Node in an array", () => {
22
+ const node = document.createElement("span");
23
+ const result = withScope(() => jsx(Fragment, { children: node }));
24
+ expect(result).toHaveLength(1);
25
+ expect(result[0]).toBe(node);
26
+ });
27
+ it("flattens an array of Nodes", () => {
28
+ const a = document.createElement("div");
29
+ const b = document.createElement("span");
30
+ const result = withScope(() => jsx(Fragment, { children: [a, b] }));
31
+ expect(result).toHaveLength(2);
32
+ expect(result[0]).toBe(a);
33
+ expect(result[1]).toBe(b);
34
+ });
35
+ });
36
+ describe("jsx — string tag", () => {
37
+ it("creates a DOM element for a string tag", () => {
38
+ const el = withScope(() => jsx("div", {}));
39
+ expect(el).toBeInstanceOf(HTMLDivElement);
40
+ });
41
+ it("applies class prop", () => {
42
+ const el = withScope(() => jsx("p", { class: "text-lg" }));
43
+ expect(el.getAttribute("class")).toBe("text-lg");
44
+ });
45
+ it("renders string children", () => {
46
+ const el = withScope(() => jsx("span", { children: "hello" }));
47
+ expect(el.textContent).toBe("hello");
48
+ });
49
+ it("creates an SVG element for svg tags", () => {
50
+ const el = withScope(() => jsx("svg", {}));
51
+ expect(el).toBeInstanceOf(SVGElement);
52
+ });
53
+ });
54
+ describe("jsx — unknown type", () => {
55
+ it("returns a comment node for an unknown symbol type", () => {
56
+ const unknownType = Symbol("unknown");
57
+ const result = withScope(() => jsx(unknownType, {}));
58
+ expect(result.nodeType).toBe(Node.COMMENT_NODE);
59
+ });
60
+ });
61
+ describe("jsxs and jsxDEV", () => {
62
+ it("jsxs is the same function as jsx", () => {
63
+ expect(jsxs).toBe(jsx);
64
+ });
65
+ it("jsxDEV is the same function as jsx", () => {
66
+ expect(jsxDEV).toBe(jsx);
67
+ });
68
+ });
69
+ //# sourceMappingURL=jsx-runtime.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime.test.js","sourceRoot":"","sources":["../../src/__tests__/jsx-runtime.test.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAG,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE7D,SAAS,SAAS,CAAI,EAAW;IAC/B,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;IAC1B,OAAO,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1
1
  {
2
2
  "name": "@praxisjs/jsx",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "typescript": "^5.9.3"
23
23
  },
24
24
  "dependencies": {
25
- "@praxisjs/runtime": "0.2.2",
25
+ "@praxisjs/runtime": "0.2.3",
26
26
  "@praxisjs/shared": "0.2.0"
27
27
  },
28
28
  "scripts": {
@@ -0,0 +1,91 @@
1
+ // @vitest-environment jsdom
2
+ import { describe, it, expect } from "vitest";
3
+
4
+ import { Scope, runInScope } from "@praxisjs/runtime";
5
+
6
+ import { jsx, jsxs, jsxDEV, Fragment } from "../jsx-runtime";
7
+
8
+ function withScope<T>(fn: () => T): T {
9
+ const scope = new Scope();
10
+ return runInScope(scope, fn);
11
+ }
12
+
13
+ describe("Fragment", () => {
14
+ it("is a unique Symbol", () => {
15
+ expect(typeof Fragment).toBe("symbol");
16
+ });
17
+
18
+ it("returns [] when no children are provided", () => {
19
+ const result = withScope(() => jsx(Fragment, {}));
20
+ expect(result).toEqual([]);
21
+ });
22
+
23
+ it("returns [] when children is empty array", () => {
24
+ const result = withScope(() => jsx(Fragment, { children: [] }));
25
+ expect(Array.isArray(result)).toBe(true);
26
+ });
27
+
28
+ it("wraps a single Node in an array", () => {
29
+ const node = document.createElement("span");
30
+ const result = withScope(() => jsx(Fragment, { children: node })) as Node[];
31
+ expect(result).toHaveLength(1);
32
+ expect(result[0]).toBe(node);
33
+ });
34
+
35
+ it("flattens an array of Nodes", () => {
36
+ const a = document.createElement("div");
37
+ const b = document.createElement("span");
38
+ const result = withScope(() =>
39
+ jsx(Fragment, { children: [a, b] }),
40
+ ) as Node[];
41
+ expect(result).toHaveLength(2);
42
+ expect(result[0]).toBe(a);
43
+ expect(result[1]).toBe(b);
44
+ });
45
+ });
46
+
47
+ describe("jsx — string tag", () => {
48
+ it("creates a DOM element for a string tag", () => {
49
+ const el = withScope(() => jsx("div", {})) as HTMLElement;
50
+ expect(el).toBeInstanceOf(HTMLDivElement);
51
+ });
52
+
53
+ it("applies class prop", () => {
54
+ const el = withScope(() =>
55
+ jsx("p", { class: "text-lg" }),
56
+ ) as HTMLElement;
57
+ expect(el.getAttribute("class")).toBe("text-lg");
58
+ });
59
+
60
+ it("renders string children", () => {
61
+ const el = withScope(() =>
62
+ jsx("span", { children: "hello" }),
63
+ ) as HTMLElement;
64
+ expect(el.textContent).toBe("hello");
65
+ });
66
+
67
+ it("creates an SVG element for svg tags", () => {
68
+ const el = withScope(() => jsx("svg", {})) as SVGElement;
69
+ expect(el).toBeInstanceOf(SVGElement);
70
+ });
71
+ });
72
+
73
+ describe("jsx — unknown type", () => {
74
+ it("returns a comment node for an unknown symbol type", () => {
75
+ const unknownType = Symbol("unknown");
76
+ const result = withScope(() =>
77
+ jsx(unknownType as unknown as string, {}),
78
+ ) as Comment;
79
+ expect(result.nodeType).toBe(Node.COMMENT_NODE);
80
+ });
81
+ });
82
+
83
+ describe("jsxs and jsxDEV", () => {
84
+ it("jsxs is the same function as jsx", () => {
85
+ expect(jsxs).toBe(jsx);
86
+ });
87
+
88
+ it("jsxDEV is the same function as jsx", () => {
89
+ expect(jsxDEV).toBe(jsx);
90
+ });
91
+ });