@server/next 0.28.9 → 0.28.10
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/package.json +1 -1
- package/src/jsx/jsx-runtime.js +28 -11
- package/src/jsx/jsx-runtime.test.jsx +92 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@server/next",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.10",
|
|
4
4
|
"description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
|
|
5
5
|
"homepage": "https://server-js.com/",
|
|
6
6
|
"repository": "https://github.com/franciscop/server-next.git",
|
package/src/jsx/jsx-runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const ENTITIES = {
|
|
2
2
|
"&": "&",
|
|
3
3
|
"<": "<",
|
|
4
4
|
">": ">",
|
|
@@ -6,23 +6,34 @@ const entities = {
|
|
|
6
6
|
"'": "'",
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
const encode = (str = "") => {
|
|
10
|
-
if (typeof str === "number") str = String(str);
|
|
11
|
-
if (typeof str !== "string") return "";
|
|
12
|
-
return str.replace(/[&<>"']/g, (tag) => entities[tag]);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
9
|
const SELFCLOSE = new Set(
|
|
16
10
|
"area,base,br,col,embed,hr,img,input,link,meta,source,track,wbr".split(","),
|
|
17
11
|
);
|
|
18
12
|
|
|
13
|
+
const SVG_TAGS = new Set([
|
|
14
|
+
"svg",
|
|
15
|
+
"circle",
|
|
16
|
+
"rect",
|
|
17
|
+
"path",
|
|
18
|
+
"line",
|
|
19
|
+
"g",
|
|
20
|
+
"text",
|
|
21
|
+
"defs",
|
|
22
|
+
]);
|
|
23
|
+
|
|
19
24
|
const REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
|
|
20
25
|
|
|
21
|
-
const
|
|
26
|
+
const ALT_NAMES = {
|
|
22
27
|
classname: "class",
|
|
23
28
|
htmlfor: "for",
|
|
24
29
|
};
|
|
25
30
|
|
|
31
|
+
const encode = (str = "") => {
|
|
32
|
+
if (typeof str === "number") str = String(str);
|
|
33
|
+
if (typeof str !== "string") return "";
|
|
34
|
+
return str.replace(/[&<>"']/g, (tag) => ENTITIES[tag]);
|
|
35
|
+
};
|
|
36
|
+
|
|
26
37
|
// valid primitives only — null, undefined, false, true are all skipped
|
|
27
38
|
const isValidChild = (child) =>
|
|
28
39
|
child != null && child !== false && child !== true;
|
|
@@ -53,7 +64,6 @@ const renderChild = (child) => {
|
|
|
53
64
|
|
|
54
65
|
if (typeof child === "function") {
|
|
55
66
|
const result = child();
|
|
56
|
-
// Strings returned by functions are pre-rendered HTML — don't re-encode them
|
|
57
67
|
if (result == null || result === false || result === true) return "";
|
|
58
68
|
if (typeof result === "string") return result;
|
|
59
69
|
if (typeof result === "number") return String(result);
|
|
@@ -63,7 +73,6 @@ const renderChild = (child) => {
|
|
|
63
73
|
if (typeof child === "string") return encode(child);
|
|
64
74
|
if (typeof child === "number") return String(child);
|
|
65
75
|
|
|
66
|
-
// Raw marker bypasses encoding (used by script, style, dangerouslySetInnerHTML)
|
|
67
76
|
if (typeof child === "object" && RAW in child) return child[RAW];
|
|
68
77
|
|
|
69
78
|
if (isReactElement(child)) {
|
|
@@ -133,7 +142,15 @@ const jsx = (tag, { children, ...props } = {}) => {
|
|
|
133
142
|
.filter(([k, v]) => !/on[A-Z]/.test(k) && typeof v !== "function")
|
|
134
143
|
.filter(([, v]) => v !== false)
|
|
135
144
|
.map(([k, v]) => {
|
|
136
|
-
const
|
|
145
|
+
const preserveSvg = k === "viewBox" || k === "preserveAspectRatio";
|
|
146
|
+
|
|
147
|
+
const key =
|
|
148
|
+
ALT_NAMES[k.toLowerCase()] ||
|
|
149
|
+
(SVG_TAGS.has(tag)
|
|
150
|
+
? preserveSvg
|
|
151
|
+
? k
|
|
152
|
+
: k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)
|
|
153
|
+
: encode(k));
|
|
137
154
|
|
|
138
155
|
if (v === true) return key;
|
|
139
156
|
|
|
@@ -537,3 +537,95 @@ describe("styles", () => {
|
|
|
537
537
|
).toRender('<div style="color:red"></div>');
|
|
538
538
|
});
|
|
539
539
|
});
|
|
540
|
+
|
|
541
|
+
describe("svg attributes", () => {
|
|
542
|
+
it("converts strokeWidth to stroke-width", () => {
|
|
543
|
+
expect(
|
|
544
|
+
<svg>
|
|
545
|
+
<circle strokeWidth="2" />
|
|
546
|
+
</svg>,
|
|
547
|
+
).toRender('<svg><circle stroke-width="2"></circle></svg>');
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("converts fillOpacity to fill-opacity", () => {
|
|
551
|
+
expect(
|
|
552
|
+
<svg>
|
|
553
|
+
<rect fillOpacity="0.5" />
|
|
554
|
+
</svg>,
|
|
555
|
+
).toRender('<svg><rect fill-opacity="0.5"></rect></svg>');
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it("converts strokeLinecap to stroke-linecap", () => {
|
|
559
|
+
expect(
|
|
560
|
+
<svg>
|
|
561
|
+
<line strokeLinecap="round" />
|
|
562
|
+
</svg>,
|
|
563
|
+
).toRender('<svg><line stroke-linecap="round"></line></svg>');
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it("does NOT break viewBox casing", () => {
|
|
567
|
+
expect(
|
|
568
|
+
<svg viewBox="0 0 100 100">
|
|
569
|
+
<rect />
|
|
570
|
+
</svg>,
|
|
571
|
+
).toRender('<svg viewBox="0 0 100 100"><rect></rect></svg>');
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it("handles mixed SVG attributes correctly", () => {
|
|
575
|
+
expect(
|
|
576
|
+
<svg viewBox="0 0 10 10">
|
|
577
|
+
<circle strokeWidth="1" fillOpacity="0.2" />
|
|
578
|
+
</svg>,
|
|
579
|
+
).toRender(
|
|
580
|
+
'<svg viewBox="0 0 10 10"><circle stroke-width="1" fill-opacity="0.2"></circle></svg>',
|
|
581
|
+
);
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it("keeps viewBox unchanged", () => {
|
|
585
|
+
expect(
|
|
586
|
+
<svg viewBox="0 0 100 100">
|
|
587
|
+
<rect />
|
|
588
|
+
</svg>,
|
|
589
|
+
).toRender('<svg viewBox="0 0 100 100"><rect></rect></svg>');
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
it("does NOT convert viewBox to view-box", () => {
|
|
593
|
+
expect(<svg viewBox="0 0 10 10"></svg>).toRender(
|
|
594
|
+
'<svg viewBox="0 0 10 10"></svg>',
|
|
595
|
+
);
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
it("converts strokeWidth to stroke-width", () => {
|
|
599
|
+
expect(
|
|
600
|
+
<svg>
|
|
601
|
+
<circle strokeWidth="2" />
|
|
602
|
+
</svg>,
|
|
603
|
+
).toRender('<svg><circle stroke-width="2"></circle></svg>');
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
it("converts fillOpacity to fill-opacity", () => {
|
|
607
|
+
expect(
|
|
608
|
+
<svg>
|
|
609
|
+
<rect fillOpacity="0.5" />
|
|
610
|
+
</svg>,
|
|
611
|
+
).toRender('<svg><rect fill-opacity="0.5"></rect></svg>');
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it("converts strokeLinecap to stroke-linecap", () => {
|
|
615
|
+
expect(
|
|
616
|
+
<svg>
|
|
617
|
+
<line strokeLinecap="round" />
|
|
618
|
+
</svg>,
|
|
619
|
+
).toRender('<svg><line stroke-linecap="round"></line></svg>');
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
it("handles mixed SVG attributes correctly", () => {
|
|
623
|
+
expect(
|
|
624
|
+
<svg viewBox="0 0 10 10">
|
|
625
|
+
<circle strokeWidth="1" fillOpacity="0.2" />
|
|
626
|
+
</svg>,
|
|
627
|
+
).toRender(
|
|
628
|
+
'<svg viewBox="0 0 10 10"><circle stroke-width="1" fill-opacity="0.2"></circle></svg>',
|
|
629
|
+
);
|
|
630
|
+
});
|
|
631
|
+
});
|