aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-11-01 08:54:46 +0000
committers-ol <s-ol@users.noreply.github.com>2018-11-01 08:54:46 +0000
commit0fcadd15d802ab20167cade1608e93caa5072723 (patch)
tree06f74ab1932af5e0ad2dc39d1724f88291bb5145 /lib
parentrefactor browser SCSS (diff)
downloadmmm-0fcadd15d802ab20167cade1608e93caa5072723.tar.gz
mmm-0fcadd15d802ab20167cade1608e93caa5072723.zip
fix server-side void tags
Diffstat (limited to 'lib')
-rw-r--r--lib/component.server.moon15
-rw-r--r--lib/dom.server.moon13
2 files changed, 22 insertions, 6 deletions
diff --git a/lib/component.server.moon b/lib/component.server.moon
index d717ff7..0026d32 100644
--- a/lib/component.server.moon
+++ b/lib/component.server.moon
@@ -1,5 +1,8 @@
import opairs from require 'lib.ordered'
+void_tags = { 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr' }
+void_tags = { t,t for t in *void_tags }
+
-- convert anything to HTML string
-- val must be one of:
-- * MMMElement (have a .render method that returns a string)
@@ -97,9 +100,15 @@ class ReactiveElement
tmp ..= "#{kk}: #{vv}; "
v = tmp
b ..= " #{k}=\"#{v}\""
- b ..= ">" .. table.concat @children, ''
- b ..= "</#{@element}>"
- b
+
+ if void_tags[@element]
+ assert #@children == 0, "void tag #{element} cannot have children!"
+ b .. ">"
+ else
+ b .. ">"
+ b ..= ">" .. table.concat @children, ''
+ b ..= "</#{@element}>"
+ b
elements = setmetatable {}, __index: (name) =>
with val = (...) -> ReactiveElement name, ...
diff --git a/lib/dom.server.moon b/lib/dom.server.moon
index 3a7b537..fe6b60c 100644
--- a/lib/dom.server.moon
+++ b/lib/dom.server.moon
@@ -1,5 +1,8 @@
import opairs from require 'lib.ordered'
+void_tags = { 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr' }
+void_tags = { t,t for t in *void_tags }
+
element = (element) -> (...) ->
children = { ... }
@@ -24,9 +27,13 @@ element = (element) -> (...) ->
if #children == 0
children = attributes
- b ..= ">" .. table.concat children, ''
- b ..= "</#{element}>"
- b
+ if void_tags[element]
+ assert #children == 0, "void tag #{element} cannot have children!"
+ b .. ">"
+ else
+ b ..= ">" .. table.concat children, ''
+ b ..= "</#{element}>"
+ b
setmetatable {}, __index: (name) =>
with val = element name