From 936807e864c9da7d4529a11ad979695b03c136f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Am=C3=A9rico?= Date: Sun, 17 Jun 2018 12:54:29 -0300 Subject: [PATCH 1/4] Use rollup with a config file and buble plugin --- dist/index.es6.js | 54 ++++++++++++++++--------- dist/index.js | 53 +++++++++++++++--------- package.json | 14 +++---- rollup.config.js | 26 ++++++++++++ yarn.lock | 101 +++++++++++++++++++++++++++------------------- 5 files changed, 161 insertions(+), 87 deletions(-) create mode 100644 rollup.config.js diff --git a/dist/index.es6.js b/dist/index.es6.js index b70a657..ba081fa 100644 --- a/dist/index.es6.js +++ b/dist/index.es6.js @@ -22,6 +22,7 @@ var svgPropsMap = { svg: 1, circle: 1, ellipse: 1, line: 1, polygon: 1, var svg = function (v) { return v.sel in svgPropsMap; }; // TODO: stop using extend here + var extend = function () { var objs = [], len = arguments.length; while ( len-- ) objs[ len ] = arguments[ len ]; @@ -58,30 +59,39 @@ var mapObject = function (obj, fn) { return Object.keys(obj).map( var deepifyKeys = function (obj) { return mapObject(obj, function (key, val) { + var obj, obj$1; + var dashIndex = key.indexOf('-'); if (dashIndex > -1) { var moduleData = {}; moduleData[key.slice(dashIndex + 1)] = val; return ( obj = {}, obj[key.slice(0, dashIndex)] = moduleData, obj ) - var obj; } return ( obj$1 = {}, obj$1[key] = val, obj$1 ) - var obj$1; } ); }; var flatifyKeys = function (obj) { return mapObject(obj, - function (mod, data) { return !object(data) ? (( obj = {}, obj[mod] = data, obj )) : mapObject( + function (mod, data) { + var obj; + + return !object(data) ? (( obj = {}, obj[mod] = data, obj )) : mapObject( flatifyKeys(data), - function (key, val) { return (( obj = {}, obj[(mod + "-" + key)] = val, obj )) - var obj; } - ) - var obj; } + function (key, val) { + var obj; + + return (( obj = {}, obj[(mod + "-" + key)] = val, obj )); + } + ); + } ); }; var omit = function (key, obj) { return mapObject(obj, - function (mod, data) { return mod !== key ? (( obj = {}, obj[mod] = data, obj )) : {} - var obj; } + function (mod, data) { + var obj; + + return mod !== key ? (( obj = {}, obj[mod] = data, obj )) : {}; + } ); }; // Const fnName = (...params) => guard ? default : ... @@ -109,9 +119,10 @@ var considerSvg = function (vnode$$1) { return !svg(vnode$$1) ? vnode$$1 : var considerData = function (data) { return !data.data ? data : mapObject(data, function (mod, data) { + var obj; + var key = mod === 'data' ? 'dataset' : mod; return (( obj = {}, obj[key] = data, obj )) - var obj; }) }; @@ -122,20 +133,24 @@ var considerAria = function (data) { return data.attrs || data.aria ? omit('aria ) : data; }; var considerProps = function (data) { return mapObject(data, - function (key, val) { return object(val) ? ( obj = {}, obj[key] = val, obj ) : - { props: ( obj$1 = {}, obj$1[key] = val, obj$1 ) } - var obj; - var obj$1; } + function (key, val) { + var obj, obj$1; + + return object(val) ? ( obj = {}, obj[key] = val, obj ) : + { props: ( obj$1 = {}, obj$1[key] = val, obj$1 ) }; + } ); }; var rewritesMap = { for: 1, role: 1, tabindex: 1 }; var considerAttrs = function (data) { return mapObject(data, - function (key, data) { return !(key in rewritesMap) ? ( obj = {}, obj[key] = data, obj ) : { + function (key, data) { + var obj, obj$1; + + return !(key in rewritesMap) ? ( obj = {}, obj[key] = data, obj ) : { attrs: extend(data.attrs, ( obj$1 = {}, obj$1[key] = data, obj$1 )) - } - var obj; - var obj$1; } + }; + } ); }; var considerKey = function (data) { @@ -175,4 +190,5 @@ var index = { createElement: createElement }; -export { createElement };export default index; +export default index; +export { createElement }; diff --git a/dist/index.js b/dist/index.js index 993f053..cfcc01f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -28,6 +28,7 @@ var svgPropsMap = { svg: 1, circle: 1, ellipse: 1, line: 1, polygon: 1, var svg = function (v) { return v.sel in svgPropsMap; }; // TODO: stop using extend here + var extend = function () { var objs = [], len = arguments.length; while ( len-- ) objs[ len ] = arguments[ len ]; @@ -64,30 +65,39 @@ var mapObject = function (obj, fn) { return Object.keys(obj).map( var deepifyKeys = function (obj) { return mapObject(obj, function (key, val) { + var obj, obj$1; + var dashIndex = key.indexOf('-'); if (dashIndex > -1) { var moduleData = {}; moduleData[key.slice(dashIndex + 1)] = val; return ( obj = {}, obj[key.slice(0, dashIndex)] = moduleData, obj ) - var obj; } return ( obj$1 = {}, obj$1[key] = val, obj$1 ) - var obj$1; } ); }; var flatifyKeys = function (obj) { return mapObject(obj, - function (mod, data) { return !object(data) ? (( obj = {}, obj[mod] = data, obj )) : mapObject( + function (mod, data) { + var obj; + + return !object(data) ? (( obj = {}, obj[mod] = data, obj )) : mapObject( flatifyKeys(data), - function (key, val) { return (( obj = {}, obj[(mod + "-" + key)] = val, obj )) - var obj; } - ) - var obj; } + function (key, val) { + var obj; + + return (( obj = {}, obj[(mod + "-" + key)] = val, obj )); + } + ); + } ); }; var omit = function (key, obj) { return mapObject(obj, - function (mod, data) { return mod !== key ? (( obj = {}, obj[mod] = data, obj )) : {} - var obj; } + function (mod, data) { + var obj; + + return mod !== key ? (( obj = {}, obj[mod] = data, obj )) : {}; + } ); }; // Const fnName = (...params) => guard ? default : ... @@ -115,9 +125,10 @@ var considerSvg = function (vnode$$1) { return !svg(vnode$$1) ? vnode$$1 : var considerData = function (data) { return !data.data ? data : mapObject(data, function (mod, data) { + var obj; + var key = mod === 'data' ? 'dataset' : mod; return (( obj = {}, obj[key] = data, obj )) - var obj; }) }; @@ -128,20 +139,24 @@ var considerAria = function (data) { return data.attrs || data.aria ? omit('aria ) : data; }; var considerProps = function (data) { return mapObject(data, - function (key, val) { return object(val) ? ( obj = {}, obj[key] = val, obj ) : - { props: ( obj$1 = {}, obj$1[key] = val, obj$1 ) } - var obj; - var obj$1; } + function (key, val) { + var obj, obj$1; + + return object(val) ? ( obj = {}, obj[key] = val, obj ) : + { props: ( obj$1 = {}, obj$1[key] = val, obj$1 ) }; + } ); }; var rewritesMap = { for: 1, role: 1, tabindex: 1 }; var considerAttrs = function (data) { return mapObject(data, - function (key, data) { return !(key in rewritesMap) ? ( obj = {}, obj[key] = data, obj ) : { + function (key, data) { + var obj, obj$1; + + return !(key in rewritesMap) ? ( obj = {}, obj[key] = data, obj ) : { attrs: extend(data.attrs, ( obj$1 = {}, obj$1[key] = data, obj$1 )) - } - var obj; - var obj$1; } + }; + } ); }; var considerKey = function (data) { @@ -182,4 +197,4 @@ var index = { }; exports.createElement = createElement; -exports['default'] = index; +exports.default = index; diff --git a/package.json b/package.json index 95a1d0a..364b7a3 100644 --- a/package.json +++ b/package.json @@ -25,10 +25,10 @@ "babel-preset-es2015": "^6.24.1", "babel-preset-stage-2": "^6.24.1", "benchmark": "^2.1.4", - "buble": "^0.17.3", + "buble": "^0.19.3", "eslint-config-xo-swizz": "^0.11.0", - "rimraf": "^2.6.1", - "rollup": "^0.41.3", + "rollup": "^0.60.7", + "rollup-plugin-buble": "^0.19.2", "simple-git": "^1.92.0", "snabbdom": "^0.6.7", "traceur": "^0.0.111", @@ -42,10 +42,7 @@ "lint": "./node_modules/.bin/xo", "test:prebuild": "ava --match \"trans -*\" --match \"src -*\" --match \"utils -*\"", "test:postbuild": "ava --match \"dist -*\"", - "transpile": "./node_modules/.bin/buble -i src/ -o lib/ --no modules --objectAssign fn.assign", - "modules": "rollup -i lib/index.js -o dist/index.js -f cjs && rollup -i lib/index.js -o dist/index.es6.js -f es", - "clean": "./node_modules/.bin/rimraf 'lib/'", - "build": "npm run transpile && npm run modules && npm run clean", + "build": "rollup --config", "make": "npm run lint && npm run test:prebuild && npm run build && npm run test:postbuild", "perf:all": "node perf/build-branches && node perf/run", "perf": "node perf/run" @@ -64,7 +61,8 @@ "extends": "xo-swizz", "rules": { "import/no-dynamic-require": "off", - "capitalized-comments": "off" + "capitalized-comments": "off", + "linebreak-style": "off" }, "ignores": [ "test/**/transform-*.js" diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..41fa661 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,26 @@ +const buble = require('rollup-plugin-buble') + +const bubleOptions = { + transforms: { + modules: false + }, + objectAssign: 'fn.assign' +} + +module.exports = { + input: 'src/index.js', + plugins: [buble(bubleOptions)], + external: ['extend'], + output: [ + { + file: 'dist/index.es6.js', + format: 'es', + exports: 'named' + }, + { + file: 'dist/index.js', + format: 'cjs', + exports: 'named' + } + ] +} diff --git a/yarn.lock b/yarn.lock index cbe34f2..ccbb14b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -53,34 +53,48 @@ pretty-ms "^0.2.1" text-table "^0.2.0" +"@types/estree@0.0.39": + version "0.0.39" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" + +"@types/node@*": + version "10.3.3" + resolved "https://registry.yarnpkg.com/@types/node/-/node-10.3.3.tgz#8798d9e39af2fa604f715ee6a6b19796528e46c3" + abbrev@1: version "1.1.0" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f" -acorn-jsx@^3.0.0, acorn-jsx@^3.0.1: +acorn-dynamic-import@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-3.0.0.tgz#901ceee4c7faaef7e07ad2a47e890675da50a278" + dependencies: + acorn "^5.0.0" + +acorn-jsx@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-3.0.1.tgz#afdf9488fb1ecefc8348f6fb22f464e32a58b36b" dependencies: acorn "^3.0.4" -acorn5-object-spread@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/acorn5-object-spread/-/acorn5-object-spread-4.0.0.tgz#d5758081eed97121ab0be47e31caaef2aa399697" +acorn-jsx@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-4.1.1.tgz#e8e41e48ea2fe0c896740610ab6a4ffd8add225e" dependencies: - acorn "^5.1.2" + acorn "^5.0.3" acorn@^3.0.4: version "3.3.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" +acorn@^5.0.0, acorn@^5.0.3, acorn@^5.4.1: + version "5.7.1" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.1.tgz#f095829297706a7c9776958c0afc8930a9b9d9d8" + acorn@^5.0.1: version "5.0.3" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.0.3.tgz#c460df08491463f028ccb82eab3730bf01087b3d" -acorn@^5.1.2: - version "5.2.1" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.2.1.tgz#317ac7821826c22c702d66189ab8359675f135d7" - ajv-keywords@^1.0.0: version "1.5.1" resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c" @@ -1031,18 +1045,18 @@ braces@^1.8.2: preserve "^0.2.0" repeat-element "^1.1.2" -buble@^0.17.3: - version "0.17.3" - resolved "https://registry.yarnpkg.com/buble/-/buble-0.17.3.tgz#b30e281054aa619da5e7b0530ac99fcf309bee67" +buble@^0.19.2, buble@^0.19.3: + version "0.19.3" + resolved "https://registry.yarnpkg.com/buble/-/buble-0.19.3.tgz#01e9412062cff1da6f20342b6ecd72e7bf699d02" dependencies: - acorn "^5.1.2" - acorn-jsx "^3.0.1" - acorn5-object-spread "^4.0.0" - chalk "^2.1.0" + acorn "^5.4.1" + acorn-dynamic-import "^3.0.0" + acorn-jsx "^4.1.1" + chalk "^2.3.1" magic-string "^0.22.4" minimist "^1.2.0" os-homedir "^1.0.1" - vlq "^0.2.2" + vlq "^1.0.0" buf-compare@^1.0.0: version "1.0.1" @@ -1132,7 +1146,7 @@ chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^2.0.1: +chalk@^2.0.1, chalk@^2.3.1: version "2.4.1" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e" dependencies: @@ -1140,14 +1154,6 @@ chalk@^2.0.1: escape-string-regexp "^1.0.5" supports-color "^5.3.0" -chalk@^2.1.0: - version "2.3.0" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba" - dependencies: - ansi-styles "^3.1.0" - escape-string-regexp "^1.0.5" - supports-color "^4.0.0" - chokidar@^1.4.2: version "1.6.1" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.6.1.tgz#2f4447ab5e96e50fb3d789fd90d4c72e0e4c70c2" @@ -1838,6 +1844,10 @@ estraverse@~4.1.0: version "4.1.1" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.1.1.tgz#f6caca728933a850ef90661d0e17982ba47111a2" +estree-walker@^0.5.2: + version "0.5.2" + resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.5.2.tgz#d3850be7529c9580d815600b53126515e146dd39" + esutils@^2.0.0, esutils@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" @@ -2923,7 +2933,7 @@ meow@^3.4.2, meow@^3.7.0: redent "^1.0.0" trim-newlines "^1.0.0" -micromatch@^2.1.5: +micromatch@^2.1.5, micromatch@^2.3.11: version "2.3.11" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" dependencies: @@ -3667,11 +3677,26 @@ rimraf@2, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.6.1: dependencies: glob "^7.0.5" -rollup@^0.41.3: - version "0.41.6" - resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.41.6.tgz#e0d05497877a398c104d816d2733a718a7a94e2a" +rollup-plugin-buble@^0.19.2: + version "0.19.2" + resolved "https://registry.yarnpkg.com/rollup-plugin-buble/-/rollup-plugin-buble-0.19.2.tgz#c0590c7d3d475b5ed59f129764ec93710cc6e8dd" + dependencies: + buble "^0.19.2" + rollup-pluginutils "^2.0.1" + +rollup-pluginutils@^2.0.1: + version "2.3.0" + resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.3.0.tgz#478ace04bd7f6da2e724356ca798214884738fc4" + dependencies: + estree-walker "^0.5.2" + micromatch "^2.3.11" + +rollup@^0.60.7: + version "0.60.7" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.60.7.tgz#2b62ef9306f719b1ab85a7814b3e6596ac51fae8" dependencies: - source-map-support "^0.4.0" + "@types/estree" "0.0.39" + "@types/node" "*" rsvp@^3.0.13: version "3.5.0" @@ -3781,7 +3806,7 @@ sort-keys@^1.1.1, sort-keys@^1.1.2: dependencies: is-plain-obj "^1.0.0" -source-map-support@^0.4.0, source-map-support@^0.4.2: +source-map-support@^0.4.2: version "0.4.15" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.15.tgz#03202df65c06d2bd8c7ec2362a193056fef8d3b1" dependencies: @@ -3947,12 +3972,6 @@ supports-color@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" -supports-color@^4.0.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b" - dependencies: - has-flag "^2.0.0" - supports-color@^5.0.0, supports-color@^5.3.0: version "5.4.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54" @@ -4218,9 +4237,9 @@ vlq@^0.2.1: version "0.2.2" resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.2.tgz#e316d5257b40b86bb43cb8d5fea5d7f54d6b0ca1" -vlq@^0.2.2: - version "0.2.3" - resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.3.tgz#8f3e4328cf63b1540c0d67e1b2778386f8975b26" +vlq@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/vlq/-/vlq-1.0.0.tgz#8101be90843422954c2b13eb27f2f3122bdcc806" well-known-symbols@^1.0.0: version "1.0.0" From b25cd151e10a2156365b94971f5391e1495f76b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Am=C3=A9rico?= Date: Sun, 17 Jun 2018 13:53:06 -0300 Subject: [PATCH 2/4] Compile perf builds directly to target file --- perf/.gitignore | 4 ++-- perf/build-branches.js | 3 +-- perf/modules-attribute-props.js | 4 ++-- perf/modules-object-props.js | 4 ++-- perf/no-props.js | 4 ++-- perf/real-world-form.js | 4 ++-- perf/simple-props.js | 4 ++-- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/perf/.gitignore b/perf/.gitignore index ed7a33a..8d57c49 100644 --- a/perf/.gitignore +++ b/perf/.gitignore @@ -1,2 +1,2 @@ -/snnabdom-new.js -/snnabdom-base.js +/snabbdom-new.js +/snabbdom-base.js diff --git a/perf/build-branches.js b/perf/build-branches.js index 6ff8ef5..a14ba82 100644 --- a/perf/build-branches.js +++ b/perf/build-branches.js @@ -7,8 +7,7 @@ const simpleGit = require('simple-git')() const baseBranch = process.argv[2] || 'develop' function buildSnabbdom(suffix) { - execSync('npm run build', { stdio: [0, 1, 2] }) - fs.writeFileSync(`perf/snnabdom-${suffix}.js`, fs.readFileSync('dist/index.js', 'utf-8'), 'utf-8') + execSync(`npm run build -- --file perf/snabbdom-${suffix}.js`, { stdio: [0, 1, 2] }) } simpleGit.status((err, status) => { diff --git a/perf/modules-attribute-props.js b/perf/modules-attribute-props.js index 5edd0d3..ba25fae 100644 --- a/perf/modules-attribute-props.js +++ b/perf/modules-attribute-props.js @@ -2,8 +2,8 @@ const Benchmark = require('benchmark') const h = require('snabbdom/h').default -const baseCreateElement = require('./snnabdom-base').createElement -const newCreateElement = require('./snnabdom-new').createElement +const baseCreateElement = require('./snabbdom-base').createElement +const newCreateElement = require('./snabbdom-new').createElement const isVisible = true const isEnabled = false diff --git a/perf/modules-object-props.js b/perf/modules-object-props.js index ee8bc0f..5ae651c 100644 --- a/perf/modules-object-props.js +++ b/perf/modules-object-props.js @@ -2,8 +2,8 @@ const Benchmark = require('benchmark') const h = require('snabbdom/h').default -const baseCreateElement = require('./snnabdom-base').createElement -const newCreateElement = require('./snnabdom-new').createElement +const baseCreateElement = require('./snabbdom-base').createElement +const newCreateElement = require('./snabbdom-new').createElement function objectPropsHyper() { return h('div', { style: { color: 'red', fontWeight: 'bold' }, dataset: { color: 'red', hidden: true } }, [ diff --git a/perf/no-props.js b/perf/no-props.js index 66b06e5..d536627 100644 --- a/perf/no-props.js +++ b/perf/no-props.js @@ -2,8 +2,8 @@ const Benchmark = require('benchmark') const h = require('snabbdom/h').default -const baseCreateElement = require('./snnabdom-base').createElement -const newCreateElement = require('./snnabdom-new').createElement +const baseCreateElement = require('./snabbdom-base').createElement +const newCreateElement = require('./snabbdom-new').createElement function noPropsHyper() { return h('div', {}, [ diff --git a/perf/real-world-form.js b/perf/real-world-form.js index dfe7d4e..14bd820 100644 --- a/perf/real-world-form.js +++ b/perf/real-world-form.js @@ -1,8 +1,8 @@ /* eslint import/no-unresolved: 0 */ const Benchmark = require('benchmark') -const baseCreateElement = require('./snnabdom-base').createElement -const newCreateElement = require('./snnabdom-new').createElement +const baseCreateElement = require('./snabbdom-base').createElement +const newCreateElement = require('./snabbdom-new').createElement function realWorldForm(createElement) { const state = {} diff --git a/perf/simple-props.js b/perf/simple-props.js index 1a04ef9..a07e169 100644 --- a/perf/simple-props.js +++ b/perf/simple-props.js @@ -2,8 +2,8 @@ const Benchmark = require('benchmark') const h = require('snabbdom/h').default -const baseCreateElement = require('./snnabdom-base').createElement -const newCreateElement = require('./snnabdom-new').createElement +const baseCreateElement = require('./snabbdom-base').createElement +const newCreateElement = require('./snabbdom-new').createElement function simplePropsHyper() { return h('div', { props: { href: 'xxxxx', target: 'route' } }, [ From 876f5a18aae0bbf126b96558ce1420c80c52155e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Am=C3=A9rico?= Date: Sun, 17 Jun 2018 14:19:28 -0300 Subject: [PATCH 3/4] Fix lint warnings --- perf/build-branches.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/perf/build-branches.js b/perf/build-branches.js index a14ba82..a8ffb07 100644 --- a/perf/build-branches.js +++ b/perf/build-branches.js @@ -1,13 +1,12 @@ /* eslint unicorn/no-process-exit: 0 */ const execSync = require('child_process').execSync -const fs = require('fs') const simpleGit = require('simple-git')() const baseBranch = process.argv[2] || 'develop' function buildSnabbdom(suffix) { - execSync(`npm run build -- --file perf/snabbdom-${suffix}.js`, { stdio: [0, 1, 2] }) + execSync(`npm run build -- --file perf/snabbdom-${suffix}.js`, { stdio: [0, 1, 2] }) } simpleGit.status((err, status) => { From 9516505f11762a86effcc5ae9b823eb95960133b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Am=C3=A9rico?= Date: Sun, 17 Jun 2018 14:49:58 -0300 Subject: [PATCH 4/4] Improve support for svg --- dist/index.es6.js | 28 +++++++++++------------ dist/index.js | 28 +++++++++++------------ src/index.js | 19 +++++++++------ src/is.js | 5 ---- test/snabbdom-specs/vnode-svg/actual.js | 5 +++- test/snabbdom-specs/vnode-svg/expected.js | 9 +++++++- 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/dist/index.es6.js b/dist/index.es6.js index ba081fa..cdb55fe 100644 --- a/dist/index.es6.js +++ b/dist/index.es6.js @@ -1,7 +1,5 @@ import _extend from 'extend'; -var undefinedv = function (v) { return v === undefined; }; - var number = function (v) { return typeof v === 'number'; }; var string = function (v) { return typeof v === 'string'; }; @@ -16,11 +14,6 @@ var fun = function (v) { return typeof v === 'function'; }; var vnode = function (v) { return object(v) && 'sel' in v && 'data' in v && 'children' in v && 'text' in v; }; -var svgPropsMap = { svg: 1, circle: 1, ellipse: 1, line: 1, polygon: 1, - polyline: 1, rect: 1, g: 1, path: 1, text: 1 }; - -var svg = function (v) { return v.sel in svgPropsMap; }; - // TODO: stop using extend here var extend = function () { @@ -105,17 +98,18 @@ var createTextElement = function (text$$1) { return !text(text$$1) ? undefined : key: undefined }; }; -var considerSvg = function (vnode$$1) { return !svg(vnode$$1) ? vnode$$1 : +var transformSvg = function (vnode$$1) { assign(vnode$$1, { data: omit('props', extend(vnode$$1.data, { ns: 'http://www.w3.org/2000/svg', attrs: omit('className', extend(vnode$$1.data.props, { class: vnode$$1.data.props ? vnode$$1.data.props.className : undefined } )) } - )) }, - { children: undefinedv(vnode$$1.children) ? undefined : - vnode$$1.children.map(function (child) { return considerSvg(child); }) - } - ); }; + )) } + ); + if (vnode$$1.children) { + vnode$$1.children.forEach(transformSvg); + } +}; var considerData = function (data) { return !data.data ? data : mapObject(data, function (mod, data) { @@ -176,14 +170,18 @@ var createElement = function (sel, data) { return sel(data || {}, children) } var text$$1 = sanitizeText(children); - return considerSvg({ + var vnode$$1 = { sel: sel, data: data ? sanitizeData(data) : {}, children: text$$1 ? undefined : sanitizeChildren(children), text: text$$1, elm: undefined, key: data ? data.key : undefined - }) + }; + if (sel === 'svg') { + transformSvg(vnode$$1); + } + return vnode$$1 }; var index = { diff --git a/dist/index.js b/dist/index.js index cfcc01f..7243e25 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6,8 +6,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var _extend = _interopDefault(require('extend')); -var undefinedv = function (v) { return v === undefined; }; - var number = function (v) { return typeof v === 'number'; }; var string = function (v) { return typeof v === 'string'; }; @@ -22,11 +20,6 @@ var fun = function (v) { return typeof v === 'function'; }; var vnode = function (v) { return object(v) && 'sel' in v && 'data' in v && 'children' in v && 'text' in v; }; -var svgPropsMap = { svg: 1, circle: 1, ellipse: 1, line: 1, polygon: 1, - polyline: 1, rect: 1, g: 1, path: 1, text: 1 }; - -var svg = function (v) { return v.sel in svgPropsMap; }; - // TODO: stop using extend here var extend = function () { @@ -111,17 +104,18 @@ var createTextElement = function (text$$1) { return !text(text$$1) ? undefined : key: undefined }; }; -var considerSvg = function (vnode$$1) { return !svg(vnode$$1) ? vnode$$1 : +var transformSvg = function (vnode$$1) { assign(vnode$$1, { data: omit('props', extend(vnode$$1.data, { ns: 'http://www.w3.org/2000/svg', attrs: omit('className', extend(vnode$$1.data.props, { class: vnode$$1.data.props ? vnode$$1.data.props.className : undefined } )) } - )) }, - { children: undefinedv(vnode$$1.children) ? undefined : - vnode$$1.children.map(function (child) { return considerSvg(child); }) - } - ); }; + )) } + ); + if (vnode$$1.children) { + vnode$$1.children.forEach(transformSvg); + } +}; var considerData = function (data) { return !data.data ? data : mapObject(data, function (mod, data) { @@ -182,14 +176,18 @@ var createElement = function (sel, data) { return sel(data || {}, children) } var text$$1 = sanitizeText(children); - return considerSvg({ + var vnode$$1 = { sel: sel, data: data ? sanitizeData(data) : {}, children: text$$1 ? undefined : sanitizeChildren(children), text: text$$1, elm: undefined, key: data ? data.key : undefined - }) + }; + if (sel === 'svg') { + transformSvg(vnode$$1); + } + return vnode$$1 }; var index = { diff --git a/src/index.js b/src/index.js index 8010ccb..0372677 100644 --- a/src/index.js +++ b/src/index.js @@ -13,17 +13,18 @@ const createTextElement = (text) => !is.text(text) ? undefined : { key: undefined } -const considerSvg = (vnode) => !is.svg(vnode) ? vnode : +const transformSvg = (vnode) => { fn.assign(vnode, { data: fn.omit('props', fn.extend(vnode.data, { ns: 'http://www.w3.org/2000/svg', attrs: fn.omit('className', fn.extend(vnode.data.props, { class: vnode.data.props ? vnode.data.props.className : undefined } )) } - )) }, - { children: is.undefinedv(vnode.children) ? undefined : - vnode.children.map((child) => considerSvg(child)) - } + )) } ) + if (vnode.children) { + vnode.children.forEach(transformSvg) + } +} const considerData = (data) => { return !data.data ? data : fn.mapObject(data, (mod, data) => { @@ -71,14 +72,18 @@ export const createElement = (sel, data, ...children) => { return sel(data || {}, children) } const text = sanitizeText(children) - return considerSvg({ + const vnode = { sel, data: data ? sanitizeData(data) : {}, children: text ? undefined : sanitizeChildren(children), text, elm: undefined, key: data ? data.key : undefined - }) + } + if (sel === 'svg') { + transformSvg(vnode) + } + return vnode } export default { diff --git a/src/is.js b/src/is.js index 72adfbb..d9b5385 100644 --- a/src/is.js +++ b/src/is.js @@ -16,8 +16,3 @@ export const object = (v) => typeof v === 'object' && v !== null export const fun = (v) => typeof v === 'function' export const vnode = (v) => object(v) && 'sel' in v && 'data' in v && 'children' in v && 'text' in v - -const svgPropsMap = { svg: 1, circle: 1, ellipse: 1, line: 1, polygon: 1, - polyline: 1, rect: 1, g: 1, path: 1, text: 1 } - -export const svg = (v) => v.sel in svgPropsMap diff --git a/test/snabbdom-specs/vnode-svg/actual.js b/test/snabbdom-specs/vnode-svg/actual.js index 52f32cc..d9b6899 100644 --- a/test/snabbdom-specs/vnode-svg/actual.js +++ b/test/snabbdom-specs/vnode-svg/actual.js @@ -2,7 +2,10 @@ export default (createElement) => { return createElement('svg', null, [ createElement('g', null, [ - createElement('circle', { cx: 43.5, cy: 23, r: 5 }) + createElement('circle', { cx: 43.5, cy: 23, r: 5 }), + createElement('polygon', { points: '60,30 90,90 30,90' }, [ + createElement('animateTransform', { type: 'rotate', from: '0 60 70', to: '360 60 70' }) + ]) ]) ]) } diff --git a/test/snabbdom-specs/vnode-svg/expected.js b/test/snabbdom-specs/vnode-svg/expected.js index b62349c..2f9415a 100644 --- a/test/snabbdom-specs/vnode-svg/expected.js +++ b/test/snabbdom-specs/vnode-svg/expected.js @@ -4,7 +4,14 @@ export default (h) => { h('g', { attrs: {} }, [ h('circle', { attrs: { cx: 43.5, cy: 23, r: 5 } - }, []) + }, []), + h('polygon', { + attrs: { points: '60,30 90,90 30,90' } + }, [ + h('animateTransform', { + attrs: { type: 'rotate', from: '0 60 70', to: '360 60 70' } + }, []) + ]) ]) ]) }