Browse Source

Move list of selfclosing tags into its own module

master
Dylan Baker 5 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
 const util = require('util')
1
 const util = require('util')
2
+const selfClosingTags = require('./util/selfClosingTags')
2
 
3
 
3
 module.exports = class Compiler {
4
 module.exports = class Compiler {
4
   constructor(tree, context) {
5
   constructor(tree, context) {
6
     this.context = context
7
     this.context = context
7
     this.pos = 0
8
     this.pos = 0
8
     this.result = ''
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
     this.standardLibrary = {
10
     this.standardLibrary = {
31
       cond: function(predicate, left, right) {
11
       cond: function(predicate, left, right) {
32
         if (predicate) {
12
         if (predicate) {
87
       result += compiler.compile()
67
       result += compiler.compile()
88
     })
68
     })
89
 
69
 
90
-    if (!this.selfClosingTags.includes(node.functionName.name)) {
70
+    if (!selfClosingTags.includes(node.functionName.name)) {
91
       result += `</${node.functionName.name}>`
71
       result += `</${node.functionName.name}>`
92
     }
72
     }
93
 
73
 

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

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