]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Babel loose (#7452)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Fri, 5 Jun 2020 21:03:54 +0000 (00:03 +0300)
committerGitHub <noreply@github.com>
Fri, 5 Jun 2020 21:03:54 +0000 (17:03 -0400)
* Use loose mode for babel
* Add note about loose mode in performance docs

babel.config.json
docs/docs/general/performance.md
src/core/core.controller.js
src/scales/scale.time.js

index f49a9a87ca761147b2e4ae019c9b37a2e64514c4..7f32580dc1b28e2178e41c76decfc10c6c77a53c 100644 (file)
@@ -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
+}
index 4e9841c0f31ff84bd28ac9ae6ad378f92028f169..c91e466bf64dec0fc12b64b7b1e2b470eefd7b43 100644 (file)
@@ -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)
index 052a15c585f2b83fe3c8aa0ff737875a164367a0..5a7e6243de151397b9b96ee48e46348a2ff1ba6d 100644 (file)
@@ -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) {
index ec8d61e7174fde1c068b968bb7574d525f21074a..570ac747f6089a659242ef32d3f5248c08fbf6ed 100644 (file)
@@ -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<object>} 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);
 }
 
 /**