This repository was archived by the owner on Feb 4, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +5
-55
lines changed Expand file tree Collapse file tree 2 files changed +5
-55
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ const assert = require ( 'assert' ) ;
3
4
const util = require ( 'util' ) ;
4
5
5
6
const stringifyEntity = require ( 'bem-naming' ) . stringify ;
7
+ const parseEntity = require ( 'bem-naming' ) . parse ;
6
8
7
9
/**
8
10
* Enum for types of BEM entities.
@@ -30,26 +32,13 @@ module.exports = class BemEntityName {
30
32
* Used if neither `mod.val` nor `val` were not specified.
31
33
*/
32
34
constructor ( obj ) {
33
- if ( ! obj . block ) {
34
- throw new Error ( 'This is not valid BEM entity: the field `block` is undefined.' ) ;
35
- }
35
+ assert ( obj . block , 'This is not valid BEM entity: the field `block` is undefined.' ) ;
36
+ assert ( ! obj . mod || obj . mod . name , 'This is not valid BEM entity: the field `mod.name` is undefined.' ) ;
36
37
37
38
const data = this . _data = { block : obj . block } ;
38
39
39
40
obj . elem && ( data . elem = obj . elem ) ;
40
-
41
- const modObj = obj . mod ;
42
- const modName = ( typeof modObj === 'string' ? modObj : modObj && modObj . name ) || obj . modName ;
43
- const hasModVal = modObj && modObj . hasOwnProperty ( 'val' ) || obj . hasOwnProperty ( 'modVal' ) ;
44
-
45
- if ( modName ) {
46
- data . mod = {
47
- name : modName ,
48
- val : hasModVal ? modObj && modObj . val || obj . modVal : true
49
- } ;
50
- } else if ( modObj || hasModVal ) {
51
- throw new Error ( 'This is not valid BEM entity: the field `mod.name` is undefined.' ) ;
52
- }
41
+ obj . mod && ( data . mod = { name : obj . mod . name , val : obj . mod . val || true } ) ;
53
42
54
43
this . __isBemEntityName__ = true ;
55
44
}
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments