From 06b5d0f2fdd733b4bd3ed00567584972e9f90b7c Mon Sep 17 00:00:00 2001 From: Kabir Shah Date: Sun, 1 Dec 2019 22:43:18 -0800 Subject: [PATCH] generate node creation functions in a loop --- packages/moon/dist/moon.js | 468 ++------------------------------- packages/moon/dist/moon.min.js | 2 +- packages/moon/src/view/m.js | 168 ++---------- 3 files changed, 39 insertions(+), 599 deletions(-) diff --git a/packages/moon/dist/moon.js b/packages/moon/dist/moon.js index b3bcbc2b..fa0a7091 100644 --- a/packages/moon/dist/moon.js +++ b/packages/moon/dist/moon.js @@ -600,461 +600,35 @@ }; } + /** + * HTML tag names + */ + + var names = ["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", "math", "menu", "menuitem", "meta", "meter", "multicol", "nav", "nextid", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "plaintext", "pre", "progress", "q", "rb", "rbc", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "svg", "table", "tbody", "td", "template", "text", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp"]; + /** + * Node creation functions. + */ + var m = { node: function node(name) { return function (data) { return new NodeNew(name, data); }; - }, - a: function a(data) { - return new NodeNew("a", data); - }, - abbr: function abbr(data) { - return new NodeNew("abbr", data); - }, - acronym: function acronym(data) { - return new NodeNew("acronym", data); - }, - address: function address(data) { - return new NodeNew("address", data); - }, - applet: function applet(data) { - return new NodeNew("applet", data); - }, - area: function area(data) { - return new NodeNew("area", data); - }, - article: function article(data) { - return new NodeNew("article", data); - }, - aside: function aside(data) { - return new NodeNew("aside", data); - }, - audio: function audio(data) { - return new NodeNew("audio", data); - }, - b: function b(data) { - return new NodeNew("b", data); - }, - base: function base(data) { - return new NodeNew("base", data); - }, - basefont: function basefont(data) { - return new NodeNew("basefont", data); - }, - bdi: function bdi(data) { - return new NodeNew("bdi", data); - }, - bdo: function bdo(data) { - return new NodeNew("bdo", data); - }, - bgsound: function bgsound(data) { - return new NodeNew("bgsound", data); - }, - big: function big(data) { - return new NodeNew("big", data); - }, - blink: function blink(data) { - return new NodeNew("blink", data); - }, - blockquote: function blockquote(data) { - return new NodeNew("blockquote", data); - }, - body: function body(data) { - return new NodeNew("body", data); - }, - br: function br(data) { - return new NodeNew("br", data); - }, - button: function button(data) { - return new NodeNew("button", data); - }, - canvas: function canvas(data) { - return new NodeNew("canvas", data); - }, - caption: function caption(data) { - return new NodeNew("caption", data); - }, - center: function center(data) { - return new NodeNew("center", data); - }, - cite: function cite(data) { - return new NodeNew("cite", data); - }, - code: function code(data) { - return new NodeNew("code", data); - }, - col: function col(data) { - return new NodeNew("col", data); - }, - colgroup: function colgroup(data) { - return new NodeNew("colgroup", data); - }, - command: function command(data) { - return new NodeNew("command", data); - }, - content: function content(data) { - return new NodeNew("content", data); - }, - data: function data(_data) { - return new NodeNew("data", _data); - }, - datalist: function datalist(data) { - return new NodeNew("datalist", data); - }, - dd: function dd(data) { - return new NodeNew("dd", data); - }, - del: function del(data) { - return new NodeNew("del", data); - }, - details: function details(data) { - return new NodeNew("details", data); - }, - dfn: function dfn(data) { - return new NodeNew("dfn", data); - }, - dialog: function dialog(data) { - return new NodeNew("dialog", data); - }, - dir: function dir(data) { - return new NodeNew("dir", data); - }, - div: function div(data) { - return new NodeNew("div", data); - }, - dl: function dl(data) { - return new NodeNew("dl", data); - }, - dt: function dt(data) { - return new NodeNew("dt", data); - }, - element: function element(data) { - return new NodeNew("element", data); - }, - em: function em(data) { - return new NodeNew("em", data); - }, - embed: function embed(data) { - return new NodeNew("embed", data); - }, - fieldset: function fieldset(data) { - return new NodeNew("fieldset", data); - }, - figcaption: function figcaption(data) { - return new NodeNew("figcaption", data); - }, - figure: function figure(data) { - return new NodeNew("figure", data); - }, - font: function font(data) { - return new NodeNew("font", data); - }, - footer: function footer(data) { - return new NodeNew("footer", data); - }, - form: function form(data) { - return new NodeNew("form", data); - }, - frame: function frame(data) { - return new NodeNew("frame", data); - }, - frameset: function frameset(data) { - return new NodeNew("frameset", data); - }, - h1: function h1(data) { - return new NodeNew("h1", data); - }, - h2: function h2(data) { - return new NodeNew("h2", data); - }, - h3: function h3(data) { - return new NodeNew("h3", data); - }, - h4: function h4(data) { - return new NodeNew("h4", data); - }, - h5: function h5(data) { - return new NodeNew("h5", data); - }, - h6: function h6(data) { - return new NodeNew("h6", data); - }, - head: function head(data) { - return new NodeNew("head", data); - }, - header: function header(data) { - return new NodeNew("header", data); - }, - hgroup: function hgroup(data) { - return new NodeNew("hgroup", data); - }, - hr: function hr(data) { - return new NodeNew("hr", data); - }, - html: function html(data) { - return new NodeNew("html", data); - }, - i: function i(data) { - return new NodeNew("i", data); - }, - iframe: function iframe(data) { - return new NodeNew("iframe", data); - }, - image: function image(data) { - return new NodeNew("image", data); - }, - img: function img(data) { - return new NodeNew("img", data); - }, - input: function input(data) { - return new NodeNew("input", data); - }, - ins: function ins(data) { - return new NodeNew("ins", data); - }, - isindex: function isindex(data) { - return new NodeNew("isindex", data); - }, - kbd: function kbd(data) { - return new NodeNew("kbd", data); - }, - keygen: function keygen(data) { - return new NodeNew("keygen", data); - }, - label: function label(data) { - return new NodeNew("label", data); - }, - legend: function legend(data) { - return new NodeNew("legend", data); - }, - li: function li(data) { - return new NodeNew("li", data); - }, - link: function link(data) { - return new NodeNew("link", data); - }, - listing: function listing(data) { - return new NodeNew("listing", data); - }, - main: function main(data) { - return new NodeNew("main", data); - }, - map: function map(data) { - return new NodeNew("map", data); - }, - mark: function mark(data) { - return new NodeNew("mark", data); - }, - marquee: function marquee(data) { - return new NodeNew("marquee", data); - }, - math: function math(data) { - return new NodeNew("math", data); - }, - menu: function menu(data) { - return new NodeNew("menu", data); - }, - menuitem: function menuitem(data) { - return new NodeNew("menuitem", data); - }, - meta: function meta(data) { - return new NodeNew("meta", data); - }, - meter: function meter(data) { - return new NodeNew("meter", data); - }, - multicol: function multicol(data) { - return new NodeNew("multicol", data); - }, - nav: function nav(data) { - return new NodeNew("nav", data); - }, - nextid: function nextid(data) { - return new NodeNew("nextid", data); - }, - nobr: function nobr(data) { - return new NodeNew("nobr", data); - }, - noembed: function noembed(data) { - return new NodeNew("noembed", data); - }, - noframes: function noframes(data) { - return new NodeNew("noframes", data); - }, - noscript: function noscript(data) { - return new NodeNew("noscript", data); - }, - object: function object(data) { - return new NodeNew("object", data); - }, - ol: function ol(data) { - return new NodeNew("ol", data); - }, - optgroup: function optgroup(data) { - return new NodeNew("optgroup", data); - }, - option: function option(data) { - return new NodeNew("option", data); - }, - output: function output(data) { - return new NodeNew("output", data); - }, - p: function p(data) { - return new NodeNew("p", data); - }, - param: function param(data) { - return new NodeNew("param", data); - }, - picture: function picture(data) { - return new NodeNew("picture", data); - }, - plaintext: function plaintext(data) { - return new NodeNew("plaintext", data); - }, - pre: function pre(data) { - return new NodeNew("pre", data); - }, - progress: function progress(data) { - return new NodeNew("progress", data); - }, - q: function q(data) { - return new NodeNew("q", data); - }, - rb: function rb(data) { - return new NodeNew("rb", data); - }, - rbc: function rbc(data) { - return new NodeNew("rbc", data); - }, - rp: function rp(data) { - return new NodeNew("rp", data); - }, - rt: function rt(data) { - return new NodeNew("rt", data); - }, - rtc: function rtc(data) { - return new NodeNew("rtc", data); - }, - ruby: function ruby(data) { - return new NodeNew("ruby", data); - }, - s: function s(data) { - return new NodeNew("s", data); - }, - samp: function samp(data) { - return new NodeNew("samp", data); - }, - script: function script(data) { - return new NodeNew("script", data); - }, - section: function section(data) { - return new NodeNew("section", data); - }, - select: function select(data) { - return new NodeNew("select", data); - }, - shadow: function shadow(data) { - return new NodeNew("shadow", data); - }, - slot: function slot(data) { - return new NodeNew("slot", data); - }, - small: function small(data) { - return new NodeNew("small", data); - }, - source: function source(data) { - return new NodeNew("source", data); - }, - spacer: function spacer(data) { - return new NodeNew("spacer", data); - }, - span: function span(data) { - return new NodeNew("span", data); - }, - strike: function strike(data) { - return new NodeNew("strike", data); - }, - strong: function strong(data) { - return new NodeNew("strong", data); - }, - style: function style(data) { - return new NodeNew("style", data); - }, - sub: function sub(data) { - return new NodeNew("sub", data); - }, - summary: function summary(data) { - return new NodeNew("summary", data); - }, - sup: function sup(data) { - return new NodeNew("sup", data); - }, - svg: function svg(data) { - return new NodeNew("svg", data); - }, - table: function table(data) { - return new NodeNew("table", data); - }, - tbody: function tbody(data) { - return new NodeNew("tbody", data); - }, - td: function td(data) { - return new NodeNew("td", data); - }, - template: function template(data) { - return new NodeNew("template", data); - }, - text: function text(data) { - return new NodeNew("text", data); - }, - textarea: function textarea(data) { - return new NodeNew("textarea", data); - }, - tfoot: function tfoot(data) { - return new NodeNew("tfoot", data); - }, - th: function th(data) { - return new NodeNew("th", data); - }, - thead: function thead(data) { - return new NodeNew("thead", data); - }, - time: function time(data) { - return new NodeNew("time", data); - }, - title: function title(data) { - return new NodeNew("title", data); - }, - tr: function tr(data) { - return new NodeNew("tr", data); - }, - track: function track(data) { - return new NodeNew("track", data); - }, - tt: function tt(data) { - return new NodeNew("tt", data); - }, - u: function u(data) { - return new NodeNew("u", data); - }, - ul: function ul(data) { - return new NodeNew("ul", data); - }, - "var": function _var(data) { - return new NodeNew("var", data); - }, - video: function video(data) { - return new NodeNew("video", data); - }, - wbr: function wbr(data) { - return new NodeNew("wbr", data); - }, - xmp: function xmp(data) { - return new NodeNew("xmp", data); } }; + var _loop = function _loop(i) { + var name = names[i]; + + m[name] = function (data) { + return new NodeNew(name, data); + }; + }; + + for (var i = 0; i < names.length; i++) { + _loop(i); + } + var view = { driver: driver$1, m: m diff --git a/packages/moon/dist/moon.min.js b/packages/moon/dist/moon.min.js index dd528220..6d7521ea 100644 --- a/packages/moon/dist/moon.min.js +++ b/packages/moon/dist/moon.min.js @@ -4,4 +4,4 @@ * Released under the MIT License * https://kbrsh.github.io/moon */ -!function(n,e){"undefined"==typeof module?n.Moon=e():module.exports=e()}(this,function(){"use strict";var e,o,n={driver:{input:function(){return e},output:function(n){e=n}}};function i(n){var e={};for(var t in o)e[t]=o[t].input();var r=n(e);for(var u in r)o[u].output(r[u])}function s(n,e,t){this.node=n,this.element=e,this.children=t}function c(n,e){this.name=n,this.data=e}var H={};function R(n,e,t){if("ariaset"===e)for(var r in t)n.setAttribute("aria-"+r,t[r]);else{var u=n[e];for(var o in t)u[o]=t[o]}}function j(n,e,t,r){for(var u in t)if(!(u in r))switch(e){case"ariaset":n.removeAttribute("aria-"+u);break;case"dataset":delete n.dataset[u];break;default:n.style[u]=""}}var a=null;function D(){}function G(n){var e,t=n.name,r=[];if("text"===t)e=document.createTextNode(n.data.value);else{e=document.createElement(t);var u=n.data;for(var o in u){var i=u[o];if(64===o.charCodeAt(0)){var c=e.MoonEvent;null===c&&(c=e.MoonEvent=new D),c[o]=i,e.addEventListener(o.slice(1),c)}else switch(o){case"ariaset":case"dataset":case"style":R(e,o,i);break;case"focus":i&&e.focus();break;case"class":e.className=i;break;case"for":e.htmlFor=i;break;case"children":for(var a=0;a data => new NodeNew(name, data), - a: data => new NodeNew("a", data), - abbr: data => new NodeNew("abbr", data), - acronym: data => new NodeNew("acronym", data), - address: data => new NodeNew("address", data), - applet: data => new NodeNew("applet", data), - area: data => new NodeNew("area", data), - article: data => new NodeNew("article", data), - aside: data => new NodeNew("aside", data), - audio: data => new NodeNew("audio", data), - b: data => new NodeNew("b", data), - base: data => new NodeNew("base", data), - basefont: data => new NodeNew("basefont", data), - bdi: data => new NodeNew("bdi", data), - bdo: data => new NodeNew("bdo", data), - bgsound: data => new NodeNew("bgsound", data), - big: data => new NodeNew("big", data), - blink: data => new NodeNew("blink", data), - blockquote: data => new NodeNew("blockquote", data), - body: data => new NodeNew("body", data), - br: data => new NodeNew("br", data), - button: data => new NodeNew("button", data), - canvas: data => new NodeNew("canvas", data), - caption: data => new NodeNew("caption", data), - center: data => new NodeNew("center", data), - cite: data => new NodeNew("cite", data), - code: data => new NodeNew("code", data), - col: data => new NodeNew("col", data), - colgroup: data => new NodeNew("colgroup", data), - command: data => new NodeNew("command", data), - content: data => new NodeNew("content", data), - data: data => new NodeNew("data", data), - datalist: data => new NodeNew("datalist", data), - dd: data => new NodeNew("dd", data), - del: data => new NodeNew("del", data), - details: data => new NodeNew("details", data), - dfn: data => new NodeNew("dfn", data), - dialog: data => new NodeNew("dialog", data), - dir: data => new NodeNew("dir", data), - div: data => new NodeNew("div", data), - dl: data => new NodeNew("dl", data), - dt: data => new NodeNew("dt", data), - element: data => new NodeNew("element", data), - em: data => new NodeNew("em", data), - embed: data => new NodeNew("embed", data), - fieldset: data => new NodeNew("fieldset", data), - figcaption: data => new NodeNew("figcaption", data), - figure: data => new NodeNew("figure", data), - font: data => new NodeNew("font", data), - footer: data => new NodeNew("footer", data), - form: data => new NodeNew("form", data), - frame: data => new NodeNew("frame", data), - frameset: data => new NodeNew("frameset", data), - h1: data => new NodeNew("h1", data), - h2: data => new NodeNew("h2", data), - h3: data => new NodeNew("h3", data), - h4: data => new NodeNew("h4", data), - h5: data => new NodeNew("h5", data), - h6: data => new NodeNew("h6", data), - head: data => new NodeNew("head", data), - header: data => new NodeNew("header", data), - hgroup: data => new NodeNew("hgroup", data), - hr: data => new NodeNew("hr", data), - html: data => new NodeNew("html", data), - i: data => new NodeNew("i", data), - iframe: data => new NodeNew("iframe", data), - image: data => new NodeNew("image", data), - img: data => new NodeNew("img", data), - input: data => new NodeNew("input", data), - ins: data => new NodeNew("ins", data), - isindex: data => new NodeNew("isindex", data), - kbd: data => new NodeNew("kbd", data), - keygen: data => new NodeNew("keygen", data), - label: data => new NodeNew("label", data), - legend: data => new NodeNew("legend", data), - li: data => new NodeNew("li", data), - link: data => new NodeNew("link", data), - listing: data => new NodeNew("listing", data), - main: data => new NodeNew("main", data), - map: data => new NodeNew("map", data), - mark: data => new NodeNew("mark", data), - marquee: data => new NodeNew("marquee", data), - math: data => new NodeNew("math", data), - menu: data => new NodeNew("menu", data), - menuitem: data => new NodeNew("menuitem", data), - meta: data => new NodeNew("meta", data), - meter: data => new NodeNew("meter", data), - multicol: data => new NodeNew("multicol", data), - nav: data => new NodeNew("nav", data), - nextid: data => new NodeNew("nextid", data), - nobr: data => new NodeNew("nobr", data), - noembed: data => new NodeNew("noembed", data), - noframes: data => new NodeNew("noframes", data), - noscript: data => new NodeNew("noscript", data), - object: data => new NodeNew("object", data), - ol: data => new NodeNew("ol", data), - optgroup: data => new NodeNew("optgroup", data), - option: data => new NodeNew("option", data), - output: data => new NodeNew("output", data), - p: data => new NodeNew("p", data), - param: data => new NodeNew("param", data), - picture: data => new NodeNew("picture", data), - plaintext: data => new NodeNew("plaintext", data), - pre: data => new NodeNew("pre", data), - progress: data => new NodeNew("progress", data), - q: data => new NodeNew("q", data), - rb: data => new NodeNew("rb", data), - rbc: data => new NodeNew("rbc", data), - rp: data => new NodeNew("rp", data), - rt: data => new NodeNew("rt", data), - rtc: data => new NodeNew("rtc", data), - ruby: data => new NodeNew("ruby", data), - s: data => new NodeNew("s", data), - samp: data => new NodeNew("samp", data), - script: data => new NodeNew("script", data), - section: data => new NodeNew("section", data), - select: data => new NodeNew("select", data), - shadow: data => new NodeNew("shadow", data), - slot: data => new NodeNew("slot", data), - small: data => new NodeNew("small", data), - source: data => new NodeNew("source", data), - spacer: data => new NodeNew("spacer", data), - span: data => new NodeNew("span", data), - strike: data => new NodeNew("strike", data), - strong: data => new NodeNew("strong", data), - style: data => new NodeNew("style", data), - sub: data => new NodeNew("sub", data), - summary: data => new NodeNew("summary", data), - sup: data => new NodeNew("sup", data), - svg: data => new NodeNew("svg", data), - table: data => new NodeNew("table", data), - tbody: data => new NodeNew("tbody", data), - td: data => new NodeNew("td", data), - template: data => new NodeNew("template", data), - text: data => new NodeNew("text", data), - textarea: data => new NodeNew("textarea", data), - tfoot: data => new NodeNew("tfoot", data), - th: data => new NodeNew("th", data), - thead: data => new NodeNew("thead", data), - time: data => new NodeNew("time", data), - title: data => new NodeNew("title", data), - tr: data => new NodeNew("tr", data), - track: data => new NodeNew("track", data), - tt: data => new NodeNew("tt", data), - u: data => new NodeNew("u", data), - ul: data => new NodeNew("ul", data), - var: data => new NodeNew("var", data), - video: data => new NodeNew("video", data), - wbr: data => new NodeNew("wbr", data), - xmp: data => new NodeNew("xmp", data) +/** + * HTML tag names + */ +const names = ["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", "math", "menu", "menuitem", "meta", "meter", "multicol", "nav", "nextid", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "plaintext", "pre", "progress", "q", "rb", "rbc", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "svg", "table", "tbody", "td", "template", "text", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp"]; + +/** + * Node creation functions. + */ +const m = { + node: name => data => new NodeNew(name, data) }; + +for (let i = 0; i < names.length; i++) { + const name = names[i]; + m[name] = data => new NodeNew(name, data); +} + +export default m;