Skip to content

Commit 3c02846

Browse files
authored
Babel loose (chartjs#7452)
* Use loose mode for babel * Add note about loose mode in performance docs
1 parent 0703d78 commit 3c02846

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

babel.config.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"presets": [
3-
"@babel/preset-env"
3+
[
4+
"@babel/preset-env", {
5+
"loose": true
6+
}
7+
]
48
],
59
"plugins": [
610
"@babel/plugin-transform-object-assign"
@@ -12,4 +16,4 @@
1216
]
1317
}
1418
}
15-
}
19+
}

docs/docs/general/performance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,8 @@ new Chart(ctx, {
219219
}
220220
});
221221
```
222+
223+
### When transpiling with Babel, cosider using `loose` mode
224+
225+
Babel 7.9 changed the way classes are constructed. It is slow, unless used with `loose` mode.
226+
[More information](https://github.com/babel/babel/issues/11356)

src/core/core.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ function updateConfig(chart) {
122122
chart._animationsDisabled = isAnimationDisabled(newOptions);
123123
}
124124

125-
const KNOWN_POSITIONS = new Set(['top', 'bottom', 'left', 'right', 'chartArea']);
125+
const KNOWN_POSITIONS = ['top', 'bottom', 'left', 'right', 'chartArea'];
126126
function positionIsHorizontal(position, axis) {
127-
return position === 'top' || position === 'bottom' || (!KNOWN_POSITIONS.has(position) && axis === 'x');
127+
return position === 'top' || position === 'bottom' || (KNOWN_POSITIONS.indexOf(position) === -1 && axis === 'x');
128128
}
129129

130130
function compare2Level(l1, l2) {

src/scales/scale.time.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,13 @@ function sorter(a, b) {
4444
* @param {number[]} items
4545
*/
4646
function arrayUnique(items) {
47-
const set = new Set();
48-
let i, ilen;
49-
50-
for (i = 0, ilen = items.length; i < ilen; ++i) {
51-
set.add(items[i]);
52-
}
47+
const unique = {};
5348

54-
if (set.size === ilen) {
55-
return items;
49+
for (let i = 0, ilen = items.length; i < ilen; ++i) {
50+
unique[items[i]] = true;
5651
}
5752

58-
return [...set];
53+
return Object.keys(unique).map(x => +x);
5954
}
6055

6156
/**
@@ -305,7 +300,7 @@ function determineMajorUnit(unit) {
305300

306301
/**
307302
* @param {number[]} timestamps
308-
* @param {Set<object>} ticks
303+
* @param {object} ticks
309304
* @param {number} time
310305
*/
311306
function addTick(timestamps, ticks, time) {
@@ -314,7 +309,7 @@ function addTick(timestamps, ticks, time) {
314309
}
315310
const {lo, hi} = _lookup(timestamps, time);
316311
const timestamp = timestamps[lo] >= time ? timestamps[lo] : timestamps[hi];
317-
ticks.add(timestamp);
312+
ticks[timestamp] = true;
318313
}
319314

320315
/**
@@ -334,7 +329,7 @@ function generate(scale) {
334329
const minor = timeOpts.unit || determineUnitForAutoTicks(timeOpts.minUnit, min, max, scale._getLabelCapacity(min));
335330
const stepSize = valueOrDefault(timeOpts.stepSize, 1);
336331
const weekday = minor === 'week' ? timeOpts.isoWeekday : false;
337-
const ticks = new Set();
332+
const ticks = {};
338333
let first = min;
339334
let time;
340335

@@ -364,15 +359,15 @@ function generate(scale) {
364359
}
365360
} else {
366361
for (time = first; time < max; time = +adapter.add(time, stepSize, minor)) {
367-
ticks.add(time);
362+
ticks[time] = true;
368363
}
369364

370365
if (time === max || options.bounds === 'ticks') {
371-
ticks.add(time);
366+
ticks[time] = true;
372367
}
373368
}
374369

375-
return [...ticks];
370+
return Object.keys(ticks).map(x => +x);
376371
}
377372

378373
/**

0 commit comments

Comments
 (0)