Babel loose (#7452)

* Use loose mode for babel
* Add note about loose mode in performance docs
This commit is contained in:
Jukka Kurkela 2020-06-06 00:03:54 +03:00 committed by GitHub
parent 0703d78286
commit 3c02846c00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 19 deletions

View File

@ -1,6 +1,10 @@
{
"presets": [
"@babel/preset-env"
[
"@babel/preset-env", {
"loose": true
}
]
],
"plugins": [
"@babel/plugin-transform-object-assign"
@ -12,4 +16,4 @@
]
}
}
}
}

View 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)

View 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) {

View File

@ -44,18 +44,13 @@ function sorter(a, b) {
* @param {number[]} items
*/
function arrayUnique(items) {
const set = new Set();
let i, ilen;
const unique = {};
for (i = 0, ilen = items.length; i < ilen; ++i) {
set.add(items[i]);
for (let i = 0, ilen = items.length; i < ilen; ++i) {
unique[items[i]] = true;
}
if (set.size === ilen) {
return items;
}
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);
}
/**