-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsx-runtime.js
69 lines (69 loc) · 2.38 KB
/
jsx-runtime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import ElementComponent from '../../@xylem-js/xylem-js/dom/_internal/ElementComponent.js';
import isSupplier from '../../@xylem-js/xylem-js/utilities/isSupplier.js';
import TextComponent from '../../@xylem-js/xylem-js/dom/_internal/TextComponent.js';
const listenerRegexOn = /^on:(.+)$/;
const listenerRegexAt = /^@(.+)$/;
export function jsxs(tagName, attributesWithChildren, key) {
let { children, ...attributes } = attributesWithChildren;
if (arguments.length > 2) {
attributes.key = key;
}
let childrenArray;
if (Array.isArray(children)) {
childrenArray = children.flat();
}
else if (children === undefined) {
childrenArray = [];
}
else if (typeof children === 'string') {
childrenArray = [new TextComponent(children)];
}
else {
childrenArray = [children];
}
childrenArray = (childrenArray).map(child => {
if (typeof child === 'object' && child !== null) {
if (Array.isArray(child)) {
throw new Error(`child is array`);
}
else if (isSupplier(child)) {
return new TextComponent(child);
}
else {
return child;
}
}
return new TextComponent(child);
});
if (typeof tagName === 'string') {
const elementComponent = new ElementComponent(tagName, attributes, childrenArray);
for (const key in attributes) {
if (key === '<>') {
elementComponent.elementSubscriber(attributes['<>']);
attributes['<>'] = false;
}
else if (listenerRegexOn.test(key)) {
const [, eventName] = listenerRegexOn.exec(key);
elementComponent.addListener(eventName, attributes[key]);
attributes[key] = false;
}
else if (listenerRegexAt.test(key)) {
const [, eventName] = listenerRegexAt.exec(key);
elementComponent.addListener(eventName, attributes[key]);
attributes[key] = false;
}
}
return elementComponent;
}
else if (tagName === Fragment) {
return childrenArray;
}
else {
return new tagName(attributesWithChildren);
}
}
export function jsx(_tagName, _attributesWithChildren, _key) {
return jsxs.apply(null, arguments);
}
export function Fragment() {
}