Skip to content

Commit d0b47f9

Browse files
authored
fix(processing): filter null values during strict theme processing (#87)
1 parent e30a28b commit d0b47f9

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

packages/processor/js/src/processor/meta/metaProcessor.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { MappingMetaType } from '../mapping/mappingProcessor';
99
import { Processor } from '../processor';
1010
import {
1111
createAllStyles,
12+
isNil,
1213
toObject,
1314
} from '../../service';
1415

@@ -51,13 +52,10 @@ export class MetaProcessor implements Processor<MappingProcessorParamsType, Them
5152
}
5253

5354
private getStrictThemeValue(name: string, theme: StrictTheme, fallback?: any) {
55+
const key: string = this.isReference(name) ? this.createKeyFromReference(name) : name;
56+
const value = this.findValue(key, theme);
5457

55-
if (this.isReference(name)) {
56-
const themeKey: string = this.createKeyFromReference(name);
57-
return this.findValue(themeKey, theme) || fallback;
58-
}
59-
60-
return this.findValue(name, theme) || fallback;
58+
return isNil(value) ? fallback : value;
6159
}
6260

6361
private findValue(name: string, theme: StrictTheme): string {

packages/processor/js/src/service/common/common.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,14 @@ export function toObject(array: [string, any][]): any {
6464
return p;
6565
}, {});
6666
}
67+
68+
/**
69+
* Check value for null or undefined
70+
*
71+
*
72+
* @return boolean
73+
* @param value
74+
*/
75+
export function isNil(value: any): boolean {
76+
return value === undefined || value === null;
77+
}

packages/processor/js/src/service/style/style.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
safe,
1212
noNulls,
1313
noDuplicates,
14+
isNil,
1415
} from '../common';
1516
import {
1617
getComponentDefaultAppearance,
@@ -292,7 +293,7 @@ function createStateVariations(states: string[], separator: string, result: stri
292293
function withStrictTokens(mapping: StatelessMappingType, theme: ThemedStyleType): StatelessMappingType {
293294
return Object.keys(mapping).reduce((acc: StatelessMappingType, next: string): StatelessMappingType => {
294295
const currentToken: ParameterType = mapping[next];
295-
const nextToken: ParameterType = theme[currentToken] || currentToken;
296+
const nextToken: ParameterType = isNil(theme[currentToken]) ? currentToken : theme[currentToken];
296297

297298
return { ...acc, [next]: nextToken };
298299
}, {});

0 commit comments

Comments
 (0)