diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-06-09 22:32:30 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-06-20 12:06:19 +0100 |
| commit | ac3981df81148fad21c32b22496ecc145ad36e98 (patch) | |
| tree | cfba69d2fedb0cacc7d544749f199bd339a1c6ad /lib/html/ast.js | |
| parent | 8617c85c8626354fff63eeaeb775402715fe63a4 (diff) | |
Use simpler structure for HTML without fragments
Diffstat (limited to 'lib/html/ast.js')
| -rw-r--r-- | lib/html/ast.js | 33 |
1 files changed, 3 insertions, 30 deletions
diff --git a/lib/html/ast.js b/lib/html/ast.js index 30e65c7..db9e690 100644 --- a/lib/html/ast.js +++ b/lib/html/ast.js @@ -1,15 +1,6 @@ -var _ = require("underscore"); - var htmlPaths = require("../html-paths"); -function fragment(children) { - return { - type: "fragment", - children: collapseFragments(children) - }; -} - function nonFreshElement(tagName, attributes, children) { return elementWithTag( htmlPaths.element(tagName, attributes, {fresh: false}), @@ -26,18 +17,9 @@ function elementWithTag(tag, children) { return { type: "element", tag: tag, - children: collapseFragments(children), - isEmpty: _.all(children, function(child) { - return child.isEmpty; - }), - appendChild: appendChild + children: children || [] }; } - -function appendChild(child) { - this.children.push(child); - this.isEmpty = this.isEmpty && child.isEmpty; -} function selfClosingElement(tagName, attributes) { return { @@ -50,23 +32,14 @@ function selfClosingElement(tagName, attributes) { function text(value) { return { type: "text", - value: value, - isEmpty: !value + value: value }; } var forceWrite = { - type: "forceWrite", - isEmpty: false + type: "forceWrite" }; -function collapseFragments(elements) { - return _.flatten((elements || []).map(function(element) { - return element.type === "fragment" ? element.children : [element]; - }), true); -} - -exports.fragment = fragment; exports.freshElement = freshElement; exports.nonFreshElement = nonFreshElement; exports.elementWithTag = elementWithTag; |
