-
Notifications
You must be signed in to change notification settings - Fork 5
/
compile.js
38 lines (30 loc) · 858 Bytes
/
compile.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
"use strict";
var React = require("react");
function compileChildren (children) {
return children.map(function (child) {
if ( Array.isArray(child) ) {
if ( child.length === 0 ) {
return child;
} else if ( Array.isArray(child[0]) ) {
return child.map(compile);
} else {
return compile(child);
}
}
return child;
});
}
function compile (item) {
var type = item[0];
var props = item[1];
var children;
if ( props != null && props.constructor === Object ) {
children = item.slice(2);
} else {
props = {};
children = item.slice(1);
}
children = compileChildren(children);
return React.createElement.apply(React, [type, props].concat(children));
}
module.exports = compile;