Skip to content

Commit

Permalink
bem-contrib#6 Add alias @ for symbol start entity
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyar committed Mar 25, 2018
1 parent f141069 commit a7fbdcf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ function buildSelector (ctx, mod) {
}

export default postcss.plugin('pobem', () => (css) => {
css.walkAtRules(/block|elem|mod/, function (rule) {
rule.replaceWith(postcss.rule({
selector: rule.name + rule.params,
nodes: rule.nodes,
raws: rule.raws,
source: rule.source
}));
});
css.walkRules((rule) => {
rule.selector = rule.selector
.replace(/[.:]?(block\(.+)/g, (match, raw) => {
Expand Down
25 changes: 25 additions & 0 deletions test/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@ const test = (selector, result) => {
};

describe('plugin', () => {
describe('Aliases for start entity', () => {
it('dot', () => {
test(
'.block(foo)',
'.foo'
);
});
it('colon', () => {
test(
':block(foo)',
'.foo'
);
});
it('at', () => {
test(
'@block(foo)',
'.foo'
);
test(
'@media',
'@media'
);
});
});

describe('block', () => {
it('simple', () => {
test(
Expand Down

0 comments on commit a7fbdcf

Please sign in to comment.