From 32fff04f486a24d1ec232242a9917881a0039472 Mon Sep 17 00:00:00 2001 From: Vladimir Kutepov Date: Fri, 6 Nov 2020 19:58:22 +0300 Subject: [PATCH] 3.5.0 --- .eslintrc | 3 ++- CHANGELOG.md | 8 +++++- benchmark/.eslintrc | 1 + dist/hyperapp-render.js | 8 +++--- dist/hyperapp-render.js.map | 2 +- dist/hyperapp-render.min.js | 4 +-- dist/hyperapp-render.min.js.map | 2 +- package.json | 46 ++++++++++++++++----------------- src/index.js | 9 +++---- test/.eslintrc | 2 ++ test/index.test.js | 24 ++++++++++++++++- tools/build.js | 4 +-- 12 files changed, 73 insertions(+), 40 deletions(-) diff --git a/.eslintrc b/.eslintrc index 483ef4f..7a95e7a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,7 +9,8 @@ }, "settings": { "react": { - "pragma": "h" + "pragma": "h", + "version": "*" } } } diff --git a/CHANGELOG.md b/CHANGELOG.md index ac39a00..00872e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [3.5.0] - 2020-11-06 + +- Compatibility with Hyperapp [v2.0.6](https://github.com/hyperapp/hyperapp/releases/tag/2.0.6) + after internal VNode schema change. + ## [3.4.0] - 2020-05-25 - Hybrid npm package with both CommonJS and ESM versions @@ -61,7 +66,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Initial public release. -[unreleased]: https://github.com/kriasoft/hyperapp-render/compare/v3.4.0...HEAD +[unreleased]: https://github.com/kriasoft/hyperapp-render/compare/v3.5.0...HEAD +[3.5.0]: https://github.com/kriasoft/hyperapp-render/compare/v3.4.0...v3.5.0 [3.4.0]: https://github.com/kriasoft/hyperapp-render/compare/v3.3.0...v3.4.0 [3.3.0]: https://github.com/kriasoft/hyperapp-render/compare/v3.2.0...v3.3.0 [3.2.0]: https://github.com/kriasoft/hyperapp-render/compare/v3.1.0...v3.2.0 diff --git a/benchmark/.eslintrc b/benchmark/.eslintrc index d919666..90b09c5 100644 --- a/benchmark/.eslintrc +++ b/benchmark/.eslintrc @@ -9,6 +9,7 @@ "peerDependencies": false }], "react/jsx-filename-extension": "off", + "react/jsx-props-no-spreading": "off", "react/prop-types": "off" } } diff --git a/dist/hyperapp-render.js b/dist/hyperapp-render.js index 3de937b..5a5c48a 100644 --- a/dist/hyperapp-render.js +++ b/dist/hyperapp-render.js @@ -1,9 +1,9 @@ -/*! Hyperapp Render v3.4.0 | MIT Licence | https://github.com/kriasoft/hyperapp-render */ +/*! Hyperapp Render v3.5.0 | MIT Licence | https://github.com/kriasoft/hyperapp-render */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : - (global = global || self, factory(global.hyperappRender = {})); + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.hyperappRender = {})); }(this, (function (exports) { 'use strict'; var isArray = Array.isArray; @@ -231,10 +231,12 @@ children: node, footer: '' }); + } else if (node.tag === 3) { + out += escapeHtml(node.type); } else if (node.type === 3) { out += escapeHtml(node.name); } else if (typeof node === 'object') { - out += renderFragment(node.name || node.nodeName, node.props || node.attributes, node.children, stack); + out += renderFragment(node.name || node.type || node.nodeName, node.props || node.attributes, node.children, stack); } else { out += escapeHtml(node); } diff --git a/dist/hyperapp-render.js.map b/dist/hyperapp-render.js.map index 8463ead..ef2bc01 100644 --- a/dist/hyperapp-render.js.map +++ b/dist/hyperapp-render.js.map @@ -1 +1 @@ -{"version":3,"file":"hyperapp-render.js","sources":["src/index.js"],"sourcesContent":["const { isArray } = Array\nconst { hasOwnProperty } = Object.prototype\nconst styleNameCache = new Map()\nconst uppercasePattern = /[A-Z]/g\nconst msPattern = /^ms-/\n\n// https://www.w3.org/International/questions/qa-escapes#use\nconst escapeRegExp = /[\"&'<>]/\n\n// https://www.w3.org/TR/html/syntax.html#void-elements\nconst voidElements = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n])\n\n// credits to https://github.com/component/escape-html\nexport function escapeHtml(value) {\n const str = '' + value\n if (typeof value === 'number') {\n // better performance for safe values\n return str\n }\n\n const match = escapeRegExp.exec(str)\n if (!match) {\n return str\n }\n\n let { index } = match\n let lastIndex = 0\n let out = ''\n\n for (let escape = ''; index < str.length; index++) {\n switch (str.charCodeAt(index)) {\n case 34: // \"\n escape = '"'\n break\n case 38: // &\n escape = '&'\n break\n case 39: // '\n escape = ''' // shorter than \"'\" and \"'\" plus supports HTML4\n break\n case 60: // <\n escape = '<'\n break\n case 62: // >\n escape = '>'\n break\n default:\n continue\n }\n\n if (lastIndex !== index) {\n out += str.substring(lastIndex, index)\n }\n\n lastIndex = index + 1\n out += escape\n }\n\n return lastIndex !== index ? out + str.substring(lastIndex, index) : out\n}\n\n// credits to https://github.com/jorgebucaran/classcat\nexport function concatClassNames(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return value || ''\n }\n\n let out = ''\n let delimiter = ''\n\n if (isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n const name = concatClassNames(value[i])\n if (name !== '') {\n out += delimiter + name\n delimiter = ' '\n }\n }\n } else {\n for (const name in value) {\n if (hasOwnProperty.call(value, name) && value[name]) {\n out += delimiter + name\n delimiter = ' '\n }\n }\n }\n\n return out\n}\n\n// \"backgroundColor\" => \"background-color\"\n// \"MozTransition\" => \"-moz-transition\"\n// \"msTransition\" => \"-ms-transition\"\nfunction hyphenateStyleName(styleName) {\n if (!styleNameCache.has(styleName)) {\n const name = styleName\n .replace(uppercasePattern, '-$&')\n .toLowerCase()\n .replace(msPattern, '-ms-')\n\n // returns 'undefined' instead of the 'Map' object in IE11\n styleNameCache.set(styleName, name)\n }\n return styleNameCache.get(styleName)\n}\n\nexport function stringifyStyles(style) {\n let out = ''\n let delimiter = ''\n\n for (const name in style) {\n if (hasOwnProperty.call(style, name)) {\n const value = style[name]\n\n if (value != null) {\n if (name === 'cssText') {\n out += delimiter + value\n } else {\n out += delimiter + hyphenateStyleName(name) + ':' + value\n }\n delimiter = ';'\n }\n }\n }\n\n return out\n}\n\n// https://www.w3.org/TR/html51/syntax.html#serializing-html-fragments\nfunction renderFragment(name, props, children, stack) {\n let out = ''\n let footer = ''\n\n if (name) {\n out += '<' + name\n\n for (let prop in props) {\n if (hasOwnProperty.call(props, prop)) {\n let value = props[prop]\n\n if (\n value != null &&\n prop !== 'key' &&\n prop !== 'innerHTML' &&\n prop !== '__source' && // babel-plugin-transform-react-jsx-source\n !(prop[0] === 'o' && prop[1] === 'n')\n ) {\n if (prop === 'class' || prop === 'className') {\n prop = 'class'\n value = concatClassNames(value) || false\n } else if (prop === 'style' && typeof value === 'object') {\n value = stringifyStyles(value) || false\n }\n\n if (value !== false) {\n out += ' ' + prop\n\n if (value !== true) {\n out += '=\"' + escapeHtml(value) + '\"'\n }\n }\n }\n }\n }\n\n if (voidElements.has(name)) {\n out += '/>'\n } else {\n out += '>'\n footer = ''\n }\n }\n\n if (children.length > 0) {\n stack.push({\n childIndex: 0,\n children,\n footer,\n })\n } else {\n const { innerHTML } = props\n\n if (innerHTML != null) {\n out += innerHTML\n }\n\n out += footer\n }\n\n return out\n}\n\nfunction resolveNode(node, state, actions) {\n if (typeof node === 'function') {\n return resolveNode(node(state, actions), state, actions)\n }\n if (node && node.type === 2) {\n return resolveNode(node.lazy.view(node.lazy), state, actions)\n }\n return node\n}\n\nexport function renderer(view, state, actions) {\n const stack = [\n {\n childIndex: 0,\n children: [view],\n footer: '',\n },\n ]\n let end = false\n\n return (bytes) => {\n if (end) {\n return null\n }\n\n let out = ''\n\n while (out.length < bytes) {\n if (stack.length === 0) {\n end = true\n break\n }\n\n const frame = stack[stack.length - 1]\n\n if (frame.childIndex >= frame.children.length) {\n out += frame.footer\n stack.pop()\n } else {\n const node = resolveNode(frame.children[frame.childIndex++], state, actions)\n\n if (node != null && typeof node !== 'boolean') {\n if (isArray(node)) {\n stack.push({\n childIndex: 0,\n children: node,\n footer: '',\n })\n } else if (node.type === 3) {\n out += escapeHtml(node.name)\n } else if (typeof node === 'object') {\n out += renderFragment(\n node.name || node.nodeName,\n node.props || node.attributes,\n node.children,\n stack,\n )\n } else {\n out += escapeHtml(node)\n }\n }\n }\n }\n\n return out\n }\n}\n\nexport function renderToString(view, state, actions) {\n return renderer(view, state, actions)(Infinity)\n}\n"],"names":["isArray","Array","hasOwnProperty","Object","prototype","styleNameCache","Map","uppercasePattern","msPattern","escapeRegExp","voidElements","Set","escapeHtml","value","str","match","exec","index","lastIndex","out","escape","length","charCodeAt","substring","concatClassNames","delimiter","i","name","call","hyphenateStyleName","styleName","has","replace","toLowerCase","set","get","stringifyStyles","style","renderFragment","props","children","stack","footer","prop","push","childIndex","innerHTML","resolveNode","node","state","actions","type","lazy","view","renderer","end","bytes","frame","pop","nodeName","attributes","renderToString","Infinity"],"mappings":";;;;;;;;MAAQA,UAAYC,MAAZD;MACAE,iBAAmBC,MAAM,CAACC,UAA1BF;EACR,IAAMG,cAAc,GAAG,IAAIC,GAAJ,EAAvB;EACA,IAAMC,gBAAgB,GAAG,QAAzB;EACA,IAAMC,SAAS,GAAG,MAAlB;EAGA,IAAMC,YAAY,GAAG,SAArB;EAGA,IAAMC,YAAY,GAAG,IAAIC,GAAJ,CAAQ,CAC3B,MAD2B,EAE3B,MAF2B,EAG3B,IAH2B,EAI3B,KAJ2B,EAK3B,OAL2B,EAM3B,IAN2B,EAO3B,KAP2B,EAQ3B,OAR2B,EAS3B,MAT2B,EAU3B,MAV2B,EAW3B,OAX2B,EAY3B,QAZ2B,EAa3B,OAb2B,EAc3B,KAd2B,CAAR,CAArB;EAkBO,SAASC,UAAT,CAAoBC,KAApB,EAA2B;EAChC,MAAMC,GAAG,GAAG,KAAKD,KAAjB;;EACA,MAAI,OAAOA,K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CAACgD,IAAD,CAAX,EAAmB;EACjBP,YAAAA,KAAK,CAACG,IAAN,CAAW;EACTC,cAAAA,UAAU,EAAE,CADH;EAETL,cAAAA,QAAQ,EAAEQ,IAFD;EAGTN,cAAAA,MAAM,EAAE;EAHC,aAAX;EAKD,WAND,MAMO,IAAIM,IAAI,CAACG,IAAL,KAAc,CAAlB,EAAqB;EAC1BhC,YAAAA,GAAG,IAAIP,UAAU,CAACoC,IAAI,CAACrB,IAAN,CAAjB;EACD,WAFM,MAEA,IAAI,OAAOqB,IAAP,KAAgB,QAApB,EAA8B;EACnC7B,YAAAA,GAAG,IAAImB,cAAc,CACnBU,IAAI,CAACrB,IAAL,IAAaqB,IAAI,CAACW,QADC,EAEnBX,IAAI,CAACT,KAAL,IAAcS,IAAI,CAACY,UAFA,EAGnBZ,IAAI,CAACR,QAHc,EAInBC,KAJmB,CAArB;EAMD,WAPM,MAOA;EACLtB,YAAAA,GAAG,IAAIP,UAAU,CAACoC,IAAD,CAAjB;EACD;EACF;EACF;EACF;;EAED,WAAO7B,GAAP;EACD,GA7CD;EA8CD;EAEM,SAAS0C,cAAT,CAAwBR,IAAxB,EAA8BJ,KAA9B,EAAqCC,OAArC,EAA8C;EACnD,SAAOI,QAAQ,CAACD,IAAD,EAAOJ,KAAP,EAAcC,OAAd,CAAR,CAA+BY,QAA/B,CAAP;EACD;;;;;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"hyperapp-render.js","sources":["src/index.js"],"sourcesContent":["const { isArray } = Array\nconst { hasOwnProperty } = Object.prototype\nconst styleNameCache = new Map()\nconst uppercasePattern = /[A-Z]/g\nconst msPattern = /^ms-/\n\n// https://www.w3.org/International/questions/qa-escapes#use\nconst escapeRegExp = /[\"&'<>]/\n\n// https://www.w3.org/TR/html/syntax.html#void-elements\nconst voidElements = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n])\n\n// credits to https://github.com/component/escape-html\nexport function escapeHtml(value) {\n const str = '' + value\n if (typeof value === 'number') {\n // better performance for safe values\n return str\n }\n\n const match = escapeRegExp.exec(str)\n if (!match) {\n return str\n }\n\n let { index } = match\n let lastIndex = 0\n let out = ''\n\n for (let escape = ''; index < str.length; index++) {\n switch (str.charCodeAt(index)) {\n case 34: // \"\n escape = '"'\n break\n case 38: // &\n escape = '&'\n break\n case 39: // '\n escape = ''' // shorter than \"'\" and \"'\" plus supports HTML4\n break\n case 60: // <\n escape = '<'\n break\n case 62: // >\n escape = '>'\n break\n default:\n continue\n }\n\n if (lastIndex !== index) {\n out += str.substring(lastIndex, index)\n }\n\n lastIndex = index + 1\n out += escape\n }\n\n return lastIndex !== index ? out + str.substring(lastIndex, index) : out\n}\n\n// credits to https://github.com/jorgebucaran/classcat\nexport function concatClassNames(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return value || ''\n }\n\n let out = ''\n let delimiter = ''\n\n if (isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n const name = concatClassNames(value[i])\n if (name !== '') {\n out += delimiter + name\n delimiter = ' '\n }\n }\n } else {\n for (const name in value) {\n if (hasOwnProperty.call(value, name) && value[name]) {\n out += delimiter + name\n delimiter = ' '\n }\n }\n }\n\n return out\n}\n\n// \"backgroundColor\" => \"background-color\"\n// \"MozTransition\" => \"-moz-transition\"\n// \"msTransition\" => \"-ms-transition\"\nfunction hyphenateStyleName(styleName) {\n if (!styleNameCache.has(styleName)) {\n const name = styleName.replace(uppercasePattern, '-$&').toLowerCase().replace(msPattern, '-ms-')\n\n // returns 'undefined' instead of the 'Map' object in IE11\n styleNameCache.set(styleName, name)\n }\n return styleNameCache.get(styleName)\n}\n\nexport function stringifyStyles(style) {\n let out = ''\n let delimiter = ''\n\n for (const name in style) {\n if (hasOwnProperty.call(style, name)) {\n const value = style[name]\n\n if (value != null) {\n if (name === 'cssText') {\n out += delimiter + value\n } else {\n out += delimiter + hyphenateStyleName(name) + ':' + value\n }\n delimiter = ';'\n }\n }\n }\n\n return out\n}\n\n// https://www.w3.org/TR/html51/syntax.html#serializing-html-fragments\nfunction renderFragment(name, props, children, stack) {\n let out = ''\n let footer = ''\n\n if (name) {\n out += '<' + name\n\n for (let prop in props) {\n if (hasOwnProperty.call(props, prop)) {\n let value = props[prop]\n\n if (\n value != null &&\n prop !== 'key' &&\n prop !== 'innerHTML' &&\n prop !== '__source' && // babel-plugin-transform-react-jsx-source\n !(prop[0] === 'o' && prop[1] === 'n')\n ) {\n if (prop === 'class' || prop === 'className') {\n prop = 'class'\n value = concatClassNames(value) || false\n } else if (prop === 'style' && typeof value === 'object') {\n value = stringifyStyles(value) || false\n }\n\n if (value !== false) {\n out += ' ' + prop\n\n if (value !== true) {\n out += '=\"' + escapeHtml(value) + '\"'\n }\n }\n }\n }\n }\n\n if (voidElements.has(name)) {\n out += '/>'\n } else {\n out += '>'\n footer = ''\n }\n }\n\n if (children.length > 0) {\n stack.push({\n childIndex: 0,\n children,\n footer,\n })\n } else {\n const { innerHTML } = props\n\n if (innerHTML != null) {\n out += innerHTML\n }\n\n out += footer\n }\n\n return out\n}\n\nfunction resolveNode(node, state, actions) {\n if (typeof node === 'function') {\n return resolveNode(node(state, actions), state, actions)\n }\n if (node && node.type === 2) {\n return resolveNode(node.lazy.view(node.lazy), state, actions)\n }\n return node\n}\n\nexport function renderer(view, state, actions) {\n const stack = [\n {\n childIndex: 0,\n children: [view],\n footer: '',\n },\n ]\n let end = false\n\n return (bytes) => {\n if (end) {\n return null\n }\n\n let out = ''\n\n while (out.length < bytes) {\n if (stack.length === 0) {\n end = true\n break\n }\n\n const frame = stack[stack.length - 1]\n\n if (frame.childIndex >= frame.children.length) {\n out += frame.footer\n stack.pop()\n } else {\n const node = resolveNode(frame.children[frame.childIndex++], state, actions)\n\n if (node != null && typeof node !== 'boolean') {\n if (isArray(node)) {\n stack.push({\n childIndex: 0,\n children: node,\n footer: '',\n })\n } else if (node.tag === 3) {\n out += escapeHtml(node.type)\n } else if (node.type === 3) {\n out += escapeHtml(node.name)\n } else if (typeof node === 'object') {\n out += renderFragment(\n node.name || node.type || node.nodeName,\n node.props || node.attributes,\n node.children,\n stack,\n )\n } else {\n out += escapeHtml(node)\n }\n }\n }\n }\n\n return out\n }\n}\n\nexport function renderToString(view, state, actions) {\n return renderer(view, state, actions)(Infinity)\n}\n"],"names":["isArray","Array","hasOwnProperty","Object","prototype","styleNameCache","Map","uppercasePattern","msPattern","escapeRegExp","voidElements","Set","escapeHtml","value","str","match","exec","index","lastIndex","out","escape","length","charCodeAt","substring","concatClassNames","delimiter","i","name","call","hyphenateStyleName","styleName","has","replace","toLowerCase","set","get","stringifyStyles","style","renderFragment","props","children","stack","footer","prop","push","childIndex","innerHTML","resolveNode","node","state","actions","type","lazy","view","renderer","end","bytes","frame","pop","tag","nodeName","attributes","renderToString","Infinity"],"mappings":";;;;;;;;MAAQA,UAAYC,MAAZD;MACAE,iBAAmBC,MAAM,CAACC,UAA1BF;EACR,IAAMG,cAAc,GAAG,IAAIC,GAAJ,EAAvB;EACA,IAAMC,gBAAgB,GAAG,QAAzB;EACA,IAAMC,SAAS,GAAG,MAAlB;EAGA,IAAMC,YAAY,GAAG,SAArB;EAGA,IAAMC,YAAY,GAAG,IAAIC,GAAJ,CAAQ,CAC3B,MAD2B,EAE3B,MAF2B,EAG3B,IAH2B,EAI3B,KAJ2B,EAK3B,OAL2B,EAM3B,IAN2B,EAO3B,KAP2B,EAQ3B,OAR2B,EAS3B,MAT2B,EAU3B,MAV2B,EAW3B,OAX2B,EAY3B,QAZ2B,EAa3B,OAb2B,EAc3B,KAd2B,CAAR,CAArB;EAkBO,SAASC,UAAT,CAAoBC,KAApB,EAA2B;EAChC,MAAMC,GAAG,GAAG,KAAKD,KAAjB;;EACA,MAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;EAE7B,WAAOC,GAAP;EACD;;EAED,MAAMC,KAAK,GAAGN,YAAY,CAACO,IAAb,CAAkBF,GAAl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;EAETL,cAAAA,QAAQ,EAAEQ,IAFD;EAGTN,cAAAA,MAAM,EAAE;EAHC,aAAX;EAKD,WAND,MAMO,IAAIM,IAAI,CAACW,GAAL,KAAa,CAAjB,EAAoB;EACzBxC,YAAAA,GAAG,IAAIP,UAAU,CAACoC,IAAI,CAACG,IAAN,CAAjB;EACD,WAFM,MAEA,IAAIH,IAAI,CAACG,IAAL,KAAc,CAAlB,EAAqB;EAC1BhC,YAAAA,GAAG,IAAIP,UAAU,CAACoC,IAAI,CAACrB,IAAN,CAAjB;EACD,WAFM,MAEA,IAAI,OAAOqB,IAAP,KAAgB,QAApB,EAA8B;EACnC7B,YAAAA,GAAG,IAAImB,cAAc,CACnBU,IAAI,CAACrB,IAAL,IAAaqB,IAAI,CAACG,IAAlB,IAA0BH,IAAI,CAACY,QADZ,EAEnBZ,IAAI,CAACT,KAAL,IAAcS,IAAI,CAACa,UAFA,EAGnBb,IAAI,CAACR,QAHc,EAInBC,KAJmB,CAArB;EAMD,WAPM,MAOA;EACLtB,YAAAA,GAAG,IAAIP,UAAU,CAACoC,IAAD,CAAjB;EACD;EACF;EACF;EACF;;EAED,WAAO7B,GAAP;EACD,GA/CD;EAgDD;EAEM,SAAS2C,cAAT,CAAwBT,IAAxB,EAA8BJ,KAA9B,EAAqCC,OAArC,EAA8C;EACnD,SAAOI,QAAQ,CAACD,IAAD,EAAOJ,KAAP,EAAcC,OAAd,CAAR,CAA+Ba,QAA/B,CAAP;EACD;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/hyperapp-render.min.js b/dist/hyperapp-render.min.js index 1c1fe87..6249e47 100644 --- a/dist/hyperapp-render.min.js +++ b/dist/hyperapp-render.min.js @@ -1,3 +1,3 @@ -/*! Hyperapp Render v3.4.0 | MIT Licence | https://github.com/kriasoft/hyperapp-render */ -!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).hyperappRender={})}(this,function(e){"use strict";var u=Array.isArray,f=Object.prototype.hasOwnProperty,l=new Map,c=/[A-Z]/g,s=/^ms-/,p=/["&'<>]/,d=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function h(e){var r=""+e;if("number"==typeof e)return r;var n=p.exec(r);if(!n)return r;for(var t=n.index,o=0,a="",i="";t":(i+=">",l="")}return 0=t.children.length?(r+=t.footer,i.pop()):null!=(n=function e(r,n,t){return"function"==typeof r?e(r(n,t),n,t):r&&2===r.type?e(r.lazy.view(r.lazy),n,t):r}(t.children[t.childIndex++],o,a))&&"boolean"!=typeof n&&(u(n)?i.push({childIndex:0,children:n,footer:""}):3===n.type?r+=h(n.name):r+="object"==typeof n?b(n.name||n.nodeName,n.props||n.attributes,n.children,i):h(n))}return r}}e.renderToString=function(e,r,n){return t(e,r,n)(1/0)},Object.defineProperty(e,"__esModule",{value:!0})}); +/*! Hyperapp Render v3.5.0 | MIT Licence | https://github.com/kriasoft/hyperapp-render */ +!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).hyperappRender={})}(this,(function(e){"use strict";var r=Array.isArray,n=Object.prototype.hasOwnProperty,t=new Map,a=/[A-Z]/g,o=/^ms-/,i=/["&'<>]/,l=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function f(e){var r=""+e;if("number"==typeof e)return r;var n=i.exec(r);if(!n)return r;for(var t=n.index,a=0,o="",l="";t":(o+=">",i="")}if(t.length>0)a.push({childIndex:0,children:t,footer:i});else{var d=r.innerHTML;null!=d&&(o+=d),o+=i}return o}function d(e,r,n){return"function"==typeof e?d(e(r,n),r,n):e&&2===e.type?d(e.lazy.view(e.lazy),r,n):e}e.renderToString=function(e,n,t){return function(e,n,t){var a=[{childIndex:0,children:[e],footer:""}],o=!1;return function(e){if(o)return null;for(var i="";i.length=l.children.length)i+=l.footer,a.pop();else{var c=d(l.children[l.childIndex++],n,t);null!=c&&"boolean"!=typeof c&&(r(c)?a.push({childIndex:0,children:c,footer:""}):3===c.tag?i+=f(c.type):3===c.type?i+=f(c.name):i+="object"==typeof c?p(c.name||c.type||c.nodeName,c.props||c.attributes,c.children,a):f(c))}}return i}}(e,n,t)(1/0)},Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=hyperapp-render.min.js.map diff --git a/dist/hyperapp-render.min.js.map b/dist/hyperapp-render.min.js.map index b5787c6..181e8f3 100644 --- a/dist/hyperapp-render.min.js.map +++ b/dist/hyperapp-render.min.js.map @@ -1 +1 @@ -{"version":3,"file":"hyperapp-render.min.js","sources":["src/index.js"],"sourcesContent":["const { isArray } = Array\nconst { hasOwnProperty } = Object.prototype\nconst styleNameCache = new Map()\nconst uppercasePattern = /[A-Z]/g\nconst msPattern = /^ms-/\n\n// https://www.w3.org/International/questions/qa-escapes#use\nconst escapeRegExp = /[\"&'<>]/\n\n// https://www.w3.org/TR/html/syntax.html#void-elements\nconst voidElements = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n])\n\n// credits to https://github.com/component/escape-html\nexport function escapeHtml(value) {\n const str = '' + value\n if (typeof value === 'number') {\n // better performance for safe values\n return str\n }\n\n const match = escapeRegExp.exec(str)\n if (!match) {\n return str\n }\n\n let { index } = match\n let lastIndex = 0\n let out = ''\n\n for (let escape = ''; index < str.length; index++) {\n switch (str.charCodeAt(index)) {\n case 34: // \"\n escape = '"'\n break\n case 38: // &\n escape = '&'\n break\n case 39: // '\n escape = ''' // shorter than \"'\" and \"'\" plus supports HTML4\n break\n case 60: // <\n escape = '<'\n break\n case 62: // >\n escape = '>'\n break\n default:\n continue\n }\n\n if (lastIndex !== index) {\n out += str.substring(lastIndex, index)\n }\n\n lastIndex = index + 1\n out += escape\n }\n\n return lastIndex !== index ? out + str.substring(lastIndex, index) : out\n}\n\n// credits to https://github.com/jorgebucaran/classcat\nexport function concatClassNames(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return value || ''\n }\n\n let out = ''\n let delimiter = ''\n\n if (isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n const name = concatClassNames(value[i])\n if (name !== '') {\n out += delimiter + name\n delimiter = ' '\n }\n }\n } else {\n for (const name in value) {\n if (hasOwnProperty.call(value, name) && value[name]) {\n out += delimiter + name\n delimiter = ' '\n }\n }\n }\n\n return out\n}\n\n// \"backgroundColor\" => \"background-color\"\n// \"MozTransition\" => \"-moz-transition\"\n// \"msTransition\" => \"-ms-transition\"\nfunction hyphenateStyleName(styleName) {\n if (!styleNameCache.has(styleName)) {\n const name = styleName\n .replace(uppercasePattern, '-$&')\n .toLowerCase()\n .replace(msPattern, '-ms-')\n\n // returns 'undefined' instead of the 'Map' object in IE11\n styleNameCache.set(styleName, name)\n }\n return styleNameCache.get(styleName)\n}\n\nexport function stringifyStyles(style) {\n let out = ''\n let delimiter = ''\n\n for (const name in style) {\n if (hasOwnProperty.call(style, name)) {\n const value = style[name]\n\n if (value != null) {\n if (name === 'cssText') {\n out += delimiter + value\n } else {\n out += delimiter + hyphenateStyleName(name) + ':' + value\n }\n delimiter = ';'\n }\n }\n }\n\n return out\n}\n\n// https://www.w3.org/TR/html51/syntax.html#serializing-html-fragments\nfunction renderFragment(name, props, children, stack) {\n let out = ''\n let footer = ''\n\n if (name) {\n out += '<' + name\n\n for (let prop in props) {\n if (hasOwnProperty.call(props, prop)) {\n let value = props[prop]\n\n if (\n value != null &&\n prop !== 'key' &&\n prop !== 'innerHTML' &&\n prop !== '__source' && // babel-plugin-transform-react-jsx-source\n !(prop[0] === 'o' && prop[1] === 'n')\n ) {\n if (prop === 'class' || prop === 'className') {\n prop = 'class'\n value = concatClassNames(value) || false\n } else if (prop === 'style' && typeof value === 'object') {\n value = stringifyStyles(value) || false\n }\n\n if (value !== false) {\n out += ' ' + prop\n\n if (value !== true) {\n out += '=\"' + escapeHtml(value) + '\"'\n }\n }\n }\n }\n }\n\n if (voidElements.has(name)) {\n out += '/>'\n } else {\n out += '>'\n footer = ''\n }\n }\n\n if (children.length > 0) {\n stack.push({\n childIndex: 0,\n children,\n footer,\n })\n } else {\n const { innerHTML } = props\n\n if (innerHTML != null) {\n out += innerHTML\n }\n\n out += footer\n }\n\n return out\n}\n\nfunction resolveNode(node, state, actions) {\n if (typeof node === 'function') {\n return resolveNode(node(state, actions), state, actions)\n }\n if (node && node.type === 2) {\n return resolveNode(node.lazy.view(node.lazy), state, actions)\n }\n return node\n}\n\nexport function renderer(view, state, actions) {\n const stack = [\n {\n childIndex: 0,\n children: [view],\n footer: '',\n },\n ]\n let end = false\n\n return (bytes) => {\n if (end) {\n return null\n }\n\n let out = ''\n\n while (out.length < bytes) {\n if (stack.length === 0) {\n end = true\n break\n }\n\n const frame = stack[stack.length - 1]\n\n if (frame.childIndex >= frame.children.length) {\n out += frame.footer\n stack.pop()\n } else {\n const node = resolveNode(frame.children[frame.childIndex++], state, actions)\n\n if (node != null && typeof node !== 'boolean') {\n if (isArray(node)) {\n stack.push({\n childIndex: 0,\n children: node,\n footer: '',\n })\n } else if (node.type === 3) {\n out += escapeHtml(node.name)\n } else if (typeof node === 'object') {\n out += renderFragment(\n node.name || node.nodeName,\n node.props || node.attributes,\n node.children,\n stack,\n )\n } else {\n out += escapeHtml(node)\n }\n }\n }\n }\n\n return out\n }\n}\n\nexport function renderToString(view, state, actions) {\n return renderer(view, state, actions)(Infinity)\n}\n"],"names":["isArray","Array","hasOwnProperty","Object","prototype","styleNameCache","Map","uppercasePattern","msPattern","escapeRegExp","voidElements","Set","escapeHtml","value","str","match","exec","index","lastIndex","out","escape","length","charCodeAt","substring","stringifyStyles","style","styleName","name","delimiter","call","has","replace","toLowerCase","set","get","renderFragment","props","children","stack","innerHTML","footer","prop","concatClassNames","i","push","childIndex","renderer","view","state","actions","end","bytes","node","frame","pop","resolveNode","type","lazy","nodeName","attributes","Infinity"],"mappings":";+MAA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B,SAAShB,QACrCF,GAAOkC,EAAMb,OACbF,EAAMgB,OAIM,OAFNF,EAvCd,SAASG,EAAYH,EAAMJ,EAAOC,SACZ,mBAATG,EACFG,EAAYH,EAAKJ,EAAOC,GAAUD,EAAOC,GAE9CG,GAAsB,IAAdA,EAAKI,KACRD,EAAYH,EAAKK,KAAKV,KAAKK,EAAKK,MAAOT,EAAOC,GAEhDG,EAgCYG,CAAYF,EAAMhB,SAASgB,EAAMR,cAAeG,EAAOC,KAEhC,kBAATG,IACrBpD,EAAQoD,GACVd,EAAMM,KAAK,CACTC,WAAY,EACZR,SAAUe,EACVZ,OAAQ,KAEa,IAAdY,EAAKI,KACdrC,GAAOP,EAAWwC,EAAKzB,MAEvBR,GADyB,iBAATiC,EACTjB,EACLiB,EAAKzB,MAAQyB,EAAKM,SAClBN,EAAKhB,OAASgB,EAAKO,WACnBP,EAAKf,SACLC,GAGK1B,EAAWwC,WAMnBjC,oBAIJ,SAAwB4B,EAAMC,EAAOC,UACnCH,EAASC,EAAMC,EAAOC,EAAtBH,CAA+Bc,EAAAA"} \ No newline at end of file +{"version":3,"file":"hyperapp-render.min.js","sources":["src/index.js"],"sourcesContent":["const { isArray } = Array\nconst { hasOwnProperty } = Object.prototype\nconst styleNameCache = new Map()\nconst uppercasePattern = /[A-Z]/g\nconst msPattern = /^ms-/\n\n// https://www.w3.org/International/questions/qa-escapes#use\nconst escapeRegExp = /[\"&'<>]/\n\n// https://www.w3.org/TR/html/syntax.html#void-elements\nconst voidElements = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n])\n\n// credits to https://github.com/component/escape-html\nexport function escapeHtml(value) {\n const str = '' + value\n if (typeof value === 'number') {\n // better performance for safe values\n return str\n }\n\n const match = escapeRegExp.exec(str)\n if (!match) {\n return str\n }\n\n let { index } = match\n let lastIndex = 0\n let out = ''\n\n for (let escape = ''; index < str.length; index++) {\n switch (str.charCodeAt(index)) {\n case 34: // \"\n escape = '"'\n break\n case 38: // &\n escape = '&'\n break\n case 39: // '\n escape = ''' // shorter than \"'\" and \"'\" plus supports HTML4\n break\n case 60: // <\n escape = '<'\n break\n case 62: // >\n escape = '>'\n break\n default:\n continue\n }\n\n if (lastIndex !== index) {\n out += str.substring(lastIndex, index)\n }\n\n lastIndex = index + 1\n out += escape\n }\n\n return lastIndex !== index ? out + str.substring(lastIndex, index) : out\n}\n\n// credits to https://github.com/jorgebucaran/classcat\nexport function concatClassNames(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return value || ''\n }\n\n let out = ''\n let delimiter = ''\n\n if (isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n const name = concatClassNames(value[i])\n if (name !== '') {\n out += delimiter + name\n delimiter = ' '\n }\n }\n } else {\n for (const name in value) {\n if (hasOwnProperty.call(value, name) && value[name]) {\n out += delimiter + name\n delimiter = ' '\n }\n }\n }\n\n return out\n}\n\n// \"backgroundColor\" => \"background-color\"\n// \"MozTransition\" => \"-moz-transition\"\n// \"msTransition\" => \"-ms-transition\"\nfunction hyphenateStyleName(styleName) {\n if (!styleNameCache.has(styleName)) {\n const name = styleName.replace(uppercasePattern, '-$&').toLowerCase().replace(msPattern, '-ms-')\n\n // returns 'undefined' instead of the 'Map' object in IE11\n styleNameCache.set(styleName, name)\n }\n return styleNameCache.get(styleName)\n}\n\nexport function stringifyStyles(style) {\n let out = ''\n let delimiter = ''\n\n for (const name in style) {\n if (hasOwnProperty.call(style, name)) {\n const value = style[name]\n\n if (value != null) {\n if (name === 'cssText') {\n out += delimiter + value\n } else {\n out += delimiter + hyphenateStyleName(name) + ':' + value\n }\n delimiter = ';'\n }\n }\n }\n\n return out\n}\n\n// https://www.w3.org/TR/html51/syntax.html#serializing-html-fragments\nfunction renderFragment(name, props, children, stack) {\n let out = ''\n let footer = ''\n\n if (name) {\n out += '<' + name\n\n for (let prop in props) {\n if (hasOwnProperty.call(props, prop)) {\n let value = props[prop]\n\n if (\n value != null &&\n prop !== 'key' &&\n prop !== 'innerHTML' &&\n prop !== '__source' && // babel-plugin-transform-react-jsx-source\n !(prop[0] === 'o' && prop[1] === 'n')\n ) {\n if (prop === 'class' || prop === 'className') {\n prop = 'class'\n value = concatClassNames(value) || false\n } else if (prop === 'style' && typeof value === 'object') {\n value = stringifyStyles(value) || false\n }\n\n if (value !== false) {\n out += ' ' + prop\n\n if (value !== true) {\n out += '=\"' + escapeHtml(value) + '\"'\n }\n }\n }\n }\n }\n\n if (voidElements.has(name)) {\n out += '/>'\n } else {\n out += '>'\n footer = ''\n }\n }\n\n if (children.length > 0) {\n stack.push({\n childIndex: 0,\n children,\n footer,\n })\n } else {\n const { innerHTML } = props\n\n if (innerHTML != null) {\n out += innerHTML\n }\n\n out += footer\n }\n\n return out\n}\n\nfunction resolveNode(node, state, actions) {\n if (typeof node === 'function') {\n return resolveNode(node(state, actions), state, actions)\n }\n if (node && node.type === 2) {\n return resolveNode(node.lazy.view(node.lazy), state, actions)\n }\n return node\n}\n\nexport function renderer(view, state, actions) {\n const stack = [\n {\n childIndex: 0,\n children: [view],\n footer: '',\n },\n ]\n let end = false\n\n return (bytes) => {\n if (end) {\n return null\n }\n\n let out = ''\n\n while (out.length < bytes) {\n if (stack.length === 0) {\n end = true\n break\n }\n\n const frame = stack[stack.length - 1]\n\n if (frame.childIndex >= frame.children.length) {\n out += frame.footer\n stack.pop()\n } else {\n const node = resolveNode(frame.children[frame.childIndex++], state, actions)\n\n if (node != null && typeof node !== 'boolean') {\n if (isArray(node)) {\n stack.push({\n childIndex: 0,\n children: node,\n footer: '',\n })\n } else if (node.tag === 3) {\n out += escapeHtml(node.type)\n } else if (node.type === 3) {\n out += escapeHtml(node.name)\n } else if (typeof node === 'object') {\n out += renderFragment(\n node.name || node.type || node.nodeName,\n node.props || node.attributes,\n node.children,\n stack,\n )\n } else {\n out += escapeHtml(node)\n }\n }\n }\n }\n\n return out\n }\n}\n\nexport function renderToString(view, state, actions) {\n return renderer(view, state, actions)(Infinity)\n}\n"],"names":["isArray","Array","hasOwnProperty","Object","prototype","styleNameCache","Map","uppercasePattern","msPattern","escapeRegExp","voidElements","Set","escapeHtml","value","str","match","exec","index","lastIndex","out","escape","length","charCodeAt","substring","concatClassNames","delimiter","i","name","call","hyphenateStyleName","styleName","has","replace","toLowerCase","set","get","stringifyStyles","style","renderFragment","props","children","stack","footer","prop","push","childIndex","innerHTML","resolveNode","node","state","actions","type","lazy","view","end","bytes","frame","pop","tag","nodeName","attributes","renderer","Infinity"],"mappings":";0PAAQA,EAAYC,MAAZD,QACAE,EAAmBC,OAAOC,UAA1BF,eACFG,EAAiB,IAAIC,IACrBC,EAAmB,SACnBC,EAAY,OAGZC,EAAe,UAGfC,EAAe,IAAIC,IAAI,CAC3B,OACA,OACA,KACA,MACA,QACA,KACA,MACA,QACA,OACA,OACA,QACA,SACA,QACA,QAIK,SAASC,EAAWC,OACnBC,EAAM,GAAKD,KACI,iBAAVA,SAEFC,MAGHC,EAAQN,EAAaO,KAAKF,OAC3BC,SACID,UAGHG,EAAUF,EAAVE,MACFC,EAAY,EACZC,EAAM,GAEDC,EAAS,GAAIH,EAAQH,EAAIO,OAAQJ,IAAS,QACzCH,EAAIQ,WAAWL,SAChB,GACHG,EAAS,oBAEN,GACHA,EAAS,mBAEN,GACHA,EAAS,mBAEN,GACHA,EAAS,kBAEN,GACHA,EAAS,8BAMTF,IAAcD,IAChBE,GAAOL,EAAIS,UAAUL,EAAWD,IAGlCC,EAAYD,EAAQ,EACpBE,GAAOC,SAGFF,IAAcD,EAAQE,EAAML,EAAIS,UAAUL,EAAWD,GAASE,EAIhE,SAASK,EAAiBX,MACV,iBAAVA,GAAuC,iBAAVA,SAC/BA,GAAS,OAGdM,EAAM,GACNM,EAAY,MAEZzB,EAAQa,OACL,IAAIa,EAAI,EAAGA,EAAIb,EAAMQ,OAAQK,IAAK,KAC/BC,EAAOH,EAAiBX,EAAMa,IACvB,KAATC,IACF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ACF3B,GAAO2B,GAGT3B,GAAOuB,SAGFvB,EAGT,SAAS4B,EAAYC,EAAMC,EAAOC,SACZ,mBAATF,EACFD,EAAYC,EAAKC,EAAOC,GAAUD,EAAOC,GAE9CF,GAAsB,IAAdA,EAAKG,KACRJ,EAAYC,EAAKI,KAAKC,KAAKL,EAAKI,MAAOH,EAAOC,GAEhDF,mBA+DF,SAAwBK,EAAMJ,EAAOC,UA5DrC,SAAkBG,EAAMJ,EAAOC,OAC9BT,EAAQ,CACZ,CACEI,WAAY,EACZL,SAAU,CAACa,GACXX,OAAQ,KAGRY,GAAM,SAEH,SAACC,MACFD,SACK,aAGLnC,EAAM,GAEHA,EAAIE,OAASkC,GAAO,IACJ,IAAjBd,EAAMpB,OAAc,CACtBiC,GAAM,YAIFE,EAAQf,EAAMA,EAAMpB,OAAS,MAE/BmC,EAAMX,YAAcW,EAAMhB,SAASnB,OACrCF,GAAOqC,EAAMd,OACbD,EAAMgB,UACD,KACCT,EAAOD,EAAYS,EAAMhB,SAASgB,EAAMX,cAAeI,EAAOC,GAExD,MAARF,GAAgC,kBAATA,IACrBhD,EAAQgD,GACVP,EAAMG,KAAK,CACTC,WAAY,EACZL,SAAUQ,EACVN,OAAQ,KAEY,IAAbM,EAAKU,IACdvC,GAAOP,EAAWoC,EAAKG,MACA,IAAdH,EAAKG,KACdhC,GAAOP,EAAWoC,EAAKrB,MAEvBR,GADyB,iBAAT6B,EACTV,EACLU,EAAKrB,MAAQqB,EAAKG,MAAQH,EAAKW,SAC/BX,EAAKT,OAASS,EAAKY,WACnBZ,EAAKR,SACLC,GAGK7B,EAAWoC,YAMnB7B,GAKF0C,CAASR,EAAMJ,EAAOC,EAAtBW,CAA+BC,EAAAA"} \ No newline at end of file diff --git a/package.json b/package.json index c593b1b..f63164e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "hyperapp-render", - "version": "3.4.0", + "version": "3.5.0", "description": "Render Hyperapp to an HTML string with SSR and Node.js streaming support", "repository": "kriasoft/hyperapp-render", "author": "Vladimir Kutepov", @@ -40,29 +40,29 @@ "@types/node": "*" }, "devDependencies": { - "@babel/core": "^7.3.4", - "@babel/plugin-transform-react-jsx": "^7.3.0", - "@babel/preset-env": "^7.3.4", - "@babel/register": "^7.0.0", - "babel-jest": "^24.5.0", + "@babel/core": "^7.12.3", + "@babel/plugin-transform-react-jsx": "^7.12.5", + "@babel/preset-env": "^7.12.1", + "@babel/register": "^7.12.1", + "babel-jest": "^26.6.3", "benchr": "^4.3.0", - "eslint": "^5.15.2", - "eslint-config-airbnb": "^17.1.0", - "eslint-config-prettier": "^4.1.0", - "eslint-plugin-import": "^2.16.0", - "eslint-plugin-jsx-a11y": "^6.2.1", - "eslint-plugin-react": "^7.12.4", - "fs-extra": "^7.0.1", - "husky": "^1.3.1", - "hyperapp": "^1.2.9", - "jest": "^24.5.0", - "prettier": "^1.16.4", - "rollup": "^1.6.0", - "rollup-plugin-babel": "^4.3.2", - "rollup-plugin-commonjs": "^9.2.1", - "rollup-plugin-node-resolve": "^4.0.1", - "rollup-plugin-uglify": "^6.0.2", - "typescript": "^3.3.3333" + "eslint": "^7.12.1", + "eslint-config-airbnb": "^18.2.0", + "eslint-config-prettier": "^6.15.0", + "eslint-plugin-import": "^2.22.1", + "eslint-plugin-jsx-a11y": "^6.4.1", + "eslint-plugin-react": "^7.21.5", + "fs-extra": "^9.0.1", + "husky": "^4.3.0", + "hyperapp": "^1.2.10", + "jest": "^26.6.3", + "prettier": "^2.1.2", + "rollup": "^2.33.1", + "rollup-plugin-babel": "^4.4.0", + "rollup-plugin-commonjs": "^10.1.0", + "rollup-plugin-node-resolve": "^5.2.0", + "rollup-plugin-terser": "^7.0.2", + "typescript": "^4.0.5" }, "scripts": { "lint": "node tools/lint.js", diff --git a/src/index.js b/src/index.js index 6fa88d6..8660c83 100644 --- a/src/index.js +++ b/src/index.js @@ -108,10 +108,7 @@ export function concatClassNames(value) { // "msTransition" => "-ms-transition" function hyphenateStyleName(styleName) { if (!styleNameCache.has(styleName)) { - const name = styleName - .replace(uppercasePattern, '-$&') - .toLowerCase() - .replace(msPattern, '-ms-') + const name = styleName.replace(uppercasePattern, '-$&').toLowerCase().replace(msPattern, '-ms-') // returns 'undefined' instead of the 'Map' object in IE11 styleNameCache.set(styleName, name) @@ -253,11 +250,13 @@ export function renderer(view, state, actions) { children: node, footer: '', }) + } else if (node.tag === 3) { + out += escapeHtml(node.type) } else if (node.type === 3) { out += escapeHtml(node.name) } else if (typeof node === 'object') { out += renderFragment( - node.name || node.nodeName, + node.name || node.type || node.nodeName, node.props || node.attributes, node.children, stack, diff --git a/test/.eslintrc b/test/.eslintrc index 9780020..ca440fc 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -9,8 +9,10 @@ }], "jsx-a11y/accessible-emoji": "off", "jsx-a11y/alt-text": "off", + "jsx-a11y/control-has-associated-label": "off", "react/jsx-curly-brace-presence": "off", "react/jsx-filename-extension": "off", + "react/jsx-props-no-spreading": "off", "react/no-unknown-property": "off", "react/prop-types": "off", "react/style-prop-object": "off" diff --git a/test/index.test.js b/test/index.test.js index b481d81..3abbd6a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -449,7 +449,7 @@ describe('renderToString(view, state, actions)', () => { expect(html).toBe('') }) - it('should support Hyperapp V2', () => { + it('should support Hyperapp v2.0.0', () => { const VNode = { name: 'div', props: {}, @@ -471,6 +471,28 @@ describe('renderToString(view, state, actions)', () => { expect(html).toBe('
foo bar baz
') }) + it('should support Hyperapp v2.0.6', () => { + const VNode = { + type: 'div', + props: {}, + children: [ + { + type: 'foo bar baz', + props: {}, + children: [], + node: null, + key: null, + tag: 3, + }, + ], + node: null, + key: null, + tag: 1, + } + const html = renderToString(VNode) + expect(html).toBe('
foo bar baz
') + }) + it('should support Hyperapp V2 lazy nodes', () => { const VNode = { lazy: { diff --git a/tools/build.js b/tools/build.js index 1749424..ea2296c 100644 --- a/tools/build.js +++ b/tools/build.js @@ -1,7 +1,7 @@ const fs = require('fs-extra') const rollup = require('rollup') const babel = require('rollup-plugin-babel') -const { uglify } = require('rollup-plugin-uglify') +const { terser } = require('rollup-plugin-terser') const pkg = require('../package.json') // The source files to be compiled by Rollup @@ -72,7 +72,7 @@ async function build() { ], comments: false, }), - ...(file.output.endsWith('.min.js') ? [uglify({ output: { comments: '/^!/' } })] : []), + ...(file.output.endsWith('.min.js') ? [terser({ output: { comments: '/^!/' } })] : []), ], })