-
Notifications
You must be signed in to change notification settings - Fork 25
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
Conversation
Any tests ? |
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. |
f98752f
to
b7f8070
Compare
c21fb42
to
d48e84e
Compare
05bdbce
to
bcadc1d
Compare
There was a problem hiding this 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is C
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C
is Consistency!
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because TS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это выражение и так априори boolean
There was a problem hiding this comment.
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 }) => { |
There was a problem hiding this comment.
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) || '_'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 }) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ;-(
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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' } } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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": "*" | ||
}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
This comment was marked as outdated.
Sorry, something went wrong.
|
||
const entity = obj.entity && entityParse(obj.entity); | ||
if (entity && !isValid(entity, obj)) { | ||
return { cell: null, isMatch: false }; |
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
veged protiff
22ab728
to
bdf1a05
Compare
|
const resc = s => String(s).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); | ||
|
||
const SCHEMES = { | ||
flat: ({ wp }) => [ |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is strange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не, всё норм. Можно переписать условие, но иногда isMatch не указан вообще, короче, так надо
packages/walk/lib/index.js
Outdated
// 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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
????
packages/walk/lib/index.js
Outdated
const defaults = options.defaults || {}; | ||
// const isLegacyDefaults = 'scheme' in defaults; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
packages/walk/lib/index.js
Outdated
const defaultWalker = (typeof defaults.scheme === 'string' ? walkers[defaults.scheme] : defaults.scheme) | ||
|| walkers.nested; | ||
const defaultNaming = defaults.naming || {}; | ||
// const defaultsNamingFs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
packages/walk/lib/index.js
Outdated
}); | ||
|
||
// const scheme = config && config.scheme; | ||
const walker = walkers.sdk; // typeof scheme === 'string' ? walkers[scheme] : (scheme || defaultWalker); |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
There was a problem hiding this 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?
993718e
to
050ebab
Compare
050ebab
to
90334d3
Compare
94b5c64
to
89c9691
Compare
89c9691
to
76f33f2
Compare
Closes #276
cc @Vittly