Skip to content

Commit 5aabe53

Browse files
committed
fix: handle unconfigured handleMissingStyleNameOption (gajus#121)
1 parent 578b417 commit 5aabe53

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/getClassName.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,19 @@ type OptionsType = {|
6363
handleMissingStyleName: HandleMissingStyleNameOptionType
6464
|};
6565

66-
export default (styleNameValue: string, styleModuleImportMap: StyleModuleImportMapType, options: OptionsType): string => {
66+
export default (styleNameValue: string, styleModuleImportMap: StyleModuleImportMapType, options?: OptionsType): string => {
6767
const styleModuleImportMapKeys = Object.keys(styleModuleImportMap);
6868

69+
const handleMissingStyleName = options && options.handleMissingStyleName;
70+
6971
return styleNameValue
7072
.split(' ')
7173
.filter((styleName) => {
7274
return styleName;
7375
})
7476
.map((styleName) => {
7577
if (isNamespacedStyleName(styleName)) {
76-
return getClassNameForNamespacedStyleName(styleName, styleModuleImportMap, options.handleMissingStyleName);
78+
return getClassNameForNamespacedStyleName(styleName, styleModuleImportMap, handleMissingStyleName);
7779
}
7880

7981
if (styleModuleImportMapKeys.length === 0) {
@@ -87,10 +89,10 @@ export default (styleNameValue: string, styleModuleImportMap: StyleModuleImportM
8789
const styleModuleMap: StyleModuleMapType = styleModuleImportMap[styleModuleImportMapKeys[0]];
8890

8991
if (!styleModuleMap[styleName]) {
90-
if (options.handleMissingStyleName === 'throw') {
92+
if (handleMissingStyleName === 'throw') {
9193
throw new Error('Could not resolve the styleName \'' + styleName + '\'.');
9294
}
93-
if (options.handleMissingStyleName === 'warn') {
95+
if (handleMissingStyleName === 'warn') {
9496
// eslint-disable-next-line no-console
9597
console.warn('Could not resolve the styleName \'' + styleName + '\'.');
9698
}

src/index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,16 @@ export default ({
187187
return;
188188
}
189189

190+
const handleMissingStyleName = stats.opts && stats.opts.handleMissingStyleName || optionsDefaults.handleMissingStyleName;
191+
190192
if (t.isStringLiteral(styleNameAttribute.value)) {
191193
resolveStringLiteral(
192194
path,
193195
filenameMap[filename].styleModuleImportMap,
194196
styleNameAttribute,
195-
{handleMissingStyleName: stats.opts.handleMissingStyleName || optionsDefaults.handleMissingStyleName}
197+
{
198+
handleMissingStyleName
199+
}
196200
);
197201

198202
return;
@@ -208,7 +212,9 @@ export default ({
208212
styleNameAttribute,
209213
filenameMap[filename].importedHelperIndentifier,
210214
filenameMap[filename].styleModuleImportMapIdentifier,
211-
{handleMissingStyleName: stats.opts.handleMissingStyleName || optionsDefaults.handleMissingStyleName}
215+
{
216+
handleMissingStyleName
217+
}
212218
);
213219
}
214220
},

0 commit comments

Comments
 (0)