Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alias @ for symbol start entity #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ sudo: false
language: node_js

node_js:
- "0.12"
- "4"
- "5"
- "6"
- "8"
- "node"

branches:
only:
Expand Down
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilyar может стоит объединить это с обходом на 33 строке?. Зачем 2 раза делать практически аналогичные операции?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это не возможно т.к. walkAtRules обходит rule типа atrule, walkRules обходит rule типа rule, возможно это получится объединить если использовать walk
https://t.me/bem_ru/24592

@belozer почему возникает желание объединить?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Думаю будет верно подумать в сторону выделить процесс разбора в отдельный метод.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilyar не так прочитал метод )

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@belozer а что думаешь о предложении?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilyar пока размышляю над #8 Хочется добиться максимальной валидности и однозначности.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Скорее всего будет bem-scope стиль. Наиболее близкий к ванильному css

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