Skip to content

Commit ae4ebca

Browse files
author
Brian Lonsdorf
committed
build restrict tree of abstract component comma separated
1 parent 7b100e5 commit ae4ebca

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

lib/__tests__/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ describe('parser', () => {
4848
const restrictee = table.get('restrictees').first()
4949
expect(restrictee.getIn(['annotations', 'selector'])).toEqual('.slds-table')
5050
})
51+
it('does not add itself as a restrictee', () => {
52+
expect(table.get('restrictees').first().get('id')).toEqual('basic')
53+
})
5154
it('does not place overly verbose restricts on outter mentioned elements', () => {
5255
// slds-is-sortable__icon restrict looks like
5356
// @restrict .slds-table--fixed-layout th.slds-is-sortable .slds-icon

lib/comment.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ module.exports = repo => {
3030

3131
// decorateWithRestrictees :: Component -> Component
3232
const decorateWithRestrictees = comp =>
33-
repo.findFirstVariant(getSelector(comp))
34-
.map(setId)
33+
repo.findFirstVariants(getSelector(comp))
34+
.map(vs => vs.map(setId))
3535
.fold(l => comp.set('restrictees', List()),
36-
v => comp.set('restrictees', List.of(recurse(Map(), v))))
36+
vs => comp.set('restrictees', vs.map(v => recurse(Map(), v))))
3737

3838
// setId :: Comment -> Comment
3939
const setId = comment =>

lib/repository.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
22
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
33

4-
const { Right, Left, fromNullable } = require('data.either')
5-
const { List, Map, OrderedSet } = require('immutable-ext')
4+
const Either = require('data.either')
5+
const { Right, Left, fromNullable } = Either
6+
const { List, Map, OrderedSet, Set } = require('immutable-ext')
67

78
const { toTree } = require('./tree')
89
const { find } = require('./utils')
@@ -83,9 +84,16 @@ module.exports = comments => {
8384
const findAllBySelector = selector =>
8485
utils.filter(comment => selectorMatches('selector', selector, comment))
8586

86-
// findFirstVariant :: String -> Either Null Variant
87-
const findFirstVariant = selector =>
88-
find(variants(comments), v => getSelector(v) === selector)
87+
// findFirstVariants :: String -> Either Null Variant
88+
const findFirstVariants = selector =>
89+
Either.of(selector.split(','))
90+
.map(xs => xs.map(x => x.trim()))
91+
.map(xs => Set(xs))
92+
.map(selectors =>
93+
variants(comments)
94+
.filter(v =>
95+
selectors.has(getSelector(v))))
96+
.map(xs => xs.toList())
8997

9098
// findVariants :: Component -> List Variant
9199
const findVariants = comp =>
@@ -128,7 +136,7 @@ module.exports = comments => {
128136
findModifier,
129137
findComponent,
130138
findUtility,
131-
findFirstVariant,
139+
findFirstVariants,
132140
findAllByRestrict,
133141
findAllBySelector,
134142
findVariants

0 commit comments

Comments
 (0)