-
Notifications
You must be signed in to change notification settings - Fork 530
/
outputReferencesFilter.js
32 lines (29 loc) · 1.28 KB
/
outputReferencesFilter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import GroupMessages from '../groupMessages.js';
import { getReferences } from './getReferences.js';
const FILTER_WARNINGS = GroupMessages.GROUP.FilteredOutputReferences;
/**
* @typedef {import('../../../types/DesignToken.ts').TransformedToken} TransformedToken
* @typedef {import('../../../types/DesignToken.ts').Dictionary} Dictionary
*
* @param {TransformedToken} token
* @param {{ dictionary: Dictionary, usesDtcg?: boolean }} dictionary
* @returns
*/
export function outputReferencesFilter(token, { dictionary, usesDtcg }) {
const originalValue = usesDtcg ? token.original.$value : token.original.value;
// get refs, pass unfilteredTokens to ensure we find the refs even if they are filtered out
const refs = getReferences(originalValue, dictionary.tokens, {
unfilteredTokens: dictionary.unfilteredTokens,
usesDtcg,
warnImmediately: false,
});
return refs.every((ref) => {
// check whether every ref can be found in the filtered set of tokens
const foundToken = dictionary.allTokens.find((token) => token.name === ref.name);
if (!foundToken) {
// remove the warning about this ref being filtered out, since we now prevent it from outputting it as a ref
GroupMessages.remove(FILTER_WARNINGS, ref.path.join('.'));
}
return !!foundToken;
});
}