Skip to content

Commit

Permalink
Merge 2853044 into b8332bc
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman committed Nov 25, 2018
2 parents b8332bc + 2853044 commit cfc81f0
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 17 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -43,6 +43,7 @@
},
"dependencies": {
"color-sorter": "^2.2.0",
"css-at-supports-browser-h4cks-analyzer": "^1.0.0",
"css-color-names": "^1.0.0",
"css-media-query-browser-h4cks-analyzer": "^1.0.0",
"css-property-browser-h4cks-analyzer": "^1.0.1",
Expand Down
7 changes: 1 addition & 6 deletions src/analyzer/atrules/mediaqueries.js
Expand Up @@ -7,18 +7,13 @@ module.exports = atRules => {
.map(rule => rule.params)

const browserhacks = all.filter(isBrowserHack)
const {
unique: uniqueBrowserHacks,
totalUnique: totalUniqueBrowserhacks
} = uniquer(browserhacks)

return {
total: all.length,
...uniquer(all),
browserhacks: {
total: browserhacks.length,
unique: uniqueBrowserHacks,
totalUnique: totalUniqueBrowserhacks
...uniquer(browserhacks)
}
}
}
9 changes: 8 additions & 1 deletion src/analyzer/atrules/supports.js
@@ -1,12 +1,19 @@
const isBrowserHack = require('css-at-supports-browser-h4cks-analyzer')
const uniquer = require('../../utils/uniquer')

module.exports = atRules => {
const all = atRules
.filter(rule => rule.type === 'supports')
.map(rule => rule.params)

const browserhacks = all.filter(isBrowserHack)

return {
total: all.length,
...uniquer(all)
...uniquer(all),
browserhacks: {
total: browserhacks.length,
...uniquer(browserhacks)
}
}
}
9 changes: 2 additions & 7 deletions src/analyzer/stylesheets/browserhacks.js
@@ -1,5 +1,5 @@
module.exports = (atrules, properties, values) => {
const {total, totalUnique} = [atrules.mediaqueries, properties, values]
module.exports = (atrules, selectors, properties, values) => {
return [atrules.mediaqueries, atrules.supports, selectors, properties, values]
.map(metric => metric.browserhacks)
.reduce(
(totals, current) => {
Expand All @@ -12,9 +12,4 @@ module.exports = (atrules, properties, values) => {
totalUnique: 0
}
)

return {
total,
totalUnique
}
}
7 changes: 6 additions & 1 deletion src/analyzer/stylesheets/index.js
Expand Up @@ -10,7 +10,12 @@ module.exports = (
const size = Buffer.byteLength(raw, 'utf8')
const simplicity = require('./simplicity.js')(rules, selectors)
const cohesion = require('./cohesion.js')(rules, declarations)
const browserhacks = require('./browserhacks.js')(atrules, properties, values)
const browserhacks = require('./browserhacks.js')(
atrules,
selectors,
properties,
values
)

return {
size,
Expand Down
12 changes: 11 additions & 1 deletion test/analyzer/atrules/supports/output.json
Expand Up @@ -14,5 +14,15 @@
"value": "(filter: blur(5px))",
"count": 1
}
]
],
"browserhacks": {
"total": 2,
"unique": [
{
"value": "(-webkit-appearance:none)",
"count": 2
}
],
"totalUnique": 1
}
}
7 changes: 6 additions & 1 deletion test/analyzer/index.js
Expand Up @@ -61,7 +61,12 @@ test('Returns the correct analysis object structure', async t => {
supports: {
total: 0,
totalUnique: 0,
unique: []
unique: [],
browserhacks: {
total: 0,
unique: [],
totalUnique: 0
}
}
},
declarations: {
Expand Down
44 changes: 44 additions & 0 deletions test/analyzer/stylesheets/browserhacks.js
@@ -0,0 +1,44 @@
const test = require('ava')
const analyze = require('../../../src/analyzer/stylesheets/browserhacks.js')

test('it counts the totals of browserhacks correctly', t => {
const atRules = {
mediaqueries: {
browserhacks: {
total: 1,
totalUnique: 1
}
},
supports: {
browserhacks: {
total: 2,
totalUnique: 2
}
}
}
const selectors = {
browserhacks: {
total: 1,
totalUnique: 1
}
}
const properties = {
browserhacks: {
total: 1,
totalUnique: 1
}
}
const values = {
browserhacks: {
total: 1,
totalUnique: 1
}
}
const expected = {
total: 6,
totalUnique: 6
}
const actual = analyze(atRules, selectors, properties, values)

t.deepEqual(actual, expected)
})

0 comments on commit cfc81f0

Please sign in to comment.