Browse Source

Move list of selfclosing tags into its own module

master
Dylan Baker 4 years ago
parent
commit
a3e6a6df66
2 changed files with 24 additions and 22 deletions
  1. 2
    22
      src/compiler.js
  2. 22
    0
      src/util/selfClosingTags.js

+ 2
- 22
src/compiler.js View File

@@ -1,4 +1,5 @@
1 1
 const util = require('util')
2
+const selfClosingTags = require('./util/selfClosingTags')
2 3
 
3 4
 module.exports = class Compiler {
4 5
   constructor(tree, context) {
@@ -6,27 +7,6 @@ module.exports = class Compiler {
6 7
     this.context = context
7 8
     this.pos = 0
8 9
     this.result = ''
9
-    this.selfClosingTags = [
10
-      'area',
11
-      'base',
12
-      'br',
13
-      'col',
14
-      'command',
15
-      '!doctype',
16
-      '!DOCTYPE',
17
-      'embed',
18
-      'hr',
19
-      'img',
20
-      'input',
21
-      'keygen',
22
-      'link',
23
-      'menuitem',
24
-      'meta',
25
-      'param',
26
-      'source',
27
-      'track',
28
-      'wbr',
29
-    ]
30 10
     this.standardLibrary = {
31 11
       cond: function(predicate, left, right) {
32 12
         if (predicate) {
@@ -87,7 +67,7 @@ module.exports = class Compiler {
87 67
       result += compiler.compile()
88 68
     })
89 69
 
90
-    if (!this.selfClosingTags.includes(node.functionName.name)) {
70
+    if (!selfClosingTags.includes(node.functionName.name)) {
91 71
       result += `</${node.functionName.name}>`
92 72
     }
93 73
 

+ 22
- 0
src/util/selfClosingTags.js View File

@@ -0,0 +1,22 @@
1
+module.exports = [
2
+  'area',
3
+  'base',
4
+  'br',
5
+  'col',
6
+  'command',
7
+  '!doctype',
8
+  '!DOCTYPE',
9
+  'embed',
10
+  'hr',
11
+  'img',
12
+  'input',
13
+  'keygen',
14
+  'link',
15
+  'menuitem',
16
+  'meta',
17
+  'param',
18
+  'source',
19
+  'track',
20
+  'wbr',
21
+]
22
+

Loading…
Cancel
Save