Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/atrules/atrules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ AtRules('finds @font-face', () => {
}
}`
const actual = analyze(fixture, {
useUnstableLocations: true
}).atrules.fontface.__unstable__uniqueWithLocations
useLocations: true
}).atrules.fontface.uniqueWithLocations
const expected = {
5: [{
line: 2,
Expand Down
6 changes: 3 additions & 3 deletions src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export class Collection {
* uniquenessRatio: number;
* unique: Record<string, number>;
* } & ({
* __unstable__uniqueWithLocations: Record<string, CssLocation[]>
* uniqueWithLocations: Record<string, CssLocation[]>
* } | {
* __unstable__uniqueWithLocations?: undefined
* uniqueWithLocations?: undefined
* })}
*/
c() {
Expand Down Expand Up @@ -103,7 +103,7 @@ export class Collection {
}

if (useLocations) {
data.__unstable__uniqueWithLocations = Object.fromEntries(uniqueWithLocations)
data.uniqueWithLocations = Object.fromEntries(uniqueWithLocations)
}

return data
Expand Down
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ function ratio(part, total) {
}

let defaults = {
useUnstableLocations: false
useLocations: false
}

/**
* @typedef Options
* @property {boolean} useUnstableLocations **WARNING: EXPERIMENTAL!** Use Locations (`{ 'item': [{ line, column, offset, length }] }`) instead of a regular count per occurrence (`{ 'item': 3 }`)
* @property {boolean} useLocations Use Locations (`{ 'item': [{ line, column, offset, length }] }`) instead of a regular count per occurrence (`{ 'item': 3 }`)
*/

/**
Expand All @@ -67,7 +67,7 @@ let defaults = {
*/
export function analyze(css, options = {}) {
let settings = Object.assign({}, defaults, options)
let useLocations = settings.useUnstableLocations === true
let useLocations = settings.useLocations === true
let start = Date.now()

/**
Expand All @@ -91,7 +91,7 @@ export function analyze(css, options = {}) {
let embedSize = 0
let embedTypes = {
total: 0,
/** @type {Map<string, { size: number, count: number } & ({ __unstable__uniqueWithLocations?: undefined } | ({ __unstable__uniqueWithLocations: { offset: number, line: number, column: number, length: number }[] })) }>} */
/** @type {Map<string, { size: number, count: number } & ({ uniqueWithLocations?: undefined } | ({ uniqueWithLocations: { offset: number, line: number, column: number, length: number }[] })) }>} */
unique: new Map()
}

Expand Down Expand Up @@ -415,15 +415,15 @@ export function analyze(css, options = {}) {
item.size += size
embedTypes.unique.set(type, item)
if (useLocations) {
item.__unstable__uniqueWithLocations.push(loc)
item.uniqueWithLocations.push(loc)
}
} else {
let item = {
count: 1,
size
}
if (useLocations) {
item.__unstable__uniqueWithLocations = [loc]
item.uniqueWithLocations = [loc]
}
embedTypes.unique.set(type, item)
}
Expand Down Expand Up @@ -694,7 +694,7 @@ export function analyze(css, options = {}) {
})

let embeddedContent = embeds.c()
delete embeddedContent.__unstable__uniqueWithLocations
delete embeddedContent.uniqueWithLocations

let totalUniqueDeclarations = uniqueDeclarations.size

Expand Down Expand Up @@ -742,7 +742,7 @@ export function analyze(css, options = {}) {
unique: fontfaces,
uniquenessRatio: fontFacesCount === 0 ? 0 : 1,
}, useLocations ? {
__unstable__uniqueWithLocations: fontfaces_with_loc.c().__unstable__uniqueWithLocations,
uniqueWithLocations: fontfaces_with_loc.c().uniqueWithLocations,
} : {}),
import: imports.c(),
media: assign(
Expand Down
4 changes: 2 additions & 2 deletions src/selectors/pseudos.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ test('logs the whole parent selector when using locations', () => {
let actual = analyze(`
a:hover,
a:lang(en) {}`,
{ useUnstableLocations: true }
).selectors.pseudoClasses.__unstable__uniqueWithLocations
{ useLocations: true }
).selectors.pseudoClasses.uniqueWithLocations
let expected = {
'hover': [
{
Expand Down
8 changes: 4 additions & 4 deletions src/selectors/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,11 @@ Selectors('tracks combinator locations', () => {
a[attr] b {}
`
let result = analyze(css, {
useUnstableLocations: true
useLocations: true
})
let actual = result.selectors.combinators

assert.equal(actual.__unstable__uniqueWithLocations, {
assert.equal(actual.uniqueWithLocations, {
' ': [
{
line: 2,
Expand Down Expand Up @@ -465,7 +465,7 @@ Selectors('tracks combinator locations', () => {
]
})

let as_strings = actual.__unstable__uniqueWithLocations[' ']
let as_strings = actual.uniqueWithLocations[' ']
.map(loc => css.substring(loc.offset, loc.offset + loc.length))
assert.equal(as_strings, [
' ',
Expand All @@ -491,7 +491,7 @@ Selectors('Can keep track of selector locations if we ask it to do so', () => {
}
}
`
let actual = analyze(fixture, { useUnstableLocations: true }).selectors.complexity.__unstable__uniqueWithLocations
let actual = analyze(fixture, { useLocations: true }).selectors.complexity.uniqueWithLocations
let expected = {
'1': [
{
Expand Down
6 changes: 3 additions & 3 deletions src/stylesheet/stylesheet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Stylesheet('measures base64 contents - with locations', () => {
}
`

const actual = analyze(fixture, { useUnstableLocations: true }).stylesheet.embeddedContent
const actual = analyze(fixture, { useLocations: true }).stylesheet.embeddedContent
const expected = {
total: 5,
totalUnique: 5,
Expand All @@ -202,7 +202,7 @@ Stylesheet('measures base64 contents - with locations', () => {
'image/gif': {
count: 1,
size: 310,
__unstable__uniqueWithLocations: [
uniqueWithLocations: [
{
line: 5,
column: 9,
Expand All @@ -214,7 +214,7 @@ Stylesheet('measures base64 contents - with locations', () => {
'image/svg+xml': {
count: 4,
size: 2027,
__unstable__uniqueWithLocations: [
uniqueWithLocations: [
{
line: 13,
column: 19,
Expand Down
4 changes: 2 additions & 2 deletions src/values/colors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1063,9 +1063,9 @@ Colors('Lists locations when unstable flag is set', () => {
background-color: red;
}
`
let actual = analyze(css, { useUnstableLocations: true })
let actual = analyze(css, { useLocations: true })

assert.equal(actual.values.colors.__unstable__uniqueWithLocations, {
assert.equal(actual.values.colors.uniqueWithLocations, {
'red': [
{
line: 3,
Expand Down