From 899d429c4823cd29332998827d65f46fd4560510 Mon Sep 17 00:00:00 2001 From: Gianluca Guarini Date: Sat, 14 Sep 2024 00:42:33 +0200 Subject: [PATCH] updated: fix benchmarks --- benchmarks/bundle.js | 3277 ++++++++++++++++++ benchmarks/{events.cjs => events.js} | 43 +- benchmarks/{if.cjs => if.js} | 32 +- benchmarks/index.cjs | 33 - benchmarks/index.html | 13 + benchmarks/index.js | 45 + benchmarks/{keyed.list.cjs => keyed.list.js} | 38 +- benchmarks/{list.cjs => list.js} | 36 +- benchmarks/mount.cjs | 37 - benchmarks/mount.js | 41 + benchmarks/old-version.cjs | 1769 ---------- benchmarks/old-version.js | 1321 +++++++ benchmarks/rollup.config.js | 21 + package.json | 3 +- polyfills/range.cjs | 22 - 15 files changed, 4802 insertions(+), 1929 deletions(-) create mode 100644 benchmarks/bundle.js rename benchmarks/{events.cjs => events.js} (73%) rename benchmarks/{if.cjs => if.js} (58%) delete mode 100644 benchmarks/index.cjs create mode 100644 benchmarks/index.html create mode 100644 benchmarks/index.js rename benchmarks/{keyed.list.cjs => keyed.list.js} (70%) rename benchmarks/{list.cjs => list.js} (69%) delete mode 100644 benchmarks/mount.cjs create mode 100644 benchmarks/mount.js delete mode 100644 benchmarks/old-version.cjs create mode 100644 benchmarks/old-version.js create mode 100644 benchmarks/rollup.config.js delete mode 100644 polyfills/range.cjs diff --git a/benchmarks/bundle.js b/benchmarks/bundle.js new file mode 100644 index 0000000..a2eb646 --- /dev/null +++ b/benchmarks/bundle.js @@ -0,0 +1,3277 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jsdom-global'), require('benchmark')) : + typeof define === 'function' && define.amd ? define(['jsdom-global', 'benchmark'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jsdomGlobal, global.Benchmark)); +})(this, (function (jsdomGlobal, Benchmark) { 'use strict'; + + /** + * Convert a string from camel case to dash-case + * @param {string} string - probably a component tag name + * @returns {string} component name normalized + */ + + /** + * Convert a string containing dashes to camel case + * @param {string} string - input string + * @returns {string} my-string -> myString + */ + function dashToCamelCase(string) { + return string.replace(/-(\w)/g, (_, c) => c.toUpperCase()) + } + + /** + * Move all the child nodes from a source tag to another + * @param {HTMLElement} source - source node + * @param {HTMLElement} target - target node + * @returns {undefined} it's a void method ¯\_(ツ)_/¯ + */ + + // Ignore this helper because it's needed only for svg tags + function moveChildren(source, target) { + // eslint-disable-next-line fp/no-loops + while (source.firstChild) target.appendChild(source.firstChild); + } + + /** + * Remove the child nodes from any DOM node + * @param {HTMLElement} node - target node + * @returns {undefined} + */ + function cleanNode(node) { + // eslint-disable-next-line fp/no-loops + while (node.firstChild) node.removeChild(node.firstChild); + } + + /** + * Clear multiple children in a node + * @param {HTMLElement[]} children - direct children nodes + * @returns {undefined} + */ + function clearChildren(children) { + // eslint-disable-next-line fp/no-loops,fp/no-let + for (let i = 0; i < children.length; i++) removeChild(children[i]); + } + + /** + * Remove a node + * @param {HTMLElement}node - node to remove + * @returns {undefined} + */ + const removeChild = (node) => node.remove(); + + /** + * Insert before a node + * @param {HTMLElement} newNode - node to insert + * @param {HTMLElement} refNode - ref child + * @returns {undefined} + */ + const insertBefore = (newNode, refNode) => + refNode && + refNode.parentNode && + refNode.parentNode.insertBefore(newNode, refNode); + + /** + * Replace a node + * @param {HTMLElement} newNode - new node to add to the DOM + * @param {HTMLElement} replaced - node to replace + * @returns {undefined} + */ + const replaceChild = (newNode, replaced) => + replaced && + replaced.parentNode && + replaced.parentNode.replaceChild(newNode, replaced); + + // Riot.js constants that can be used across more modules + + const IS_PURE_SYMBOL = Symbol('pure'), + PARENT_KEY_SYMBOL = Symbol('parent'); + + const EACH = 0; + const IF = 1; + const SIMPLE = 2; + const TAG = 3; + const SLOT = 4; + + const bindingTypes = { + EACH, + IF, + SIMPLE, + TAG, + SLOT, + }; + + const ATTRIBUTE = 0; + const EVENT = 1; + const TEXT = 2; + const VALUE = 3; + + const expressionTypes = { + ATTRIBUTE, + EVENT, + TEXT, + VALUE, + }; + + /** + * Quick type checking + * @param {*} element - anything + * @param {string} type - type definition + * @returns {boolean} true if the type corresponds + */ + function checkType(element, type) { + return typeof element === type + } + + /** + * Check if an element is part of an svg + * @param {HTMLElement} el - element to check + * @returns {boolean} true if we are in an svg context + */ + function isSvg(el) { + const owner = el.ownerSVGElement; + + return !!owner || owner === null + } + + /** + * Check if an element is a template tag + * @param {HTMLElement} el - element to check + * @returns {boolean} true if it's a