-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (32 loc) · 885 Bytes
/
index.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
"use strict";
var Lexer = require("./lexer");
var Tokenizer = require("./tokenizer");
var Parser = require("./parser");
function buildTree(React, node, env) {
var type = node[0];
var envTypeMapping = env[type];
if (envTypeMapping) {
node[0] = envTypeMapping;
}
// children
for (var i = 2; i < node.length; i++) {
if (typeof node[i] === "object") {
node[i] = buildTree(React, node[i], env);
}
}
return React.createElement.apply(null, node);
}
function render(React, jsx, env) {
var parser = new Parser(new Tokenizer(new Lexer(jsx)));
if (!parser.parse()) {
return null; // empty string, possibly a syntax error
}
var root = parser.root();
if (root.length == 2) {
return null; // empty string, possibly a syntax error
}
var el = buildTree(React, root[2], env);
return el;
}
render.default = render;
module.exports = render;