diff --git a/lib/entity-name.js b/lib/entity-name.js index e9df938..0757473 100644 --- a/lib/entity-name.js +++ b/lib/entity-name.js @@ -2,8 +2,6 @@ const util = require('util'); -const stringifyEntity = require('@bem/naming').stringify; - const deprecate = require('./deprecate'); const EntityTypeError = require('./entity-type-error'); @@ -205,7 +203,12 @@ class BemEntityName { get id() { if (this._id) { return this._id; } - this._id = stringifyEntity(this._data); + const e = this._data; + + this._id = e.block + + (!e.elem ? '' : '__' + e.elem) + + (!e.mod ? '' : '_' + e.mod.name + + (e.mod.val === true ? '' : '_' + e.mod.val)); return this._id; } diff --git a/package.json b/package.json index 0f03658..925f244 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "node": ">= 4.0" }, "dependencies": { - "@bem/naming": "2.0.0-5", "depd": "1.1.0", "es6-error": "4.0.2" }, diff --git a/test/id.test.js b/test/id.test.js index fa43eb3..77052ae 100644 --- a/test/id.test.js +++ b/test/id.test.js @@ -1,6 +1,4 @@ import test from 'ava'; -import sinon from 'sinon'; -import proxyquire from 'proxyquire'; import BemEntityName from '..'; @@ -18,19 +16,10 @@ test('should build not equal id for not equal blocks', t => { t.not(entityName1.id, entityName2.id); }); -test('should cache id value', t => { - const stub = sinon.stub().returns('id'); - const StubBemEntityName = proxyquire('../lib/entity-name', { - '@bem/naming': { - stringify: stub - } - }); - - const entityName = new StubBemEntityName({ block: 'block' }); - - /*eslint no-unused-expressions: "off"*/ - entityName.id; - entityName.id; +test('should cache id for repeating calls', t => { + const entityName1 = new BemEntityName({ block: 'block1' }); + const id = entityName1.id; - t.is(stub.callCount, 1); + entityName1._data = {}; + t.is(id, entityName1.id); }); diff --git a/test/to-string.test.js b/test/to-string.test.js index 1d15be7..a93ccd1 100644 --- a/test/to-string.test.js +++ b/test/to-string.test.js @@ -1,42 +1,38 @@ import test from 'ava'; -import sinon from 'sinon'; -import proxyquire from 'proxyquire'; - -const spy = sinon.spy(); -const BemEntityName = proxyquire('../lib/entity-name', { - '@bem/naming': { - stringify: spy - } -}); +import BemEntityName from '..'; -test('should use `naming.stringify()` for block', t => { +test('should stringify block entity name', t => { const entityName = new BemEntityName({ block: 'block' }); - entityName.toString(); - - t.true(spy.calledWith({ block: 'block' })); + t.is(entityName.toString(), 'block'); }); -test('should use `naming.stringify()` for elem', t => { +test('should stringify elem entity name', t => { const entityName = new BemEntityName({ block: 'block', elem: 'elem' }); - entityName.toString(); + t.is(entityName.toString(), 'block__elem'); +}); + +test('should stringify block’s simple modifier entity name', t => { + const entityName = new BemEntityName({ block: 'block', mod: { name: 'mod', val: true } }); - t.true(spy.calledWith({ block: 'block', elem: 'elem' })); + t.is(entityName.toString(), 'block_mod'); }); -test('should use `naming.stringify()` for block modifier', t => { +test('should stringify block’s modifier entity name', t => { const entityName = new BemEntityName({ block: 'block', mod: { name: 'mod', val: 'val' } }); - entityName.toString(); + t.is(entityName.toString(), 'block_mod_val'); +}); + +test('should stringify element’s simple modifier entity name', t => { + const entityName = new BemEntityName({ block: 'block', elem: 'elem', mod: { name: 'mod', val: true } }); - t.true(spy.calledWith({ block: 'block', mod: { name: 'mod', val: 'val' } })); + t.is(entityName.toString(), 'block__elem_mod'); }); -test('should use naming.stringify() for element modifier', t => { +test('should stringify element’s modifier entity name', t => { const entityName = new BemEntityName({ block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } }); - entityName.toString(); - - t.true(spy.calledWith({ block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } })); + t.is(entityName.toString(), 'block__elem_mod_val'); });