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

@bem/sdk.naming.cell.match: Некорректно обрабатывает файлы с react неймингом #386

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
1 change: 1 addition & 0 deletions packages/naming.cell.match/cell-match.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ describe('naming.cell.match', () => {
parse typical block path → bb/bb.css → { cell: { layer: 'common', block: 'bb', tech: 'css' } }
parse typical elem path → bb/ee/bb-ee.css → { cell: { layer: 'common', block: 'bb', elem: 'ee', tech: 'css' } }
parse typical block in layer → bb/[email protected] → { cell: { layer: 'ios', block: 'bb', tech: 'css' } }
parse typical block in layer → bb/[email protected] → { cell: { layer: 'touch-phone', block: 'bb', tech: 'css' } }
parse typical mod path → bb/_mod/bb_mod.css → { cell: { layer: 'common', block: 'bb', mod: 'mod', tech: 'css' } }
`]
})) {
Expand Down
7 changes: 4 additions & 3 deletions packages/naming.entity.parse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ const BemEntityName = require('@bem/sdk.entity-name');
*
* @param {INamingConventionDelims} delims — separates entity names from each other.
* @param {String} wordPattern — defines which symbols can be used for block, element and modifier's names.
* @param {String} blockPattern — WIP
* @returns {RegExp}
*/
function buildRegex(delims, wordPattern) {
const block = '(' + wordPattern + ')';
function buildRegex(delims, wordPattern, blockPattern) {
const block = '(' + blockPattern + ')';
Copy link
Member Author

Choose a reason for hiding this comment

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

@zxqfox Нашел место где ломалось, при создании регулярки на вход подается один и тот же шаблон, далее мы парсим строку bb-ee и нам выдает, что это блок, а не элемент, надо придумать, как лучше тут сделать.

const elem = '(?:' + delims.elem + '(' + wordPattern + '))?';
const modName = '(?:' + delims.mod.name + '(' + wordPattern + '))?';
const modVal = '(?:' + delims.mod.val + '(' + wordPattern + '))?';
Expand Down Expand Up @@ -50,7 +51,7 @@ function parse(str, regex) {
* @returns {Function}
*/
module.exports = (convention) => {
const regex = buildRegex(convention.delims, convention.wordPattern);
const regex = buildRegex(convention.delims, convention.wordPattern, convention.blockPattern);

return (str) => parse(str, regex);
};
3 changes: 2 additions & 1 deletion packages/naming.presets/origin-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ module.exports = Object.assign({}, origin, {
fs: Object.assign({}, origin.fs, {
delims: { elem: '' }
}),
wordPattern: '[a-zA-Z0-9]+'
wordPattern: '[a-zA-Z0-9-]+',
blockPattern: '[a-zA-Z0-9]+',
});