ovr 2.0.0 → 2.0.1
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/dist/jsx/index.js +12 -11
- package/package.json +1 -1
package/dist/jsx/index.js
CHANGED
|
@@ -30,7 +30,7 @@ export async function* jsx(tag, props) {
|
|
|
30
30
|
else {
|
|
31
31
|
// element
|
|
32
32
|
const { children, ...attrs } = props;
|
|
33
|
-
|
|
33
|
+
const attrParts = [];
|
|
34
34
|
for (let key in attrs) {
|
|
35
35
|
const value = attrs[key]; // needs to come before reassigning keys
|
|
36
36
|
if (key === "className")
|
|
@@ -39,16 +39,16 @@ export async function* jsx(tag, props) {
|
|
|
39
39
|
key = "for";
|
|
40
40
|
if (value === true) {
|
|
41
41
|
// just put the key without the value
|
|
42
|
-
|
|
42
|
+
attrParts.push(` ${key}`);
|
|
43
43
|
}
|
|
44
44
|
else if (typeof value === "string" ||
|
|
45
45
|
typeof value === "number" ||
|
|
46
46
|
typeof value === "bigint") {
|
|
47
|
-
|
|
47
|
+
attrParts.push(` ${key}=${JSON.stringify(value)}`);
|
|
48
48
|
}
|
|
49
49
|
// otherwise, don't include the attribute
|
|
50
50
|
}
|
|
51
|
-
yield `<${tag}${
|
|
51
|
+
yield `<${tag}${attrParts.join("")}>`;
|
|
52
52
|
if (voidElements.has(tag))
|
|
53
53
|
return;
|
|
54
54
|
if (children)
|
|
@@ -74,8 +74,7 @@ export async function* toGenerator(element) {
|
|
|
74
74
|
element = element();
|
|
75
75
|
if (element instanceof Promise)
|
|
76
76
|
element = await element;
|
|
77
|
-
|
|
78
|
-
if (element == null || typeof element === "boolean")
|
|
77
|
+
if (element == null || typeof element === "boolean" || element === "")
|
|
79
78
|
return;
|
|
80
79
|
if (typeof element === "object") {
|
|
81
80
|
if (Symbol.asyncIterator in element) {
|
|
@@ -88,7 +87,7 @@ export async function* toGenerator(element) {
|
|
|
88
87
|
// this is where to escape string children if added in the future
|
|
89
88
|
generators.push(toGenerator(children));
|
|
90
89
|
}
|
|
91
|
-
|
|
90
|
+
let queue = new Array(generators.length).fill("");
|
|
92
91
|
const complete = new Set();
|
|
93
92
|
let current = 0;
|
|
94
93
|
for await (const { index, result } of merge(generators)) {
|
|
@@ -114,7 +113,9 @@ export async function* toGenerator(element) {
|
|
|
114
113
|
queue[index] += result.value; // queue the value for later
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
|
-
|
|
116
|
+
queue = queue.join("");
|
|
117
|
+
if (queue)
|
|
118
|
+
yield queue; // clear the queue
|
|
118
119
|
}
|
|
119
120
|
else {
|
|
120
121
|
yield JSON.stringify(element); // avoids things like [object Object]
|
|
@@ -136,8 +137,8 @@ export async function* toGenerator(element) {
|
|
|
136
137
|
* @returns A promise that resolves to the concatenated HTML.
|
|
137
138
|
*/
|
|
138
139
|
export const toString = async (element) => {
|
|
139
|
-
|
|
140
|
+
const parts = [];
|
|
140
141
|
for await (const value of toGenerator(element))
|
|
141
|
-
|
|
142
|
-
return
|
|
142
|
+
parts.push(value);
|
|
143
|
+
return parts.join("");
|
|
143
144
|
};
|