Skip to content

Commit 54316b0

Browse files
IanVSgajus
authored andcommitted
fix: set default handleMissingStyleName option (#129)
The default was not being set for non-namespaced styles. This caused a bug where errors were not thrown for runtime style names, since the options are not passed in if they are only the defaults.
1 parent 17d261e commit 54316b0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/getClassName.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import type {
66
HandleMissingStyleNameOptionType
77
} from './types';
88

9+
const DEFAULT_HANDLE_MISSING_STYLENAME_OPTION = 'throw';
10+
911
const isNamespacedStyleName = (styleName: string): boolean => {
1012
return styleName.indexOf('.') !== -1;
1113
};
@@ -21,7 +23,8 @@ const getClassNameForNamespacedStyleName = (
2123
const styleNameParts = styleName.split('.');
2224
const importName = styleNameParts[0];
2325
const moduleName = styleNameParts[1];
24-
const handleMissingStyleName = handleMissingStyleNameOption || 'throw';
26+
const handleMissingStyleName = handleMissingStyleNameOption ||
27+
DEFAULT_HANDLE_MISSING_STYLENAME_OPTION;
2528

2629
if (!moduleName) {
2730
if (handleMissingStyleName === 'throw') {
@@ -66,7 +69,8 @@ type OptionsType = {|
6669
export default (styleNameValue: string, styleModuleImportMap: StyleModuleImportMapType, options?: OptionsType): string => {
6770
const styleModuleImportMapKeys = Object.keys(styleModuleImportMap);
6871

69-
const handleMissingStyleName = options && options.handleMissingStyleName;
72+
const handleMissingStyleName = options && options.handleMissingStyleName ||
73+
DEFAULT_HANDLE_MISSING_STYLENAME_OPTION;
7074

7175
return styleNameValue
7276
.split(' ')

0 commit comments

Comments
 (0)