|
@@ -6,6 +6,26 @@ module.exports = class Compiler {
|
6
|
6
|
}
|
7
|
7
|
|
8
|
8
|
compile() {
|
|
9
|
+ const selfClosingTags = [
|
|
10
|
+ 'area',
|
|
11
|
+ 'base',
|
|
12
|
+ 'br',
|
|
13
|
+ 'col',
|
|
14
|
+ 'command',
|
|
15
|
+ 'embed',
|
|
16
|
+ 'hr',
|
|
17
|
+ 'img',
|
|
18
|
+ 'input',
|
|
19
|
+ 'keygen',
|
|
20
|
+ 'link',
|
|
21
|
+ 'menuitem',
|
|
22
|
+ 'meta',
|
|
23
|
+ 'param',
|
|
24
|
+ 'source',
|
|
25
|
+ 'track',
|
|
26
|
+ 'wbr',
|
|
27
|
+ ]
|
|
28
|
+
|
9
|
29
|
this.tree.forEach(node => {
|
10
|
30
|
if (node.type === 'functionCall') {
|
11
|
31
|
const attributes = node.args.map(
|
|
@@ -18,7 +38,16 @@ module.exports = class Compiler {
|
18
|
38
|
const content = compiler.compile()
|
19
|
39
|
this.result += `<${node.functionName}${
|
20
|
40
|
attributes.length ? ' ' : ''
|
21
|
|
- }${attributes.join(' ')}>${content}</${node.functionName}>`
|
|
41
|
+ }${attributes.join(' ')}>`
|
|
42
|
+
|
|
43
|
+ if (content) {
|
|
44
|
+ this.result += content
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ if (!selfClosingTags.includes(node.functionName)) {
|
|
48
|
+ this.result += `</${node.functionName}>`
|
|
49
|
+ }
|
|
50
|
+
|
22
|
51
|
} else if (node.type === 'string') {
|
23
|
52
|
this.result += node.content
|
24
|
53
|
} else if (node.type === 'identifier') {
|