Skip to content

Commit 9f7648c

Browse files
committed
feat(import-notation): add expand to api
1 parent 17e05a6 commit 9f7648c

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

packages/import-notation/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const BemCellSet = hashSet(helpers.stringifyCell);
2323
function parse(importString, ctx) {
2424
const cell = {};
2525

26-
ctx && (importString = helpers.expand(importString, ctx));
26+
ctx && (importString = expand(importString, ctx));
2727

2828
return Array.from(importString.split(' ').reduce((acc, importToken) => {
2929
const split = importToken.split(':'),
@@ -92,5 +92,6 @@ function stringify(cells) {
9292

9393
module.exports = {
9494
parse,
95-
stringify
95+
stringify,
96+
expand: helpers.expand
9697
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var expect = require('chai').expect,
2+
e = require('..').expand;
3+
4+
it('should return notation if no ctx specified', () => {
5+
expect(e('b:button')).to.eql('b:button');
6+
});
7+
8+
describe('ctx', () => {
9+
describe('block', () => {
10+
it('should copy block if notation has no block', () => {
11+
expect(e('e:icon', { block: 'button' })).to.eql('b:button e:icon');
12+
});
13+
14+
it('should not copy block if notation has block', () => {
15+
expect(e('b:button e:icon', { block: 'input' })).to.eql('b:button e:icon');
16+
});
17+
});
18+
19+
describe('elem', () => {
20+
it('should copy elem if notation has no elem', () => {
21+
expect(e('m:theme=default', { block: 'button', elem: 'icon' })).to.eql('b:button e:icon m:theme=default');
22+
});
23+
24+
it('should not copy elem if notation has elem', () => {
25+
expect(e('b:button e:icon', { block: 'input', elem: 'clear' })).to.eql('b:button e:icon');
26+
});
27+
});
28+
});

0 commit comments

Comments
 (0)