Skip to content

Commit 06465d3

Browse files
committed
Minor things
1 parent 3fb81da commit 06465d3

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

lib/parse/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ function consumeAtRule(tokens, context, nested) {
691691
* order.
692692
*/
693693
function consumeBlock(tokens, context, ignoreCloseCurlyBlock) {
694-
const rules = []
694+
const rules = list([], ' ', '<block-contents>')
695695
const declarations = []
696696
while (!tokens.atEnd()) {
697697
if (tokens.consume(isWhitespace) || tokens.consume(isSemicolon)) {

lib/parse/postprocess.js

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

2-
const { angle, keyword, list, map, number, omitted, string } = require('../values/value.js')
2+
const { angle, keyword, list, number, omitted, string } = require('../values/value.js')
33
const { findContext, findParent, findSibling } = require('../utils/context.js')
44
const { getCalculationType, matchNumericType } = require('./types.js')
55
const { isCalculation, isColon, isList, isOmitted, isWhitespace } = require('../utils/value.js')
@@ -192,7 +192,7 @@ function postParseBorderRadius(radii) {
192192
}
193193

194194
/**
195-
* @param {object[]} product
195+
* @param {object|object[]} product
196196
* @returns {object[]}
197197
* @see {@link https://drafts.csswg.org/css-values-4/#typedef-calc-product}
198198
* @see {@link https://drafts.csswg.org/css-values-4/#parse-a-calculation}
@@ -215,7 +215,7 @@ function postParseCalcProduct([left, tail]) {
215215
}
216216

217217
/**
218-
* @param {object[]} sum
218+
* @param {object|object[]} sum
219219
* @returns {object|object[]}
220220
* @see {@link https://drafts.csswg.org/css-values-4/#typedef-calc-sum}
221221
* @see {@link https://drafts.csswg.org/css-values-4/#parse-a-calculation}

lib/parse/stream.js

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

2+
/**
3+
* @param {string|object[]}
4+
* @returns {string|[]}
5+
*/
6+
function empty(value) {
7+
return Array.isArray(value) ? [] : ''
8+
}
9+
210
class Stream {
311

412
index = -1
@@ -21,13 +29,6 @@ class Stream {
2129
return this.data[this.index]
2230
}
2331

24-
/**
25-
* @returns {string|object[]}
26-
*/
27-
get empty() {
28-
return Array.isArray(this.data) ? [] : ''
29-
}
30-
3132
/**
3233
* @yields {object|string}
3334
*/
@@ -69,7 +70,7 @@ class Stream {
6970
const fallback = args[0] ?? null
7071
if (typeof n === 'number') {
7172
if (1 < n) {
72-
let consumed = this.empty
73+
let consumed = empty(this.data)
7374
while (n-- && !this.atEnd()) {
7475
consumed = consumed.concat(data[++this.index])
7576
}
@@ -95,7 +96,7 @@ class Stream {
9596
* @returns {string|object[]}
9697
*/
9798
consumeRunOf(...items) {
98-
let consumed = this.empty
99+
let consumed = empty(this.data)
99100
let last
100101
while (items.some(item => last = this.consume(item))) {
101102
consumed = consumed.concat(last)
@@ -108,8 +109,8 @@ class Stream {
108109
* @returns {string|object[]}
109110
*/
110111
consumeUntil(item) {
111-
const { data, empty, index: start } = this
112-
let consumed = empty
112+
const { data, index: start } = this
113+
let consumed = empty(data)
113114
while (this.index < data.length) {
114115
const next = data[this.index + 1]
115116
if (next === item) {
@@ -143,7 +144,7 @@ class Stream {
143144
}
144145
switch (size) {
145146
case 0:
146-
return this.empty
147+
return empty(this.data)
147148
case 1:
148149
return this.data[this.index + offset + size]
149150
default:
@@ -164,7 +165,7 @@ class Stream {
164165
}
165166
switch (size) {
166167
case 0:
167-
return this.empty
168+
return empty(this.data)
168169
case 1:
169170
return this.data[this.index - offset - size]
170171
default:

lib/parse/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ function getCalculationFunctionType({ name, value }, resolutionType) {
301301
case 'random':
302302
case 'rem':
303303
case 'round':
304-
return combineCalculationTypes(addTypes, value.flat().filter(isCalculation), resolutionType)
304+
return combineCalculationTypes(addTypes, value.filter(isCalculation), resolutionType)
305305
case 'container-progress':
306306
case 'media-progress': {
307307
const feature = value[0].value

lib/values/value.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class List extends Array {
1212
/**
1313
* @see {@link https://github.com/tc39/proposal-rm-builtin-subclassing}
1414
*
15-
* It prevents `list([1]).map(id)` from returning `[undefined, 1]`, and is
16-
* compatible with a future breaking change.
15+
* It enforces returning Array rather than a List, which is consistent with
16+
* the TC39 proposal above.
1717
*/
1818
static get [Symbol.species]() {
1919
return Array
@@ -64,7 +64,7 @@ function list(values = [], separator = ' ', types = []) {
6464
/**
6565
* @param {object} value
6666
* @param {function} transform
67-
* @param {string[]} newTypes
67+
* @param {string[]} [newTypes]
6868
* @returns {object}
6969
*/
7070
function map({ end, start, types, value, ...props }, transform, newTypes = []) {

0 commit comments

Comments
 (0)