Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function E(node) {
- function isChildren(x) { return x instanceof Array; }
- function isText(x) { return typeof x === "string"; }
- if(!(node instanceof Array))
- return node;
- var element = node[0];
- var props = null;
- var text = null;
- var children = null;
- if(node.length > 1) {
- if(isChildren(node[1])) {
- children = node[1].map(E);
- } else if(isText(node[1])) {
- text = node[1];
- if(isChildren(node[2])) {
- children = node[2].map(E);
- }
- } else if(node.length == 2) {
- props = node[1];
- } else if(isChildren(node[2])) {
- props = node[1];
- children = node[2].map(E);
- } else if(isText(node[2])) {
- props = node[1];
- text = node[2];
- if(isChildren(node[3])) {
- children = node[3].map(E);
- }
- }
- }
- return React.createElement(element, props, text, children);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement