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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"knip": "knip"
},
"dependencies": {
"@projectwallace/css-parser": "^0.15.0"
"@projectwallace/css-parser": "^0.16.0"
},
"devDependencies": {
"@codecov/rollup-plugin": "^2.0.1",
Expand Down
11 changes: 6 additions & 5 deletions pnpm-lock.yaml

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

50 changes: 22 additions & 28 deletions src/atrules/atrules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import {
str_equals,
walk,
BREAK,
DIMENSION,
NUMBER,
IDENTIFIER,
is_identifier,
is_media_feature,
is_media_type,
is_supports_query,
is_dimension,
is_number,
type CSSNode,
} from '@projectwallace/css-parser'

Expand Down Expand Up @@ -77,38 +77,32 @@ export function isMediaBrowserhack(prelude: CSSNode, on_hack: (hack: string) =>
}

// Check for min-resolution with .001dpcm
if (str_equals('min-resolution', name) && node.has_children) {
for (const child of node) {
if (
child.type === DIMENSION &&
child.value === 0.001 &&
str_equals('dpcm', child.unit || '')
) {
on_hack('min-resolution: .001dpcm')
return BREAK
}
if (str_equals('min-resolution', name) && node.value !== null && is_dimension(node.value)) {
const dimension = node.value
if (dimension.value === 0.001 && str_equals('dpcm', dimension.unit || '')) {
on_hack('min-resolution: .001dpcm')
return BREAK
}
}

// Check for -webkit-min-device-pixel-ratio with 0 or 10000
if (str_equals('-webkit-min-device-pixel-ratio', name) && node.has_children) {
for (const child of node) {
if (child.type === NUMBER && (child.value === 0 || child.value === 10000)) {
on_hack('-webkit-min-device-pixel-ratio')
return BREAK
}
if (
str_equals('-webkit-min-device-pixel-ratio', name) &&
node.value !== null &&
is_number(node.value)
) {
const num = node.value.value
if (num === 0 || num === 10000) {
on_hack('-webkit-min-device-pixel-ratio')
return BREAK
}
}
}

// Check for \0 unit hack (appears as Identifier node)
if (node.has_children) {
for (const child of node) {
if (child.type === IDENTIFIER && child.text === '\\0') {
on_hack('\\0')
return BREAK
}
}
}
// \0 inside a media feature value (e.g. min-width:0\0) — sibling of the numeric value
if (is_identifier(node) && node.text === '\\0') {
on_hack('\\0')
return BREAK
}
})
}
5 changes: 2 additions & 3 deletions src/selectors/specificity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ATTRIBUTE_SELECTOR,
CLASS_SELECTOR,
PSEUDO_CLASS_SELECTOR,
COMBINATOR,
PSEUDO_ELEMENT_SELECTOR,
TYPE_SELECTOR,
type CSSNode,
Expand All @@ -19,7 +18,7 @@ import {
is_selector,
is_combinator,
} from '@projectwallace/css-parser'
import { parse_selector } from '@projectwallace/css-parser/parse-selector'
import { parse_selector_list } from '@projectwallace/css-parser/parse-selector'

type Specificity = [number, number, number]

Expand Down Expand Up @@ -235,7 +234,7 @@ const convertToAST = (source: string | CSSNode) => {
// ~> Let's try and parse to an AST
if (typeof source === 'string') {
try {
return parse_selector(source)
return parse_selector_list(source)
} catch (e) {
const message = e instanceof Error ? e.message : String(e)
throw new TypeError(
Expand Down