Skip to content

Commit 403ad5b

Browse files
committed
Upgrade dependencies
1 parent 439994a commit 403ad5b

12 files changed

Lines changed: 374 additions & 316 deletions

File tree

__tests__/value.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4017,7 +4017,7 @@ describe('<style-feature>', () => {
40174017
expect(parse('<style-feature>', 'color: green !important', false, containerRule)).toMatchObject({
40184018
important: true,
40194019
name: 'color',
4020-
types: ['<declaration>', '<style-feature>'],
4020+
types: ['<declaration>', '<style-feature-plain>', '<style-feature>'],
40214021
value: keyword('green', ['<named-color>', '<color-base>', '<color>', 'color']),
40224022
})
40234023
})
@@ -4044,6 +4044,8 @@ describe('<style-feature>', () => {
40444044
['width: interpolate(0, 0: 1px)'],
40454045
['width: toggle(1px)'],
40464046
['width: calc-interpolate(0, 0: random(1px, 1px), 1: 1px * sibling-count())'],
4047+
// Arbitrary substitution of range values
4048+
['var(--custom) < 1px'],
40474049
]
40484050
valid.forEach(([input, expected = input]) =>
40494051
expect(parse('<style-feature>', input, true, containerRule)).toBe(expected))

lib/parse/configure.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
const { enter } = require('../utils/context.js')
3+
24
/**
35
* @param {object} node
46
* @returns {object}
@@ -17,6 +19,15 @@ function disableWhiteSpace({ context, ...props }) {
1719
return { ...props, context: { ...context, separator: '' } }
1820
}
1921

22+
/**
23+
* @param {object} node
24+
* @returns {object}
25+
*/
26+
function enterStyleRule(node) {
27+
const { context, ...props } = node
28+
return { context: enter(node, '@style'), ...props }
29+
}
30+
2031
/**
2132
* @param {object} node
2233
* @returns {object}
@@ -35,6 +46,7 @@ module.exports = {
3546
'<mf-comparison>': disableWhiteSpace,
3647
'<page-selector>': disableWhiteSpace,
3748
'<pt-name-and-class-selector>': disableWhiteSpace,
49+
'<style-feature>': enterStyleRule,
3850
'<supports-feature>': setStrictParsing,
3951
'<syntax-component>': disableWhiteSpace,
4052
'<urange>': disableWhiteSpace,

lib/parse/parser.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,9 @@ function parseStyleSheet(input, context, allowImport = false) {
949949
* @returns {SyntaxError|object|null}
950950
*/
951951
function parseCSSArbitrarySubstitution(input, context) {
952+
if (input.types[0] !== '<function>') {
953+
return null
954+
}
952955
const { definition: { cascading, elemental } } = getRule(context)
953956
for (const { cascade, element, name, type = `<${name}()>` } of substitutions.arbitrary) {
954957
if (!elemental && (element || (cascade && !cascading))) {
@@ -973,17 +976,15 @@ function parseCSSArbitrarySubstitutionContainingValue(input, context) {
973976
for (let value of input) {
974977
const { types: [type], value: nested } = value
975978
if (type === '<function>' || type === '<block>') {
976-
if (type === '<function>') {
977-
const match = parseCSSArbitrarySubstitution(value, context)
978-
if (isError(match)) {
979-
return match
980-
}
981-
if (match) {
982-
value = match
983-
containsSubstitution = true
984-
}
979+
let match = parseCSSArbitrarySubstitution(value, context)
980+
if (isError(match)) {
981+
return match
982+
}
983+
if (match) {
984+
value = match
985+
containsSubstitution = true
985986
}
986-
const match = parseCSSArbitrarySubstitutionContainingValue(new Stream(nested), context)
987+
match = parseCSSArbitrarySubstitutionContainingValue(new Stream(nested), context)
987988
if (isError(match)) {
988989
return match
989990
}
@@ -1182,6 +1183,7 @@ const parser = module.exports = {
11821183
getDeclarationDefinition,
11831184
insertCSSRule,
11841185
parseBlockContents,
1186+
parseCSSArbitrarySubstitution,
11851187
parseCSSDeclaration,
11861188
parseCSSDeclarationValue,
11871189
parseCSSGrammar,

lib/parse/postprocess.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
const { angle, filter, keyword, list, map, number, omitted, string } = require('../values/value.js')
3-
const { findFunction, findSibling, getDeclaration, getDeclarationName, getFunctionName, getRuleName, isDeclaredBy, isProducedBy } = require('../utils/context.js')
3+
const { findFunction, findSibling, getDeclaration, getDeclarationName, getFunctionName, getRule, getRuleName, isDeclaredBy, isProducedBy } = require('../utils/context.js')
44
const { addTypes, dimensionTypes, getCalculationType, matchNumericType } = require('./types.js')
55
const { isCalculation, isColon, isFailure, isList, isOmitted, isWhitespace } = require('../utils/value.js')
66
const { isHexadecimal, isIdentifierCharacter, isWhitespace: isWhitespaceCharacter } = require('./tokenize.js')
@@ -1527,25 +1527,29 @@ function postParseSteps(steps, node) {
15271527
}
15281528

15291529
/**
1530-
* @param {object} feature
1530+
* @param {object} name
15311531
* @param {object} node
15321532
* @param {object} parser
15331533
* @returns {SyntaxError|object}
1534-
* @see {@link https://drafts.csswg.org/css-conditional-5/#typedef-style-feature}
1534+
* @see {@link https://drafts.csswg.org/css-conditional-5/#typedef-style-feature-name}
15351535
*
1536-
* It aborts parsing when the feature is an unknown property or a declaration
1537-
* whose value is either `revert` or `revert-layer`.
1536+
* It aborts parsing when the name is not a valid style property.
15381537
*/
1539-
function postParseStyleFeature(feature, node, { createContext, getDeclarationDefinition }) {
1540-
const { types, value } = feature
1541-
if (
1542-
types[0] === '<ident-token>'
1543-
? getDeclarationDefinition(createContext('@style'), value)
1544-
: !value.value?.startsWith?.('revert')
1545-
) {
1546-
return feature
1547-
}
1548-
return error(node)
1538+
function postParseStyleFeatureName(name, node, parser) {
1539+
return parser.getDeclarationDefinition(getRule(node), name.value) ? name : error(node)
1540+
}
1541+
1542+
/**
1543+
* @param {object} declaration
1544+
* @param {object} node
1545+
* @param {object} parser
1546+
* @returns {SyntaxError|object}
1547+
* @see {@link https://drafts.csswg.org/css-conditional-5/#typedef-style-feature-name}
1548+
*
1549+
* It aborts parsing when the declaration value is `revert` or `revert-layer`.
1550+
*/
1551+
function postParseStyleFeaturePlain(declaration, node) {
1552+
return declaration.value.value?.startsWith?.('revert') ? error(node) : declaration
15491553
}
15501554

15511555
/**
@@ -1841,7 +1845,8 @@ module.exports = {
18411845
'<signed-integer>': postParseSignedInteger,
18421846
'<signless-integer>': postParseSignlessInteger,
18431847
'<steps()>': postParseSteps,
1844-
'<style-feature>': postParseStyleFeature,
1848+
'<style-feature-plain>': postParseStyleFeaturePlain,
1849+
'<style-feature-name>': postParseStyleFeatureName,
18451850
'<symbols()>': postParseSymbols,
18461851
'<syntax-string>': postParseSyntaxString,
18471852
'<syntax>': postParseSyntax,

lib/parse/replace.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ function resolveColorComponentDefinition(node) {
162162
}
163163
}
164164

165+
/**
166+
* @param {object} node
167+
* @param {object} parser
168+
* @returns {SyntaxError|object|null}
169+
* @see {@link https://drafts.csswg.org/css-conditional-5/#typedef-style-range-value}
170+
*/
171+
function replaceWithArbitrarySubstitution(node, parser) {
172+
return node.input.consume(parser.parseCSSArbitrarySubstitution, node)
173+
}
174+
165175
/**
166176
* @param {object} node
167177
* @param {object} parser
@@ -216,6 +226,7 @@ module.exports = {
216226
'<number>': replaceNumeric,
217227
'<percentage>': replaceNumeric,
218228
'<resolution>': replaceNumeric,
229+
'<style-range-value>': replaceWithArbitrarySubstitution,
219230
'<subclass-selector>': replaceWithNestingSelector,
220231
'<system-color>': replaceWithDeprecatedColor,
221232
'<time>': replaceNumeric,

lib/properties/definitions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ module.exports = {
529529
},
530530
serialized: 'none',
531531
},
532-
value: 'none | auto | base | <compat-auto> | <compat-special>',
532+
value: 'none | auto | base | base-select | <compat-auto> | <compat-special>',
533533
},
534534
'aspect-ratio': {
535535
initial: {

lib/utils/context.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ const { isCSSType } = require('./node.js')
33

44
const type = Symbol('context')
55

6+
/**
7+
* @param {object} node
8+
* @param {string} name
9+
* @returns {object}
10+
*/
11+
function enter(node, name) {
12+
const { context } = node
13+
const contextDefinition = getRule(node)?.definition.value ?? getRoot(node)
14+
const definition = contextDefinition.rules.find(rule => rule.name === name)
15+
return { ...context, context, definition }
16+
}
17+
618
/**
719
* @param {object} node
820
* @param {function} accept
@@ -142,6 +154,19 @@ function getProduction(node) {
142154
return findParent(node, isCSSType, isCSSType)
143155
}
144156

157+
/**
158+
* @param {object} node
159+
* @returns {object|undefined}
160+
*/
161+
function getRoot({ context }) {
162+
let root
163+
while (context) {
164+
root = context
165+
context = context.context
166+
}
167+
return root
168+
}
169+
145170
/**
146171
* @param {object} node
147172
* @returns {object|undefined}
@@ -185,6 +210,7 @@ function isProducedBy(node, name) {
185210
}
186211

187212
module.exports = {
213+
enter,
188214
findContext,
189215
findFunction,
190216
findParent,
@@ -194,6 +220,7 @@ module.exports = {
194220
getFunction,
195221
getFunctionName,
196222
getProduction,
223+
getRoot,
197224
getRule,
198225
getRuleName,
199226
isContext,

lib/values/definitions.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,14 @@ module.exports = {
468468
'<string()>': 'string(<custom-ident> , [first | start | last | first-except]?)',
469469
'<string>': '<string-token>',
470470
'<stripes()>': 'stripes(<color-stripe>#)',
471-
'<style-feature>': '<declaration> | <ident>',
471+
'<style-feature-boolean>': '<style-feature-name>',
472+
'<style-feature-name>': '<ident>',
473+
'<style-feature-plain>': '<declaration>',
474+
'<style-feature>': '<style-feature-plain> | <style-feature-boolean> | <style-range>',
472475
'<style-in-parens>': '(<style-query>) | (<style-feature>) | <general-enclosed>',
473476
'<style-query>': 'not <style-in-parens> | <style-in-parens> [[and <style-in-parens>]* | [or <style-in-parens>]*] | <style-feature>',
477+
'<style-range-value>': '<custom-property-name> | <number> | <percentage> | <dimension>',
478+
'<style-range>': '<style-range-value> <mf-comparison> <style-range-value> | <style-range-value> <mf-lt> <style-range-value> <mf-lt> <style-range-value> | <style-range-value> <mf-gt> <style-range-value> <mf-gt> <style-range-value>',
474479
'<subclass-selector>': '<id-selector> | <class-selector> | <attribute-selector> | <pseudo-class-selector>',
475480
'<superellipse()>': 'superellipse(<number [-∞,∞]> | infinity | -infinity)',
476481
'<supports()>': 'supports(<declaration>)',

lib/values/pseudos.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ const typographic = {
290290
* @see {@link https://drafts.csswg.org/selectors-4/#compat}
291291
* @see {@link https://drafts.csswg.org/selectors-4/#defined-pseudo}
292292
* @see {@link https://drafts.csswg.org/selectors-5/#selectordef-state}
293+
* @see {@link https://drafts.csswg.org/selectors-5/#heading-pseudo}
294+
* @see {@link https://drafts.csswg.org/selectors-5/#heading-functional-pseudo}
293295
* @see {@link https://immersive-web.github.io/dom-overlays/#selectordef-xr-overlay}
294296
*/
295297
const classes = {
@@ -302,6 +304,7 @@ const classes = {
302304
...structural.functions,
303305
...time.functions,
304306
...viewTransitions.classes.functions,
307+
'heading': '<an+b>#',
305308
'host': '<compound-selector>',
306309
'host-context': '<compound-selector>',
307310
'state': '<ident>',
@@ -318,6 +321,7 @@ const classes = {
318321
...viewTransitions.classes.identifiers,
319322
'defined',
320323
'has-slotted',
324+
'heading',
321325
'high-value',
322326
'host',
323327
'low-value',

0 commit comments

Comments
 (0)