Skip to content

Commit

Permalink
#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 bdd3b96 commit d0e932b
Show file tree
Hide file tree
Showing 2 changed files with 23 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(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
15 changes: 15 additions & 0 deletions test/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ 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'
));
});

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

0 comments on commit d0e932b

Please sign in to comment.