Skip to content

Commit 4386c7e

Browse files
committed
Enforce using list() wherever appropriate
1 parent 324f8b0 commit 4386c7e

File tree

12 files changed

+91
-63
lines changed

12 files changed

+91
-63
lines changed

lib/cssom/CSS-impl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2+
const { isComputationallyIndependent, isList } = require('../utils/value.js')
23
const { parseCSSDeclaration, parseCSSGrammar } = require('../parse/parser.js')
34
const { serializeIdentifier, serializeCSSComponentValue } = require('../serialize.js')
45
const { keywords: cssWideKeywords } = require('../values/substitutions.js')
5-
const { isComputationallyIndependent } = require('../utils/value.js')
66
const matchSupport = require('../match/support.js')
77

88
const INVALID_CUSTOM_PROPERTY_NAME = {

lib/cssom/CSSCounterStyleRule-impl.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { implementation: CSSRuleImpl } = require('./CSSRule-impl.js')
55
const counterStyles = require('../values/counter-styles.js')
66
const { cssPropertyToIDLAttribute } = require('../utils/string.js')
77
const { '@counter-style': descriptors } = require('../descriptors/definitions.js')
8+
const { isList } = require('../utils/value.js')
89
const { keyword } = require('../values/value.js')
910

1011
const descriptorNames = Object.keys(descriptors)
@@ -209,7 +210,7 @@ class CSSCounterStyleRuleImpl extends CSSRuleImpl {
209210
if (value?.value === 'symbolic') {
210211
this._system = value
211212
}
212-
} else if (Array.isArray(_system)) {
213+
} else if (isList(_system)) {
213214
// Fixed <integer>? or extends <counter-style-name>
214215
value = parseCSSDeclaration('system', value, false, this)?.value
215216
if (value && value[0]?.value === _system[0]?.value) {

lib/cssom/CSSFontFeatureValuesMap-impl.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
const { parseBlockContents, parseCSSDeclaration } = require('../parse/parser.js')
33
const error = require('../error.js')
4+
const { isList } = require('../utils/value.js')
45
const root = require('../rules/definitions.js')
56

67
const INVALID_FONT_FEATURE_VALUE_ERROR = {
@@ -28,7 +29,7 @@ class CSSFontFeatureValuesMapImpl {
2829
if (value) {
2930
const declarations = parseBlockContents(value, this)[0] ?? []
3031
const entries = declarations.map(({ name, value }) =>
31-
[name, Array.isArray(value) ? [...value.map(component => component.value)] : [value.value]])
32+
[name, isList(value) ? [...value.map(component => component.value)] : [value.value]])
3233
this._map = new Map(entries)
3334
} else {
3435
this._map = new Map

lib/cssom/CSSViewTransitionRule-impl.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const { serializeCSSComponentValue, serializeCSSValue } = require('../serialize.js')
33
const { parseBlockContents } = require('../parse/parser.js')
44
const { implementation: CSSRuleImpl } = require('./CSSRule-impl.js')
5+
const { isList } = require('../utils/value.js')
56

67
/**
78
* @see {@link https://drafts.csswg.org/css-view-transitions-2/#cssviewtransitionrule}
@@ -21,7 +22,7 @@ class CSSViewTransitionRuleImpl extends CSSRuleImpl {
2122
this.navigation = serializeCSSValue(navigation)
2223
}
2324
const types = declarations.find(declaration => declaration.name === 'types')
24-
this.types = Object.freeze(Array.isArray(types?.value)
25+
this.types = Object.freeze(isList(types?.value)
2526
? [...types.value.map(serializeCSSComponentValue)] // Spread List into a plain Array
2627
: [])
2728
}

lib/match/support.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
const { isList } = require('../utils/value.js')
3+
24
/**
35
* @param {object[]} condition
46
* @returns {boolean}
@@ -7,7 +9,7 @@
79
* @see {@link https://drafts.csswg.org/css-conditional-5/#typedef-supports-feature}
810
*/
911
function match(condition) {
10-
if (Array.isArray(condition)) {
12+
if (isList(condition)) {
1113
const [head, tail] = condition
1214
if (head.value === 'not') {
1315
return !match(tail)

lib/parse/grammar.js

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

22
const { createPermutationIterator, getPermutationIndex } = require('./permutation.js')
33
const { isBranch, isCSSType, isSequence } = require('../utils/definition.js')
4-
const { isDelimiter, isOmitted, isSimpleBlock } = require('../utils/value.js')
4+
const { isDelimiter, isList, isOmitted, isSimpleBlock } = require('../utils/value.js')
55
const { list, omitted } = require('../values/value.js')
66
const Stream = require('./stream.js')
77
const actions = require('./actions.js')
@@ -339,7 +339,7 @@ function replace(node, parser) {
339339
function tag({ definition }, parser, value) {
340340
const { name } = definition
341341
if (!isOmitted(value) && isCSSType(definition) && name !== '<declaration>') {
342-
if (!Array.isArray(value)) {
342+
if (!isList(value)) {
343343
value = { ...value, types: [...value.types] }
344344
}
345345
value.types.push(name)

lib/parse/postprocess.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const { angle, keyword, list, map, number, omitted, string } = require('../values/value.js')
33
const { findContext, findParent, findSibling } = require('../utils/context.js')
44
const { getCalculationType, matchNumericType } = require('./types.js')
5-
const { isCalculation, isColon, isOmitted, isWhitespace } = require('../utils/value.js')
5+
const { isCalculation, isColon, isList, isOmitted, isWhitespace } = require('../utils/value.js')
66
const { isHexadecimal, isIdentifierCharacter, isWhitespace: isWhitespaceCharacter } = require('./tokenize.js')
77
const Stream = require('./stream.js')
88
const compatibility = require('../compatibility.js')
@@ -69,7 +69,7 @@ function error({ definition: { name, value } }) {
6969
* the matched value against a refined grammar.
7070
*/
7171
function getInputComponentValuesFromMatch(match, input) {
72-
if (Array.isArray(match)) {
72+
if (isList(match)) {
7373
match = match.flat(Infinity)
7474
const head = match.find(component => !isOmitted(component))
7575
const tail = match.findLast(component => !isOmitted(component))
@@ -119,7 +119,7 @@ function postParseAnB(notation, node) {
119119
return { types, value: { a: 2, b: 1 } }
120120
}
121121
let text = ''
122-
for (const component of (Array.isArray(notation) ? notation : [notation])) {
122+
for (const component of (isList(notation) ? notation : [notation])) {
123123
if (!isOmitted(component)) {
124124
const { unit = '', value } = component
125125
// Invalid whitespace between an optional `+` and `n`
@@ -260,7 +260,7 @@ function postParseCalcValue(value) {
260260
* It aborts parsing when some scheme is a reserved keyword in the context.
261261
*/
262262
function postParseColorScheme(schemes, node) {
263-
if (Array.isArray(schemes) && schemes[0].some(scheme => reserved.colorScheme.includes(scheme.value.toLowerCase()))) {
263+
if (isList(schemes) && schemes[0].some(scheme => reserved.colorScheme.includes(scheme.value.toLowerCase()))) {
264264
return error(node)
265265
}
266266
return schemes
@@ -290,7 +290,7 @@ function postParseComponents(components, node) {
290290
* It aborts parsing when some name is a reserved keyword in the context.
291291
*/
292292
function postParseContainerNameProperty(names, node) {
293-
if (Array.isArray(names) && names.some(name => postParseContainerNameType(name, node))) {
293+
if (isList(names) && names.some(name => postParseContainerNameType(name, node))) {
294294
return error(node)
295295
}
296296
return names
@@ -507,7 +507,7 @@ function postParseFirstValid(substitution, node, { parseCSSGrammar }) {
507507
* It aborts parsing when the name is a reserved keyword in the context.
508508
*/
509509
function postParseFlowInto(name, node) {
510-
if (Array.isArray(name) && reserved.flowInto.includes(name[0].value.toLowerCase())) {
510+
if (isList(name) && reserved.flowInto.includes(name[0].value.toLowerCase())) {
511511
return error(node)
512512
}
513513
return name
@@ -638,7 +638,7 @@ function postParseGlyphOrientationVertical(orientation, node) {
638638
* It invalidates the line when its name is `span`.
639639
*/
640640
function postParseGridLine(line, node) {
641-
if (Array.isArray(line)) {
641+
if (isList(line)) {
642642
const identifier = line.flat().at(-1)
643643
if (!isOmitted(identifier)) {
644644
const name = identifier.value.toLowerCase()
@@ -673,7 +673,7 @@ function postParseGridLine(line, node) {
673673
* with a whitespace.
674674
*/
675675
function postParseGridTemplateAreas(areas, node) {
676-
if (Array.isArray(areas)) {
676+
if (isList(areas)) {
677677
const strings = []
678678
const named = new Map
679679
for (const [row, { value }] of areas.entries()) {
@@ -1140,7 +1140,7 @@ function postParseOpenTypeTag(tag, node) {
11401140
* It represents the paint list as specified by the author.
11411141
*/
11421142
function postParsePaintOrder(paint) {
1143-
if (Array.isArray(paint)) {
1143+
if (isList(paint)) {
11441144
const res = paint.sort((a, b) => {
11451145
if (isOmitted(a)) {
11461146
return 1
@@ -1417,7 +1417,7 @@ function postParseRandom({ value: [options,, min,, max,, step], ...props }) {
14171417
*/
14181418
function postParseRange(range, node) {
14191419
if (
1420-
Array.isArray(range)
1420+
isList(range)
14211421
&& range.some(bounds =>
14221422
bounds.every(bound => bound.types.includes('<integer>'))
14231423
&& bounds[1].value < bounds[0].value)

lib/parse/shorthand.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const {
1818
zero,
1919
zeroPx,
2020
} = require('../values/defaults.js')
21+
const { isList, isOmitted } = require('../utils/value.js')
2122
const { keywords: cssWideKeywords } = require('../values/substitutions.js')
2223
const { keyword, list, omitted } = require('../values/value.js')
23-
const { isOmitted } = require('../utils/value.js')
2424
const properties = require('../properties/definitions.js')
2525
const shorthands = require('../properties/shorthands.js')
2626
const whiteSpace = require('../values/white-space.js')
@@ -115,7 +115,7 @@ function parseAnimationRange(ranges, longhands) {
115115
*/
116116
function parseAnimationRangeValue(boundaries, endType) {
117117
const [start, end] = boundaries
118-
if (Array.isArray(start) && isOmitted(end)) {
118+
if (isList(start) && isOmitted(end)) {
119119
return list([start, list([start[0], omitted], ' ', [endType])])
120120
}
121121
return boundaries
@@ -300,7 +300,7 @@ function parseBorderImage(values, longhands) {
300300
const longhand = value.types.at(-1)
301301
if (longhand?.startsWith("<'border-image")) {
302302
values.set(longhand.slice(2, -2), value)
303-
} else if (Array.isArray(value)) {
303+
} else if (isList(value)) {
304304
value.reduce(setBorderImageLonghand, values)
305305
}
306306
}
@@ -402,7 +402,7 @@ function parseContainer([name, type]) {
402402
* @see {@link https://drafts.csswg.org/css-flexbox-1/#propdef-flex}
403403
*/
404404
function parseFlex(values) {
405-
if (Array.isArray(values)) {
405+
if (isList(values)) {
406406
const [growShrink, basis] = values
407407
if (isOmitted(basis)) {
408408
const [grow, shrink] = growShrink
@@ -438,7 +438,7 @@ function parseFlex(values) {
438438
*/
439439
function parseFont(values, longhands) {
440440
const declarations = getInitialLonghandDeclarations(longhands)
441-
if (Array.isArray(values)) {
441+
if (isList(values)) {
442442
const [settings, size, lineHeight, family] = values
443443
declarations.set('font-size', size)
444444
declarations.set('font-family', family)
@@ -482,7 +482,7 @@ function parseFont(values, longhands) {
482482
* @see {@link https://drafts.csswg.org/css-fonts-4/#propdef-font-synthesis}
483483
*/
484484
function parseFontSynthesis(values, longhands) {
485-
return Array.isArray(values)
485+
return isList(values)
486486
? parseLonghandsByIndex(values.map(component => isOmitted(component) ? none : auto), longhands)
487487
: setLonghands(values, longhands)
488488
}
@@ -494,7 +494,7 @@ function parseFontSynthesis(values, longhands) {
494494
* @see {@link https://drafts.csswg.org/css-fonts-4/#propdef-font-variant}
495495
*/
496496
function parseFontVariant(values, longhands) {
497-
if (Array.isArray(values)) {
497+
if (isList(values)) {
498498
return parseLonghandsByIndex(values, longhands)
499499
}
500500
const declarations = getInitialLonghandDeclarations(longhands)
@@ -721,7 +721,7 @@ function parseMaskBorder(values, longhands) {
721721
const longhand = value.types.at(-1)
722722
if (longhand?.startsWith("<'mask-border")) {
723723
values.set(longhand.slice(2, -2), value)
724-
} else if (Array.isArray(value)) {
724+
} else if (isList(value)) {
725725
value.reduce(setMaskBorderLonghand, values)
726726
}
727727
}
@@ -803,7 +803,7 @@ function parseTextAlign(component, longhands) {
803803
* @see {@link https://drafts.csswg.org/css-inline-3/#propdef-text-box-edge}
804804
*/
805805
function parseTextBox(values, longhands) {
806-
if (Array.isArray(values)) {
806+
if (isList(values)) {
807807
let [trim, edge] = values
808808
if (isOmitted(trim)) {
809809
trim = keyword('trim-both', 'text-box-trim')
@@ -825,7 +825,7 @@ function parseTextBox(values, longhands) {
825825
* @see {@link https://drafts.csswg.org/css-text-4/#propdef-text-spacing}
826826
*/
827827
function parseTextSpacing(values, longhands) {
828-
if (Array.isArray(values)) {
828+
if (isList(values)) {
829829
return parseLonghandsByIndex(values, longhands)
830830
}
831831
switch (values.value) {
@@ -874,7 +874,7 @@ function parseViewTimeline(values, longhands) {
874874
* @see {@link https://drafts.csswg.org/css-text-4/#propdef-white-space}
875875
*/
876876
function parseWhiteSpace(values, longhands) {
877-
if (!Array.isArray(values)) {
877+
if (!isList(values)) {
878878
values = whiteSpace.get(values.value)
879879
}
880880
return parseLonghandsByIndex(values, longhands)

0 commit comments

Comments
 (0)