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 bdd3b96 commit 06b17fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ function buildSelector (ctx, mod) {
export default postcss.plugin('pobem', () => (css) => {
css.walkRules((rule) => {
rule.selector = rule.selector
.replace(/[.:]?(block\(.+)/g, (match, raw) => {
.replace(/[.:@]?(block\(.+)/g, (match, raw) => {
// "block(b1).elem(elem).mod(mod)" -> "block(b1) elem(elem) mod(mod)"
const rawSelector = raw
.replace(/[.:]?(block|elem|mod)(\([\s\w'"\->,]+\))/g, '=b=$1$2=b=')
.replace(/[.:@]?(block|elem|mod)(\([\s\w'"\->,]+\))/g, '=b=$1$2=b=')
.replace(/block(\([\s\w'"\->,]+\))=b=\s*=b=(elem|mod)/g, 'block$1=b=$2')
.replace(/elem(\([\s\w'"\->,]+\))=b=\s*=b=(mod)/g, 'elem$1=b=$2')
.replace(/mod(\([\s\w'"\->,]+\))=b=\s*=b=(mod)/g, 'mod$1=b=$2');
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 06b17fe

Please sign in to comment.