From 3c02846c00555dc228e2e72e49801f584819993f Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Sat, 6 Jun 2020 00:03:54 +0300 Subject: [PATCH] Babel loose (#7452) * Use loose mode for babel * Add note about loose mode in performance docs --- babel.config.json | 8 ++++++-- docs/docs/general/performance.md | 5 +++++ src/core/core.controller.js | 4 ++-- src/scales/scale.time.js | 25 ++++++++++--------------- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/babel.config.json b/babel.config.json index f49a9a87c..7f32580dc 100644 --- a/babel.config.json +++ b/babel.config.json @@ -1,6 +1,10 @@ { "presets": [ - "@babel/preset-env" + [ + "@babel/preset-env", { + "loose": true + } + ] ], "plugins": [ "@babel/plugin-transform-object-assign" @@ -12,4 +16,4 @@ ] } } -} \ No newline at end of file +} diff --git a/docs/docs/general/performance.md b/docs/docs/general/performance.md index 4e9841c0f..c91e466bf 100644 --- a/docs/docs/general/performance.md +++ b/docs/docs/general/performance.md @@ -219,3 +219,8 @@ new Chart(ctx, { } }); ``` + +### When transpiling with Babel, cosider using `loose` mode + +Babel 7.9 changed the way classes are constructed. It is slow, unless used with `loose` mode. +[More information](https://github.com/babel/babel/issues/11356) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 052a15c58..5a7e6243d 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -122,9 +122,9 @@ function updateConfig(chart) { chart._animationsDisabled = isAnimationDisabled(newOptions); } -const KNOWN_POSITIONS = new Set(['top', 'bottom', 'left', 'right', 'chartArea']); +const KNOWN_POSITIONS = ['top', 'bottom', 'left', 'right', 'chartArea']; function positionIsHorizontal(position, axis) { - return position === 'top' || position === 'bottom' || (!KNOWN_POSITIONS.has(position) && axis === 'x'); + return position === 'top' || position === 'bottom' || (KNOWN_POSITIONS.indexOf(position) === -1 && axis === 'x'); } function compare2Level(l1, l2) { diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index ec8d61e71..570ac747f 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -44,18 +44,13 @@ function sorter(a, b) { * @param {number[]} items */ function arrayUnique(items) { - const set = new Set(); - let i, ilen; - - for (i = 0, ilen = items.length; i < ilen; ++i) { - set.add(items[i]); - } + const unique = {}; - if (set.size === ilen) { - return items; + for (let i = 0, ilen = items.length; i < ilen; ++i) { + unique[items[i]] = true; } - return [...set]; + return Object.keys(unique).map(x => +x); } /** @@ -305,7 +300,7 @@ function determineMajorUnit(unit) { /** * @param {number[]} timestamps - * @param {Set} ticks + * @param {object} ticks * @param {number} time */ function addTick(timestamps, ticks, time) { @@ -314,7 +309,7 @@ function addTick(timestamps, ticks, time) { } const {lo, hi} = _lookup(timestamps, time); const timestamp = timestamps[lo] >= time ? timestamps[lo] : timestamps[hi]; - ticks.add(timestamp); + ticks[timestamp] = true; } /** @@ -334,7 +329,7 @@ function generate(scale) { const minor = timeOpts.unit || determineUnitForAutoTicks(timeOpts.minUnit, min, max, scale._getLabelCapacity(min)); const stepSize = valueOrDefault(timeOpts.stepSize, 1); const weekday = minor === 'week' ? timeOpts.isoWeekday : false; - const ticks = new Set(); + const ticks = {}; let first = min; let time; @@ -364,15 +359,15 @@ function generate(scale) { } } else { for (time = first; time < max; time = +adapter.add(time, stepSize, minor)) { - ticks.add(time); + ticks[time] = true; } if (time === max || options.bounds === 'ticks') { - ticks.add(time); + ticks[time] = true; } } - return [...ticks]; + return Object.keys(ticks).map(x => +x); } /** -- 2.47.2