@@ -6,49 +6,53 @@ import type {
66} from './types' ;
77
88const isNamespacedStyleName = ( styleName : string ) : boolean => {
9- return styleName . includes ( '.' ) ;
9+ return styleName . indexOf ( '.' ) !== - 1 ;
1010} ;
1111
1212const getClassNameForNamespacedStyleName = ( styleName : string , styleModuleImportMap : StyleModuleImportMapType ) : string => {
13- const [
14- importName ,
15- moduleName
16- ] = styleName . split ( '.' ) ;
13+ // Note:
14+ // Do not use the desctructing syntax with Babel.
15+ // Desctructing adds _slicedToArray helper.
16+ const styleNameParts = styleName . split ( '.' ) ;
17+ const importName = styleNameParts [ 0 ] ;
18+ const moduleName = styleNameParts [ 1 ] ;
1719
1820 if ( ! moduleName ) {
1921 throw new Error ( 'Invalid style name.' ) ;
2022 }
2123
22- if ( ! styleModuleImportMap . hasOwnProperty ( importName ) ) {
24+ if ( ! styleModuleImportMap [ importName ] ) {
2325 throw new Error ( 'Import does not exist.' ) ;
2426 }
2527
26- if ( ! styleModuleImportMap [ importName ] . hasOwnProperty ( moduleName ) ) {
28+ if ( ! styleModuleImportMap [ importName ] [ moduleName ] ) {
2729 throw new Error ( 'Module does not exist.' ) ;
2830 }
2931
3032 return styleModuleImportMap [ importName ] [ moduleName ] ;
3133} ;
3234
3335export default ( styleNameValue : string , styleModuleImportMap : StyleModuleImportMapType ) : string => {
36+ const styleModuleImportMapKeys = Object . keys ( styleModuleImportMap ) ;
37+
3438 return styleNameValue
3539 . split ( ' ' )
3640 . map ( ( styleName ) => {
3741 if ( isNamespacedStyleName ( styleName ) ) {
3842 return getClassNameForNamespacedStyleName ( styleName , styleModuleImportMap ) ;
3943 }
4044
41- if ( Object . keys ( styleModuleImportMap ) . length === 0 ) {
45+ if ( styleModuleImportMapKeys . length === 0 ) {
4246 throw new Error ( 'Cannot use styleName attribute without importing at least one stylesheet.' ) ;
4347 }
4448
45- if ( Object . keys ( styleModuleImportMap ) . length > 1 ) {
49+ if ( styleModuleImportMapKeys . length > 1 ) {
4650 throw new Error ( 'Cannot use anonymous style name with more than one stylesheet import.' ) ;
4751 }
4852
49- const styleModuleMap : StyleModuleMapType = styleModuleImportMap [ Object . keys ( styleModuleImportMap ) [ 0 ] ] ;
53+ const styleModuleMap : StyleModuleMapType = styleModuleImportMap [ styleModuleImportMapKeys [ 0 ] ] ;
5054
51- if ( ! styleModuleMap . hasOwnProperty ( styleName ) ) {
55+ if ( ! styleModuleMap [ styleName ] ) {
5256 throw new Error ( 'Module cannot be resolved.' ) ;
5357 }
5458
0 commit comments