From 2e32dc85f2fdc67815ec0c679e387b4dee4515e6 Mon Sep 17 00:00:00 2001 From: Chris Blake Date: Thu, 3 Mar 2016 16:03:28 -0500 Subject: [PATCH] Fixes `Node.freeze`. When I added the style property to the node object, I forgot to update `Node.freeze` accordingly. This is a breaking change. --- dist/lmth.min.js | 4 ++-- lib/index.js | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/lmth.min.js b/dist/lmth.min.js index 9eca1a1..3970361 100644 --- a/dist/lmth.min.js +++ b/dist/lmth.min.js @@ -1,7 +1,7 @@ // https://github.com/chrisdotcode/lmth !function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.lmth=t()}(this,function(){"use strict" function e(t,n,r,i,a,o,s){if(!(this instanceof e))throw new Error("Uh-oh. You're creating a new Node without using the `new` keyword. This isn't allowed because Bad Stuff happens when you do that. What you more than likely want is one of the element functions attached to the Node object like so: `lmth.div(...)`. If you actually did want to create a plain node, you should use `Node.new(name, id, class, style, attributes, content, children)` and avoid the manual construction with `new` where possible. If you really, really, really want to create a node with `new`, you can do so like this: `new Node(name, class, style, attributes, content, children)`.") -return this.name=t,this.id=n,this["class"]=r,this.style=i,this.attributes=a,this.content=o,this.children=s||[],this}function t(e){switch(typeof e){case"bool":case"number":case"string":return!0 +return this.name=t,this.id=n,this["class"]=r,this.style=i,this.attributes=a,this.content=o,this.children=s,this}function t(e){switch(typeof e){case"bool":case"number":case"string":return!0 default:return!1}}function n(e){return"[object Object]"===toString.call(e)}function r(e){return t(e)?"primitive":n(e)?"object":Array.isArray(e)?"array":void 0}function i(e){return"[object String]"===toString.call(e)}function a(e){var t={id:null,"class":[]} if(i(e)){var r=e.split(/([#\.][^#\.]+)/) r.forEach(function(e){e.startsWith("#")?t.id=e.substring(1):e.startsWith(".")&&t["class"].push(e.substring(1))})}else n(e)&&(Object.keys(e).forEach(function(n){t[n]=e[n]}),Array.isArray(t["class"])||(t["class"]=t["class"].split(" "))) @@ -12,7 +12,7 @@ case'"':return""" case"'":return"'"}})}function s(e,t){return t?e+'="'+o(t)+'"':e}function c(e){return Object.keys(e).reduce(function(t,n){return t+n+":"+e[n]+";"},"")}return e.prototype.toString=function(){return JSON.stringify(this)},e["new"]=function(t,n,r,i,a,o,s){return new e(t,n,r,i,a,o,s)},e.createElement=function(t){return function(n,o,s){var c="",u={},l=[],d=r(n),f=r(o) i(n)||"object"===d?u=n:"array"===d&&(l=n),"primitive"===f?c=o:"object"===f?u=o:"array"===f&&(l=o),"array"===r(s)&&(l=s) var h=a(u),m=h.id,p=h["class"],b=h.style -return delete h.id,delete h["class"],delete h.style,e["new"](t,m,p,b,h,c,l)}},e.addElement=function(t){e[t]=e.createElement(t)},e.elements=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","command","content","data","datalist","dd","del","details","dfn","dialog","dir","div","dl","dt","element","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","image","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","main","map","mark","marquee","menu","menuitem","meta","meter","multicol","nav","nobr","noembed","noframes","noscript","object","ol","optgroup","option","output","p","param","picture","plaintext","pre","progress","q","rp","rt","rtc","ruby","s","samp","script","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"],e.elements.forEach(e.addElement),e.voidElements=["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],e.freeze=function(t){return e["new"](t.name,t.id,t["class"],t.attributes,t.content)},e.prototype.transform=function(t){var n=this,r=[t(e.freeze(n))],i=n.children.map(function(e){return e.transform(t)}) +return delete h.id,delete h["class"],delete h.style,e["new"](t,m,p,b,h,c,l)}},e.addElement=function(t){e[t]=e.createElement(t)},e.elements=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","command","content","data","datalist","dd","del","details","dfn","dialog","dir","div","dl","dt","element","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","image","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","main","map","mark","marquee","menu","menuitem","meta","meter","multicol","nav","nobr","noembed","noframes","noscript","object","ol","optgroup","option","output","p","param","picture","plaintext","pre","progress","q","rp","rt","rtc","ruby","s","samp","script","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"],e.elements.forEach(e.addElement),e.voidElements=["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],e.freeze=function(t){return e["new"](t.name,t.id,t["class"],t.style,t.attributes,t.content,[])},e.prototype.transform=function(t){var n=this,r=[t(e.freeze(n))],i=n.children.map(function(e){return e.transform(t)}) return r.concat(i)},e.prototype.toList=function(){var e=this return e.transform(function(e){return e})},e.prototype.traverse=function(t){var n=this,r=t(e.freeze(n)),i=n.children.map(function(e){return e.traverse(t)}) return r.children=i,r},e.prototype.render=function(){var t=this,n=Object.keys(t.attributes).reduce(function(e,n){return e+" "+s(n,t.attributes[n])},""),r=t.children.reduce(function(e,t){return e+(i(t)?o(t):t.render())},""),a=o(t.content)+r+"" diff --git a/lib/index.js b/lib/index.js index d060ad2..8253359 100644 --- a/lib/index.js +++ b/lib/index.js @@ -28,7 +28,7 @@ function Node(name, id, class_, style, attributes, content, children) { this.style = style; this.attributes = attributes; this.content = content; - this.children = children || []; + this.children = children; return this; } @@ -184,7 +184,7 @@ Node.voidElements = [ /* Provides an immutable view of a node; removing its children. */ Node.freeze = function freeze(node) { - return Node.new(node.name, node.id, node.class, node.attributes, node.content); + return Node.new(node.name, node.id, node.class, node.style, node.attributes, node.content, []); }; /* Transforms a node tree into a nested list by taking each node and applying diff --git a/package.json b/package.json index 51043f8..334663b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lmth", - "version": "1.0.0", + "version": "2.0.0", "description": "A \"type-safe\" HTML DSL for JavaScript environments.", "main": "lib/index.js", "scripts": {