Skip to content

Commit 9a08705

Browse files
committed
split createSubResolver
1 parent 0234203 commit 9a08705

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/helpers/helpers.config.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function _attachContext(proxy, context, subProxy) {
6363
if (isPublicOptionValue(prop, value)) {
6464
if (isFunction(value) && isScriptable(prop)) {
6565
if (stack.has(prop)) {
66+
// @ts-ignore
6667
throw new Error('Recursion detected: ' + [...stack].join('->') + '->' + prop);
6768
}
6869
stack.add(prop);
@@ -126,21 +127,13 @@ export function _descriptors(proxy) {
126127
}
127128

128129
function createSubResolver(parentScopes, prop, value) {
129-
const scopes = new Set([value]);
130-
const fallback = _resolve('_fallback', parentScopes.map(scope => scope[prop] || scope));
131-
const keys = [prop];
132-
if (defined(fallback)) {
133-
const resolved = isFunction(fallback) ? fallback(prop, value) : fallback;
134-
keys.unshift(...(isArray(resolved) ? resolved : [resolved]));
135-
}
130+
const set = new Set([value]);
131+
const keys = _resolveSubKeys(parentScopes, prop, value);
136132
for (const key of keys) {
137-
if (!key) {
138-
continue;
139-
}
140133
for (const item of parentScopes) {
141134
const scope = resolveObjectKey(item, key);
142135
if (scope) {
143-
scopes.add(scope);
136+
set.add(scope);
144137
} else if (key !== prop && scope === false) {
145138
// If any of the fallback scopes is explicitly false, return false
146139
// For example, options.hover falls back to options.interaction, when
@@ -149,8 +142,18 @@ function createSubResolver(parentScopes, prop, value) {
149142
}
150143
}
151144
}
152-
parentScopes.forEach(scopes.add, scopes);
153-
return _createResolver([...scopes]);
145+
parentScopes.forEach(set.add, set);
146+
return _createResolver([...set]);
147+
}
148+
149+
function _resolveSubKeys(parentScopes, prop, value) {
150+
const fallback = _resolve('_fallback', parentScopes.map(scope => scope[prop] || scope));
151+
const keys = [prop];
152+
if (defined(fallback)) {
153+
const resolved = isFunction(fallback) ? fallback(prop, value) : fallback;
154+
keys.unshift(...(isArray(resolved) ? resolved : [resolved]));
155+
}
156+
return keys.filter(v => v);
154157
}
155158

156159
function _resolveWithPrefixes(prop, prefixes, scopes) {

0 commit comments

Comments
 (0)