Skip to content

Commit 6bafe4e

Browse files
committed
Minor things
1 parent ddad7d1 commit 6bafe4e

File tree

9 files changed

+62
-64
lines changed

9 files changed

+62
-64
lines changed

__tests__/style.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,11 @@ describe('arbitrary substitution', () => {
397397
const valid = [
398398
// Valid at parse time
399399
['--custom(--custom(!))'],
400-
['attr(name, attr())', 'attr(name, attr())'],
401-
['env(name, env())', 'env(name, env())'],
402-
['inherit(--custom, inherit())', 'inherit(--custom, inherit())'],
403-
['random-item(--key, random-item())', 'random-item(--key, random-item())'],
404-
['var(--custom, var())', 'var(--custom, var())'],
400+
['attr(name, attr())'],
401+
['env(name, env())'],
402+
['inherit(--custom, inherit())'],
403+
['random-item(--key, random-item())'],
404+
['var(--custom, var())'],
405405
// Custom function name with escaped characters
406406
['--cust\\ om()'],
407407
// Serialize the list of tokens

lib/parse/arbitrary.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function error({ definition: { name, value } }) {
2727
*/
2828
function matchAnyValue(input, restricted, stops = []) {
2929
stops = [...closingTokens, ...stops]
30-
const values = list([], '')
30+
const values = []
3131
input.consume(isWhitespace)
3232
while (!input.atEnd()) {
3333
const next = input.next()
@@ -45,7 +45,7 @@ function matchAnyValue(input, restricted, stops = []) {
4545
if (isWhitespace(values.at(-1))) {
4646
values.pop()
4747
}
48-
return 0 < values.length ? values : null
48+
return 0 < values.length ? list(values, '') : null
4949
}
5050

5151
/**

lib/parse/parser.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ function consumeComponentValue(tokens) {
445445
* emitting a parse error when processing `}` while the list is not nested.
446446
*/
447447
function consumeComponentValueList(tokens, stops = []) {
448-
const values = list([], '')
448+
const values = []
449449
tokens.consume(isWhitespace)
450450
while (!tokens.atEnd()) {
451451
if (isDelimiter(stops, tokens.next())) {
@@ -456,7 +456,7 @@ function consumeComponentValueList(tokens, stops = []) {
456456
if (isWhitespace(values.at(-1))) {
457457
values.pop()
458458
}
459-
return values
459+
return list(values, '')
460460
}
461461

462462
/**
@@ -497,7 +497,7 @@ function consumeBadDeclaration(tokens, forCustomProperty, nested) {
497497
* @returns {SyntaxError|object|undefined}
498498
*/
499499
function consumeDeclarationValue(tokens, forCustomProperty, nested) {
500-
const values = list([], '')
500+
const values = []
501501
let token
502502
while (token = tokens.next()) {
503503
if (isWhitespace(token)) {
@@ -530,7 +530,7 @@ function consumeDeclarationValue(tokens, forCustomProperty, nested) {
530530
if (isWhitespace(values.at(-1))) {
531531
values.pop()
532532
}
533-
return values
533+
return list(values, '')
534534
}
535535

536536
/**
@@ -713,7 +713,7 @@ function consumeAtRule(tokens, context, nested) {
713713
* order.
714714
*/
715715
function consumeBlockContents(tokens, context, ignoreCloseCurlyBlock) {
716-
const rules = list([], ' ', '<block-contents>')
716+
const rules = []
717717
const declarations = []
718718
while (!tokens.atEnd()) {
719719
if (tokens.consume(isWhitespace) || tokens.consume(isSemicolon)) {
@@ -756,7 +756,7 @@ function consumeBlockContents(tokens, context, ignoreCloseCurlyBlock) {
756756
if (0 < declarations.length) {
757757
rules.push(getDeclarationsInSpecifiedOrder(declarations.splice(0)))
758758
}
759-
return rules
759+
return list(rules, ' ', '<block-contents>')
760760
}
761761

762762
/**
@@ -770,7 +770,7 @@ function consumeBlockContents(tokens, context, ignoreCloseCurlyBlock) {
770770
* instead of in consumeAtRule() or CSSStyleSheet.replace*().
771771
*/
772772
function consumeStyleSheet(tokens, context, allowImport) {
773-
const rules = list([], ' ', ['<block-contents>'])
773+
const rules = []
774774
while (!tokens.atEnd()) {
775775
if (tokens.consume(token => isDelimiter([' ', '<!--', '-->'], token))) {
776776
continue
@@ -796,7 +796,7 @@ function consumeStyleSheet(tokens, context, allowImport) {
796796
rules.push(rule)
797797
}
798798
}
799-
return rules
799+
return list(rules, ' ', ['<block-contents>'])
800800
}
801801

802802
/**
@@ -852,11 +852,11 @@ function parseCommaSeparatedComponentValueList(input) {
852852
if (input.atEnd()) {
853853
return list([], ',')
854854
}
855-
const value = list([consumeComponentValueList(input, [','])], ',')
855+
const value = [consumeComponentValueList(input, [','])]
856856
while (input.consume(isComma)) {
857857
value.push(consumeComponentValueList(input, [',']))
858858
}
859-
return value
859+
return list(value, ',')
860860
}
861861

862862
/**
@@ -971,7 +971,7 @@ function parseCSSArbitrarySubstitution(value, context) {
971971
* @returns {SyntaxError|object[]|null}
972972
*/
973973
function parseCSSArbitrarySubstitutionContainingValue(input, context) {
974-
const values = list([], '')
974+
const values = []
975975
let containsSubstitution = false
976976
for (let value of input) {
977977
const { types: [type], value: nested } = value
@@ -997,7 +997,7 @@ function parseCSSArbitrarySubstitutionContainingValue(input, context) {
997997
}
998998
if (containsSubstitution) {
999999
context.globals.set('pending', true)
1000-
return values
1000+
return list(values, '')
10011001
}
10021002
input.reset()
10031003
return null
@@ -1047,26 +1047,26 @@ function parseCSSWideKeyword(input, context) {
10471047
}
10481048

10491049
/**
1050-
* @param {Stream|string|object[]} value
1050+
* @param {Stream|string|object[]} input
10511051
* @param {object|string} definition
10521052
* @param {CSSRuleImpl|CSSFontFeatureValuesMap|Element|object|string|string[]} [context]
10531053
* @returns {SyntaxError|object|object[]|null}
10541054
* @see {@link https://drafts.csswg.org/cssom-1/#parse-a-css-value}
10551055
*/
1056-
function parseCSSDeclarationValue(value, definition, context) {
1056+
function parseCSSDeclarationValue(input, definition, context) {
10571057
if (typeof input === 'string') {
1058-
value = new Stream(parseComponentValueList(value), value)
1059-
} else if (Array.isArray(value)) {
1060-
value = new Stream(value)
1058+
input = new Stream(parseComponentValueList(input), input)
1059+
} else if (Array.isArray(input)) {
1060+
input = new Stream(input)
10611061
}
10621062
context = createContext(context)
10631063
if (typeof definition === 'string') {
10641064
definition = getDeclarationDefinition(context, definition)
10651065
}
1066-
return parseCSSWideKeyword(value, context)
1067-
?? parseCSSArbitrarySubstitutionContainingValue(value, context)
1068-
?? parseCSSGrammar(value, definition, context)
1069-
?? parseCSSValueSubstitution(value, context)
1066+
return parseCSSWideKeyword(input, context)
1067+
?? parseCSSArbitrarySubstitutionContainingValue(input, context)
1068+
?? parseCSSGrammar(input, definition, context)
1069+
?? parseCSSValueSubstitution(input, context)
10701070
}
10711071

10721072
/**

lib/parse/replace.js

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

2-
const { colorFunctionKeywords, colorSpaces, colorSpaceKeywords } = require('../values/colors.js')
2+
const { colorFunctionKeywords, colorSpaceKeywords, colorSpaces }= require('../values/colors.js')
33
const { dimensionTypes, getCalculationType, matchNumericType } = require('./types.js')
4-
const { findContext, findFunction, findSibling, findParent, isProducedBy, getFunction, getRule } = require('../utils/context.js')
4+
const { findContext, findFunction, findParent, findSibling, getFunction, getRule, isProducedBy } = require('../utils/context.js')
55
const { isDelimiter, isFailure } = require('../utils/value.js')
66
const createError = require('../error.js')
77
const { simplifyCalculation } = require('./simplify.js')
@@ -22,7 +22,7 @@ function error({ definition: { name, value } }) {
2222
* @see {@link https://drafts.csswg.org/css-values-4/#calc-variables}
2323
*/
2424
function replaceCalcKeyword(node, parser) {
25-
return replaceWithColorChannelKeyword(node, parser)
25+
return replaceWithColorComponentKeyword(node, parser)
2626
}
2727

2828
/**
@@ -84,7 +84,7 @@ function replaceNumeric(node, parser) {
8484

8585
if (next?.types[0] !== '<function>') {
8686
if (definition.name === '<number>' && topLevel) {
87-
return replaceWithColorChannelKeyword(node, parser)
87+
return replaceWithColorComponentKeyword(node, parser)
8888
}
8989
return null
9090
}
@@ -136,6 +136,16 @@ function replaceNumeric(node, parser) {
136136
return null
137137
}
138138

139+
/**
140+
* @param {object} node
141+
* @param {object} parser
142+
* @returns {SyntaxError|object|null}
143+
* @see {@link https://drafts.csswg.org/css-conditional-5/#typedef-style-range-value}
144+
*/
145+
function replaceWithArbitrarySubstitution(node, parser) {
146+
return node.input.consume(parser.parseCSSArbitrarySubstitution, node)
147+
}
148+
139149
/**
140150
* @param {object} node
141151
* @returns {boolean}
@@ -153,7 +163,7 @@ function resolveColorComponentDefinition(node) {
153163
if (!isColorComponent(node)) {
154164
node = findContext(node, node => node.state === 'replacing' && isColorComponent(node))
155165
}
156-
// There must be a source color for color keywords to be valid
166+
// There must be a source color for color component keywords to be valid
157167
if (node && findSibling(node, node => node.definition.name === '<color>')) {
158168
const { definition: { name } } = getFunction(node)
159169
if (name === 'color') {
@@ -164,23 +174,13 @@ function resolveColorComponentDefinition(node) {
164174
}
165175
}
166176

167-
/**
168-
* @param {object} node
169-
* @param {object} parser
170-
* @returns {SyntaxError|object|null}
171-
* @see {@link https://drafts.csswg.org/css-conditional-5/#typedef-style-range-value}
172-
*/
173-
function replaceWithArbitrarySubstitution(node, parser) {
174-
return node.input.consume(parser.parseCSSArbitrarySubstitution, node)
175-
}
176-
177177
/**
178178
* @param {object} node
179179
* @param {object} parser
180180
* @returns {object|null}
181181
* @see {@link https://drafts.csswg.org/css-color-5/#relative-color}
182182
*/
183-
function replaceWithColorChannelKeyword(node, parser) {
183+
function replaceWithColorComponentKeyword(node, parser) {
184184
const definition = resolveColorComponentDefinition(node)
185185
if (definition) {
186186
const { definition: { name }, input } = node

lib/parse/shorthand.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ function parseBackground(layers, [...longhands]) {
246246
* @see {@link https://drafts.csswg.org/css-backgrounds-4/#background-repeat}
247247
*/
248248
function parseBackgroundRepeat(values) {
249-
const x = list([], ',')
250-
const y = list([], ',')
249+
const x = []
250+
const y = []
251251
values.forEach(style => {
252252
if (style.value === 'repeat-x') {
253253
x.push(repeat)
@@ -260,7 +260,7 @@ function parseBackgroundRepeat(values) {
260260
y.push(style[1] ?? style[0])
261261
}
262262
})
263-
return new Map([['background-repeat-x', x], ['background-repeat-y', y]])
263+
return new Map([['background-repeat-x', list(x, ',')], ['background-repeat-y', list(y, ',')]])
264264
}
265265

266266
/**

lib/parse/simplify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ function simplifyCalculation(node, resolutionType) {
307307
entries.set(unit, [calculation])
308308
}
309309
})
310-
value = list([], ',')
310+
value = []
311311
for (const [unit, nodes] of entries) {
312312
if (1 < nodes.length && unit !== 'unresolved') {
313313
value.push(nodes.reduce((a, b) => {
@@ -323,7 +323,7 @@ function simplifyCalculation(node, resolutionType) {
323323
if (value.length === 1) {
324324
return value[0]
325325
}
326-
node = map(node, () => value)
326+
node = map(node, () => list(value, ','))
327327
}
328328
return node
329329
}

lib/serialize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ function representAnimation(declarations) {
18551855
})
18561856
}
18571857
// No simplification (on purpose)
1858-
return list(animations.map(animation => list(animation)), ',')
1858+
return list(animations, ',')
18591859
}
18601860

18611861
/**

lib/values/colors.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
/* eslint-disable @stylistic/js/quote-props */
21

32
const colorFunctionKeywords = {
4-
'hsl': 'h | s | l | alpha',
5-
'hsla': 'h | s | l | alpha',
6-
'hwb': 'h | w | b | alpha',
7-
'ictcp': 'i | ct | cp | alpha',
8-
'jzazbz': 'jz | az | bz | alpha',
9-
'jzczhz': 'jz | cz | hz | alpha',
10-
'lab': 'l | a | b | alpha',
11-
'lch': 'l | c | h | alpha',
12-
'oklab': 'l | a | b | alpha',
13-
'oklch': 'l | c | h | alpha',
14-
'rgb': 'r | g | b | alpha',
15-
'rgba': 'r | g | b | alpha',
3+
hsl: 'h | s | l | alpha',
4+
hsla: 'h | s | l | alpha',
5+
hwb: 'h | w | b | alpha',
6+
ictcp: 'i | ct | cp | alpha',
7+
jzazbz: 'jz | az | bz | alpha',
8+
jzczhz: 'jz | cz | hz | alpha',
9+
lab: 'l | a | b | alpha',
10+
lch: 'l | c | h | alpha',
11+
oklab: 'l | a | b | alpha',
12+
oklch: 'l | c | h | alpha',
13+
rgb: 'r | g | b | alpha',
14+
rgba: 'r | g | b | alpha',
1615
}
1716

1817
const colorSpaceKeywords = {

lib/values/substitutions.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable sort-keys */
21

32
const properties = require('../properties/definitions.js')
43

0 commit comments

Comments
 (0)