Skip to content

Commit 7b100e5

Browse files
author
Brian Lonsdorf
committed
clean up duplicate selectors in hierarchy
1 parent 33a1b41 commit 7b100e5

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

lib/__fixtures__/ui/components/data-tables/advanced/_index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
* Icon inside sortable th
106106
*
107107
* @selector .slds-is-sortable__icon
108-
* @restrict .slds-is-sortable .slds-icon
108+
* @restrict .slds-table--fixed-layout th.slds-is-sortable
109109
*/
110110
.slds-is-sortable__icon {
111111
@include square($square-icon-small-content);

lib/__tests__/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
const fs = require('fs')
55
const glob = require('glob')
66
const path = require('path')
7+
const { List } = require('immutable')
8+
const { toTree } = require('../tree')
79

810
const parser = require('../../')
911

@@ -14,7 +16,7 @@ const scss = glob
1416
)
1517
.join('\n')
1618

17-
const { components, component, utilities, utility } = parser(scss)
19+
const { components, component, utilities, utility, findVariant } = parser(scss)
1820

1921
describe('parser', () => {
2022
describe('components', () => {
@@ -46,6 +48,14 @@ describe('parser', () => {
4648
const restrictee = table.get('restrictees').first()
4749
expect(restrictee.getIn(['annotations', 'selector'])).toEqual('.slds-table')
4850
})
51+
it('does not place overly verbose restricts on outter mentioned elements', () => {
52+
// slds-is-sortable__icon restrict looks like
53+
// @restrict .slds-table--fixed-layout th.slds-is-sortable .slds-icon
54+
const t = toTree(table).reduce((acc, x) =>
55+
acc.push(x.getIn(['annotations', 'selector'])) , List())
56+
const result = t.filter(x => x === '.slds-is-sortable__icon')
57+
expect(result.count()).toEqual(1)
58+
})
4959
})
5060
describe('button', () => {
5161
let button

lib/comment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = repo => {
7070

7171
// findModifier :: Component -> String -> Either Null Variant
7272
const findVariant = (component, id) =>
73-
find(component.get('variants'), x => x.getIn(['annotations', 'name']) === id)
73+
find(repo.variants(toTree(component).toList(List())), x => x.get('id') === id)
7474

7575
return { components, utilities, utility, component, findModifier, findVariant }
7676
}

lib/repository.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ module.exports = comments => {
4444
, List.of(List(), List())).toArray()
4545

4646
// getRestrictKeys :: String -> [Selector]
47+
const getRestrictKeys_ = restrict =>
48+
restrict.match(/(\.[a-zA-Z0-9_-]+)/g)
49+
4750
const getRestrictKeys = restrict =>
48-
restrict.match(/(\.?[a-zA-Z0-9_-]+)/g)
51+
List(restrict.split(','))
52+
.map(x => x.trim())
53+
.map(x => List(x.match(/(\.[a-zA-Z0-9_-]+)/g)))
54+
.map(xs => xs.first())
4955

5056
// makeIndex :: ((Map Restrict (Set Comment)), Comment) -> Map Restrict (Set Comment)
5157
const makeIndex = (index, comment) =>
@@ -100,7 +106,7 @@ module.exports = comments => {
100106
const initialize = () => {
101107
const normalized = comments.filter(x => !topLevel(x)).map(normalize)
102108

103-
const [fancy_, plain] = partition(normalized, c => /[*|+|~|[\]]/.test(c.getIn(['annotations', 'restrict'])))
109+
const [fancy_, plain] = partition(normalized, c => /[*|+|~|[\]|:]/.test(c.getIn(['annotations', 'restrict'])))
104110

105111
const [utils, fancy] = partition(fancy_, comment =>
106112
comment
@@ -118,6 +124,7 @@ module.exports = comments => {
118124
components,
119125
utilities,
120126
modifiers,
127+
variants,
121128
findModifier,
122129
findComponent,
123130
findUtility,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@salesforce-ux/design-system-parser",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "Parse CSS comments into a data structure",
55
"main": "./.dist/index.js",
66
"files": [

0 commit comments

Comments
 (0)