Skip to content

Commit

Permalink
Babel loose (#7452)
Browse files Browse the repository at this point in the history
* Use loose mode for babel
* Add note about loose mode in performance docs
  • Loading branch information
kurkle authored and etimberg committed Sep 1, 2020
1 parent 9378459 commit 35520df
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
8 changes: 6 additions & 2 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"presets": [
"@babel/preset-env"
[
"@babel/preset-env", {
"loose": true
}
]
],
"plugins": [
"@babel/plugin-transform-object-assign"
Expand All @@ -12,4 +16,4 @@
]
}
}
}
}
5 changes: 5 additions & 0 deletions docs/docs/general/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 10 additions & 15 deletions src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

/**
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 35520df

Please sign in to comment.