Skip to content

Commit 76c2541

Browse files
committed
Minor things
1 parent fe37c08 commit 76c2541

File tree

7 files changed

+17
-18
lines changed

7 files changed

+17
-18
lines changed

doc/parse/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Some rules like `@charset`, `@import`, `@namespace`, `@layer`, also define the o
155155

156156
However, CSS Syntax does not prescribe when and how to construct the CSSOM representation.
157157

158-
Parsing a style sheet must run recursively from its top to bottom level, which allows to construct the CSSOM tree in parallel, noting that a `CSSStyleSheet` will never be discarded, or with a second traversal, to avoid discarding `CSSRule`s and cancelling any processing, like fetching a style sheet referenced by a `CSSImportRule`.
158+
Parsing a style sheet must run recursively from its top to bottom level, which allows constructing the CSSOM tree in parallel, noting that a `CSSStyleSheet` will never be discarded, or with a second traversal, to avoid discarding `CSSRule`s and cancelling any processing, like fetching a style sheet referenced by a `CSSImportRule`.
159159

160160
---
161161

lib/parse/arbitrary.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Stream = require('./stream.js')
55
const blocks = require('../values/blocks.js')
66
const createError = require('../error.js')
77

8-
const endingTokens = Object.values(blocks.associatedTokens)
8+
const closingTokens = Object.values(blocks.associatedTokens)
99

1010
/**
1111
* @param {object} node
@@ -25,7 +25,7 @@ function error({ definition: { name, value } }) {
2525
* It deviates from the specification by trimming whitespaces.
2626
*/
2727
function matchAnyValue(input, restricted, stops = []) {
28-
stops = [...endingTokens, ...stops]
28+
stops = [...closingTokens, ...stops]
2929
const values = list([], '')
3030
input.consume(isWhitespace)
3131
while (!input.atEnd()) {

lib/parse/definition.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ function consumeRangeBoundary(chars, infinity) {
6666
* @returns {object}
6767
*/
6868
function consumeRange(chars, infinity = Infinity) {
69-
const endingToken = blocks.associatedTokens[chars.current]
69+
const closingToken = blocks.associatedTokens[chars.current]
7070
const bounds = []
7171
for (const char of chars) {
7272
switch (char) {
73-
case endingToken: {
73+
case closingToken: {
7474
const [min, max = min] = bounds
7575
return { max, min }
7676
}
@@ -84,7 +84,7 @@ function consumeRange(chars, infinity = Infinity) {
8484
break
8585
}
8686
}
87-
throw error({ message: `Missing "${endingToken}"` })
87+
throw error({ message: `Missing "${closingToken}"` })
8888
}
8989

9090
/**

lib/parse/grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ function create(definition, input, context, parent = null) {
567567
context,
568568
definition,
569569
input,
570-
location: input.index ?? null,
570+
location: input.index,
571571
parent,
572572
state: 'waiting',
573573
}

lib/parse/parser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const shorthands = require('../properties/shorthands.js')
1313
const substitutions = require('../values/substitutions.js')
1414

1515
const contextType = Symbol('context')
16-
const endingTokens = Object.values(blocks.associatedTokens)
16+
const closingTokens = Object.values(blocks.associatedTokens)
1717

1818
const EXTRA_COMPONENT_VALUE_ERROR = {
1919
message: 'Cannot parse more than a single component value',
@@ -392,9 +392,9 @@ function consumeFunction(tokens, { start, value: name }) {
392392
* It deviates from the specification by trimming whitespaces.
393393
*/
394394
function consumeSimpleBlock(tokens, { start, value: associatedToken }) {
395-
const endingToken = blocks.associatedTokens[associatedToken]
396-
const value = consumeComponentValueList(tokens, [endingToken])
397-
if (!tokens.consume(isDelimiter(endingToken))) {
395+
const closingToken = blocks.associatedTokens[associatedToken]
396+
const value = consumeComponentValueList(tokens, [closingToken])
397+
if (!tokens.consume(isDelimiter(closingToken))) {
398398
error({ message: 'Unclosed block' })
399399
}
400400
return { associatedToken, end: tokens.current.end, start, types: ['<simple-block>'], value }
@@ -492,7 +492,7 @@ function consumeDeclarationValue(tokens, forCustomProperty, nested) {
492492
break
493493
}
494494
// Invalid token
495-
if (token.types[0].startsWith('<bad-') || isDelimiter(endingTokens, token)) {
495+
if (token.types[0].startsWith('<bad-') || isDelimiter(closingTokens, token)) {
496496
return error(INVALID_DECLARATION_VALUE_ERROR)
497497
}
498498
const value = consumeComponentValue(tokens)

lib/parse/types.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ const staticCalcKeywords = nonTerminal['<calc-keyword>'].split(' | ')
1818
*/
1919
function areEqualTypes(type1, type2, left = true) {
2020
for (const [type, power] of type1) {
21-
const value = type2.get(type)
22-
if (power === 0 && !value) {
21+
if (power === 0 && !type2.has(type)) {
2322
continue
2423
}
25-
if (power !== value) {
24+
if (power !== type2.get(type)) {
2625
return false
2726
}
2827
}
@@ -408,11 +407,11 @@ function getCalculationType(calculation, resolutionType) {
408407
* @see {@link https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue-match}
409408
*/
410409
function matchNumericType(type, production, resolutionType = null) {
411-
// For convenience, allow to run this function with a type failure
410+
// For convenience, allow running this function with a type failure
412411
if (type === null) {
413412
return false
414413
}
415-
// Allow to run this function with some productions to match
414+
// Allow running this function with some productions to match
416415
if (Array.isArray(production)) {
417416
return production.some(production => matchNumericType(type, production, resolutionType))
418417
}

lib/serialize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ function serializeColor({ name, types, value }, specified) {
429429
value = canonicalize(component).value
430430
} else if (types[0] === '<function>') {
431431
// Only extract a resolved math function value for sRGB color functions
432-
if (!isSRGB || !value || !isNumeric(value, true)) {
432+
if (!isSRGB || value === undefined || !isNumeric(value, true)) {
433433
resolved = false
434434
value = serializeCalculationFunction(component)
435435
if (isAlpha) {

0 commit comments

Comments
 (0)