ast.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var htmlPaths = require("../styles/html-paths");
  2. function nonFreshElement(tagName, attributes, children) {
  3. return elementWithTag(
  4. htmlPaths.element(tagName, attributes, {fresh: false}),
  5. children);
  6. }
  7. function freshElement(tagName, attributes, children) {
  8. var tag = htmlPaths.element(tagName, attributes, {fresh: true});
  9. return elementWithTag(tag, children);
  10. }
  11. function elementWithTag(tag, children) {
  12. return {
  13. type: "element",
  14. tag: tag,
  15. children: children || []
  16. };
  17. }
  18. function text(value) {
  19. return {
  20. type: "text",
  21. value: value
  22. };
  23. }
  24. var forceWrite = {
  25. type: "forceWrite"
  26. };
  27. exports.freshElement = freshElement;
  28. exports.nonFreshElement = nonFreshElement;
  29. exports.elementWithTag = elementWithTag;
  30. exports.text = text;
  31. exports.forceWrite = forceWrite;
  32. var voidTagNames = {
  33. "br": true,
  34. "hr": true,
  35. "img": true
  36. };
  37. function isVoidElement(node) {
  38. return (node.children.length === 0) && voidTagNames[node.tag.tagName];
  39. }
  40. exports.isVoidElement = isVoidElement;