-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.jsx
94 lines (75 loc) · 1.82 KB
/
index.jsx
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/** @jsx h *//** @jsxFrag h */
const {render, html, bind, jsx2} = require('./jsx.js');
const assert = (value, expected) => {
/* c8 ignore start */
if (expected !== render(String, value)) {
console.error('got ', render(String, value));
console.error('expected', expected);
process.exit(1);
}
/* c8 ignore stop */
};
let h = jsx2.html;
// any component (passed as template value)
const Bold = ({children}) => html`<strong>${children}</strong>`;
class Span {
constructor({id, children}) {
return html`<span id=${id}>${children}</span>`;
}
}
// This is specific for ube or classes with a `tagName`
// these well be used as interpolations values
function World() { return World.tagName; }
World.tagName = 'div';
// any generic value
const test = 123;
// test it!
const myDocument = (
<p class="what" nope={null} test={bind(test)} onClick={console.log}>
<Bold>Hello</Bold>, <input type="password" disabled={true} />
<Span id="greetings">Hello</Span> <World />
</p>
);
assert(
myDocument,
`<p class="what" test="123"><strong>Hello</strong>, <input type="password" disabled><span id="greetings">Hello</span> <div></div></p>`
);
h = jsx2.svg;
const svgDocument = (
<rect x={10} y="20"></rect>
);
assert(
svgDocument,
'<rect x="10" y="20" />'
);
const fragment = (
<>
<rect key={Math.random()} x={'1'} y="2"></rect>
<rect x="3" y={4}></rect>
OK
</>
);
assert(
fragment,
'<rect x="1" y="2" /><rect x="3" y="4" />OK'
);
console.log('Test: \x1b[1mOK\x1b[0m');
const svg = (
<svg>
<g transform="translate(20,20)">
<text>hello</text>
</g>
</svg>
);
function MyElement({ children }) {
return <div>{children}</div>;
}
const me = (
<MyElement>
Some Text <b>and some more text</b>
</MyElement>
);
assert(
me,
'<div>Some Text <b>and some more text</b></div>'
);