Skip to content

Commit 86b1892

Browse files
authored
Resolve to false only when _fallback is used (#8542)
* Resolve to false only when _fallback is used * Typo * 2nd part
1 parent c5dcf5a commit 86b1892

File tree

3 files changed

+63
-14
lines changed

3 files changed

+63
-14
lines changed

src/helpers/helpers.config.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export function _descriptors(proxy, defaults = {scriptable: true, indexable: tru
172172
}
173173

174174
const readKey = (prefix, name) => prefix ? prefix + _capitalize(name) : name;
175-
const needsSubResolver = (prop, value) => isObject(value);
175+
const needsSubResolver = (prop, value) => isObject(value) && prop !== 'adapters';
176176

177177
function _cached(target, prop, resolve) {
178178
let value = target[prop]; // cached value
@@ -258,9 +258,9 @@ function addScopes(set, parentScopes, key, parentFallback) {
258258
// The fallback will resume to that new scope.
259259
return fallback;
260260
}
261-
} else if (scope === false && key !== 'fill') {
262-
// Fallback to `false` results to `false`, expect for `fill`.
263-
// The special case (fill) should be handled through descriptors.
261+
} else if (scope === false && defined(parentFallback) && key !== parentFallback) {
262+
// Fallback to `false` results to `false`, when falling back to different key.
263+
// For example `interaction` from `hover` or `plugins.tooltip` and `animation` from `animations`
264264
return null;
265265
}
266266
}
@@ -272,23 +272,25 @@ function createSubResolver(parentScopes, resolver, prop, value) {
272272
const fallback = resolveFallback(resolver._fallback, prop, value);
273273
const allScopes = [...parentScopes, ...rootScopes];
274274
const set = new Set([value]);
275-
let key = prop;
276-
while (key !== false) {
277-
key = addScopes(set, allScopes, key, fallback);
278-
if (key === null) {
279-
return false;
280-
}
275+
let key = addScopesFromKey(set, allScopes, prop, fallback || prop);
276+
if (key === null) {
277+
return false;
281278
}
282279
if (defined(fallback) && fallback !== prop) {
283-
const fallbackScopes = allScopes;
284-
key = fallback;
285-
while (key !== false) {
286-
key = addScopes(set, fallbackScopes, key, fallback);
280+
key = addScopesFromKey(set, allScopes, fallback, key);
281+
if (key === null) {
282+
return false;
287283
}
288284
}
289285
return _createResolver([...set], [''], rootScopes, fallback);
290286
}
291287

288+
function addScopesFromKey(set, allScopes, key, fallback) {
289+
while (key) {
290+
key = addScopes(set, allScopes, key, fallback);
291+
}
292+
return key;
293+
}
292294

293295
function _resolveWithPrefixes(prop, prefixes, scopes, proxy) {
294296
let value;

test/specs/core.datasetController.tests.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,31 @@ describe('Chart.DatasetController', function() {
674674
Chart.defaults.borderColor = oldColor;
675675
});
676676

677+
it('should read parsing from options when default is false', function() {
678+
const originalDefault = Chart.defaults.parsing;
679+
Chart.defaults.parsing = false;
680+
681+
var chart = acquireChart({
682+
type: 'line',
683+
data: {
684+
datasets: [{
685+
data: [{t: 1, y: 0}]
686+
}]
687+
},
688+
options: {
689+
parsing: {
690+
xAxisKey: 't'
691+
}
692+
}
693+
});
694+
695+
var meta = chart.getDatasetMeta(0);
696+
expect(meta.data[0].x).not.toBeNaN();
697+
698+
// Reset old shared state
699+
Chart.defaults.parsing = originalDefault;
700+
});
701+
677702
describe('resolveDataElementOptions', function() {
678703
it('should cache options when possible', function() {
679704
const chart = acquireChart({

test/specs/helpers.config.tests.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,28 @@ describe('Chart.helpers.config', function() {
656656
expect('test' in opts).toBeFalse();
657657
});
658658

659+
it('should not create proxy for adapters', function() {
660+
const defaults = {
661+
scales: {
662+
time: {
663+
adapters: {
664+
date: {
665+
locale: {
666+
method: (arg) => arg === undefined ? 'ok' : 'fail'
667+
}
668+
}
669+
}
670+
}
671+
}
672+
};
673+
674+
const resolver = _createResolver([{}, defaults]);
675+
const opts = _attachContext(resolver, {index: 1});
676+
const fn = opts.scales.time.adapters.date.locale.method;
677+
expect(typeof fn).toBe('function');
678+
expect(fn()).toEqual('ok');
679+
});
680+
659681
describe('_indexable and _scriptable', function() {
660682
it('should default to true', function() {
661683
const options = {

0 commit comments

Comments
 (0)