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

naming.cell.parse implementation #281

Merged
merged 8 commits into from
Jul 1, 2018
Merged

naming.cell.parse implementation #281

merged 8 commits into from
Jul 1, 2018

Conversation

qfox
Copy link
Member

@qfox qfox commented Feb 5, 2018

Closes #276

cc @Vittly

@Vittly
Copy link
Collaborator

Vittly commented Feb 6, 2018

Any tests ?

@qfox
Copy link
Member Author

qfox commented Feb 6, 2018

This code was in Sublime's cache since October... Better here in branch than in my local cache.

Anyway it's a nice start I guess to make what you need.

@qfox
Copy link
Member Author

qfox commented Apr 6, 2018

cc @blond @tadatuta

Guess it's time to review.

@qfox qfox force-pushed the qfox.naming-cell-parse branch from 05bdbce to bcadc1d Compare April 6, 2018 00:32
Copy link
Member

@awinogradov awinogradov left a comment

Choose a reason for hiding this comment

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

Please add implementation for nested modern schema with platform folder inside block.

@@ -287,7 +287,8 @@ module.exports = class BemCell {
* @returns {boolean} A Boolean indicating whether or not specified entity is instance of BemCell.
*/
static isBemCell(cell) {
return !!cell && Boolean(cell.__isBemCell__);
const C = cell && cell.constructor;
return C === this || Boolean(C && cell.__isBemCell__ && C !== Object);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is C ?

Copy link
Member Author

Choose a reason for hiding this comment

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

C is Consistency!

Copy link
Contributor

Choose a reason for hiding this comment

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

For what is to Boolean ?

Copy link
Member Author

Choose a reason for hiding this comment

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

because TS

Copy link
Contributor

Choose a reason for hiding this comment

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

это выражение и так априори boolean

Copy link
Member Author

Choose a reason for hiding this comment

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

нет

const ALPHANUM_RE = '[a-z][\\w\\-]*';
const resc = s => String(s).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');

const buildPathParseMethod = ({ fs: { pattern, delims: dd = {}, scheme = 'nested' }, delims, wordPattern: wp = ALPHANUM_RE }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like we need a default preset. Now some defaults are located inside "naming.cell.match" package. It is not obvious

const separation = pathPatternParser(pattern);

const dElem = 'elem' in dd ? dd.elem : (delims.elem || '__');
const dMod = 'mod' in dd ? dd.mod : (Object(delims.mod).name || (typeof delims.mod === 'string' && delims.mod) || '_');
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code is very similar to this. Not right

Copy link
Member Author

Choose a reason for hiding this comment

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

Need to move it to BemNamingConvention container too.

Fix planned in #304


const entityRe = ({
flat: [`(?:(${wp})(?:/(${ALPHANUM_RE})`, ')?)?', (entity, { dir }) => (entity.block === dir)],
nested: [`(?:(${wp}(?:|/${dElem}${wp})?(?:|/${dMod}${wp})?)(?:/(${ALPHANUM_RE})`, ')?)?', (entity, { dir }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Too complex for me. Can we write here a helper? Now I need to take a pencil/paper and start count braces

Copy link
Member Author

Choose a reason for hiding this comment

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

Why you should count it? Who or what forces you to do it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Guess we need to move it out to separate package along with scheme path builders.

Probably it should be #304 for a while.

let i = 1;
return entity.block === parts[0] &&
(!entity.elem || (parts[i++] === dElem + entity.elem)) &&
(!entity.mod || (parts[i++] == dMod + entity.mod.name));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very hard to read this

Copy link
Member Author

Choose a reason for hiding this comment

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

That's why we have tests. And me.

const safeEval = require('node-eval');

const BemCell = require('@bem/sdk.cell');
const { origin } = require('@bem/sdk.naming.presets');
Copy link
Collaborator

Choose a reason for hiding this comment

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

We use destructuring assignment but we aware of spread in object expression (using Object.assgin). Why?

Copy link
Collaborator

Choose a reason for hiding this comment

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

"package.json" declares node 4 and it has no support of destructuring http://node.green/#ES2015-syntax-destructuring--assignment

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I guess if we need node 4 then we need to fix it.

I'm just living in the future ;-(

Copy link
Member Author

Choose a reason for hiding this comment

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

We decided to drop 4.x support so it can be left as is.

describe('naming.cell.match', () => {
for (const [dTitle, [match, its]] of Object.entries({
'flat / origin': [flatOriginMatch, rawses`
reject invalid → blocks → { isMatch: false }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't why is it better than classic describe/it

Copy link
Member Author

Choose a reason for hiding this comment

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

Just to reduce amount of code and increase readability of tests.

rejects alien block mod2 → dd.blocks/qq/bb_m_v.t → { isMatch: false }
rejects alien elem → dd.blocks/qq/bb__e.t → { isMatch: false }
rejects alien elem mod → dd.blocks/qq/bb__e_m.t → { isMatch: false }
rejects alien elem mod2 → dd.blocks/qq/bb__e_m_v.t → { isMatch: false }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something went wrong with tabs before the arrow

Copy link
Member Author

Choose a reason for hiding this comment

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

They are spaces ;-D

reject invalid block → button/button → { cell: null, isMatch: false }
match partial block path → blocks → { cell: null, isMatch: true }
parse typical block path → blocks/blocks.css → { cell: { layer: 'common', block: 'blocks', tech: 'css' } }
parse typical block in layer → blocks/[email protected] → { cell: { layer: 'ios', block: 'blocks', tech: 'css' } }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wow! So here is a modern scheme. Want to see it nested

Copy link
Member Author

Choose a reason for hiding this comment

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

Something like:

bb/bb.t                # previously common.blocks/bb/bb.t
bb/[email protected]        # previously desktop.blocks/bb/bb.t
bb/[email protected]          # previously touch.blocks/bb/bb.t
bb/_e/bb_e.t           # previously common.blocks/bb/_e/bb_e.t
bb/_e/[email protected]   # previously desktop.blocks/bb/_e/bb_e.t
bb/__m/bb__m.t         # previously common.blocks/bb/__m/bb__m.t
bb/__m/[email protected] # previously desktop.blocks/bb/__m/bb__m.t

Copy link
Member Author

Choose a reason for hiding this comment

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

In the end I want to support this: bem-sdk-archive/bem-walk#77 (comment)

},
"devDependencies": {
"@bem/sdk.naming.presets": "*"
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cannot fine "node-eval", "mocha", "nyc", "chai" in your deps

Copy link
Member Author

@qfox qfox Apr 11, 2018

Choose a reason for hiding this comment

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

They are in root package.json, shared between subpackages

Copy link
Member

@Yeti-or Yeti-or left a comment

Choose a reason for hiding this comment

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

my eyes are bleeding
but it's seems to work fine

* Stringifier generator
*
* @param {BemNamingConvention} conv - naming, path and scheme
* @returns {function(BemCell): string} converts cell to file path
Copy link
Member Author

Choose a reason for hiding this comment

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

na vhod string

r[key] = res[i+1];
}
return r;
}, {});

This comment was marked as outdated.


const entity = obj.entity && entityParse(obj.entity);
if (entity && !isValid(entity, obj)) {
return { cell: null, isMatch: false };
Copy link
Member Author

Choose a reason for hiding this comment

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

vynesti naverh peredachu entityParse

}

const cell = entity ? BemCell.create(Object.assign({ layer }, obj, { entity })) : null;
return !obj.rest ? { cell, isMatch: true } : { cell, isMatch: false, rest: obj.rest };
Copy link
Member Author

Choose a reason for hiding this comment

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

veged protiff

@qfox qfox force-pushed the qfox.naming-cell-parse branch from 22ab728 to bdf1a05 Compare June 29, 2018 01:03
@tadatuta
Copy link
Member

  1. тесты попадали из-за линтера и es6
  2. появились заскипы — это точно норм?

const resc = s => String(s).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');

const SCHEMES = {
flat: ({ wp }) => [
Copy link
Contributor

Choose a reason for hiding this comment

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

empty arsgs

/**
* [description]
* @param {[type]} relPath [description]
* @return {[type]} [description]
Copy link
Contributor

Choose a reason for hiding this comment

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

nice docs bro

...safeEval(`(${rawExpected})`)
};
expected.cell = expected.cell ? BemCell.create(expected.cell).id : null;
expected.isMatch = expected.isMatch === false ? false : Boolean(expected.isMatch || expected.cell);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is strange

Copy link
Member Author

Choose a reason for hiding this comment

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

Не, всё норм. Можно переписать условие, но иногда isMatch не указан вообще, короче, так надо

// walk(['node_modules/islands', 'contribs/search-header'], config);

// TODO: Warn about old using old walkers
// assert(defaults.scheme, 'sdk/walk: Please stop using old API');
Copy link
Contributor

Choose a reason for hiding this comment

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

????

const defaults = options.defaults || {};
// const isLegacyDefaults = 'scheme' in defaults;
Copy link
Contributor

Choose a reason for hiding this comment

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

???

const defaultWalker = (typeof defaults.scheme === 'string' ? walkers[defaults.scheme] : defaults.scheme)
|| walkers.nested;
const defaultNaming = defaults.naming || {};
// const defaultsNamingFs
Copy link
Contributor

Choose a reason for hiding this comment

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

???

});

// const scheme = config && config.scheme;
const walker = walkers.sdk; // typeof scheme === 'string' ? walkers[scheme] : (scheme || defaultWalker);
Copy link
Contributor

Choose a reason for hiding this comment

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

???

@@ -13,7 +13,7 @@ const mockFs = require('mock-fs');

const walkers = require('../../lib/walkers');

describe('core/defaults', () => {
describe.skip('core/defaults', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

???

@@ -13,7 +13,7 @@ const mockFs = require('mock-fs');

const walkers = require('../../lib/walkers');

describe('core/walkers', () => {
describe.skip('core/walkers', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

???

Copy link
Contributor

@birhoff birhoff left a comment

Choose a reason for hiding this comment

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

very shitty docs
code inconsistency es3/es6
jsdoc lint?

@qfox qfox force-pushed the qfox.naming-cell-parse branch 3 times, most recently from 993718e to 050ebab Compare June 30, 2018 19:52
@qfox qfox force-pushed the qfox.naming-cell-parse branch from 050ebab to 90334d3 Compare June 30, 2018 23:45
@qfox qfox force-pushed the qfox.naming-cell-parse branch from 94b5c64 to 89c9691 Compare July 1, 2018 22:10
@qfox qfox force-pushed the qfox.naming-cell-parse branch from 89c9691 to 76f33f2 Compare July 1, 2018 22:46
@qfox qfox merged commit c46110d into master Jul 1, 2018
@qfox qfox deleted the qfox.naming-cell-parse branch July 1, 2018 22:50
@qfox qfox mentioned this pull request Jul 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants