Skip to content

Commit 49c8821

Browse files
committed
Minor things
1 parent 400134c commit 49c8821

File tree

5 files changed

+30
-33
lines changed

5 files changed

+30
-33
lines changed

doc/parse/parser.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ A CSS rule definition must define:
161161
- whether declarations cascade
162162
- whether it applies to elements
163163

164-
The grammar may be extended depending on the context. CSS-wide keywords, arbitrary and whole value substitutions, are not part of a specific property grammar but are accepted for any property, and for descriptors in some contexts. Similarly, some numeric substitutions are only valid in contexts applying to an element.
164+
The grammar may be extended depending on the context. Arbitrary and whole value substitutions are not part of a specific property grammar but are accepted for any property, and for descriptors in some contexts. Similarly, some numeric substitutions are only valid in contexts applying to an element.
165165

166166
`Element.style`, `Element.sizes`, `CanvasTextDrawingStyles.font`, `CSSFontFeatureValuesMap.set()`, etc, use parser entry points that take a grammar but no context. However, since CSS Syntax often requires validating values *"in the context"*, it is implicitly required, and the `grammar` argument can remain context-free. It cannot represent a style rule by default, since none of the above interfaces are associated to a style rule.
167167

doc/serialize/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ CSS values are currently represented either as a `List` or a plain object, with
4646
> 4. Replace each component value in components with the result of invoking *serialize a CSS component value*.
4747
> 5. Join the items of components into a single string, inserting `" "` (U+0020 SPACE) between each pair of items unless the second item is a `","` (U+002C COMMA). Return the result.
4848
49-
Step 3 is skipped since `<whitespace-token>`s are already removed from the representation of all productions but arbitrary ones (this could otherwise prevent validating a parent production like `<whole-value>`), which are represented with a `List` whose `separator` is an empty string.
49+
Step 3 is skipped since leading and trailing `<whitespace-token>`s are already removed while consuming a list of component values and in the parse result, except for arbitrary substitution containing values, which are represented with a `List` whose `separator` is an empty string.

lib/parse/arbitrary.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function matchAnyValue(input, restricted, stops = []) {
5353
* @returns {object}
5454
* @see {@link https://drafts.csswg.org/css-syntax-3/#typedef-block-contents}
5555
*/
56-
function matchBlockContents(node, parser) {
57-
if (node.context.rule) {
56+
function matchBlockContents({ context, input }, parser) {
57+
if (context.rule) {
5858
return parser.parseBlockContents(input, context)
5959
}
6060
return parser.parseStyleSheet(input, context)

lib/parse/parser.js

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,11 @@ function getRuleDefinition({ root, rule }, name, prelude, type) {
320320
}
321321

322322
/**
323-
* @param {CSSRuleImpl|CSSFontFeatureValuesMap|CSSStyleSheetImpl|Element|...string} [identifiers] CSSOM value or rule name(s)
324-
* @returns {object[]}
323+
* @param {CSSRuleImpl|CSSFontFeatureValuesMap|CSSStyleSheetImpl|Element|object|string|string[]} [value]
324+
* @returns {object}
325325
*/
326-
function createContext(...identifiers) {
327-
const value = identifiers[0]
326+
function createContext(value) {
327+
328328
if (value?.type === contextType) {
329329
return value
330330
}
@@ -342,34 +342,31 @@ function createContext(...identifiers) {
342342
const definition = value._definition
343343
return { ...context, rule: { context, definition, value } }
344344
}
345+
345346
const namespaces = new Set(['*'])
346-
const globals = new Map([['namespaces', namespaces]])
347-
const trees = []
347+
const context = {
348+
globals: new Map([['namespaces', namespaces]]),
349+
definition: root,
350+
trees: [],
351+
}
352+
348353
if (!value) {
349-
return { globals, trees, type: contextType }
354+
return context
350355
}
351356
if (CSSStyleSheet.isImpl(value)) {
352357
value._rules?.forEach(rule => {
353358
if (CSSNamespaceRule.isImpl(rule)) {
354359
namespaces.add(rule.prefix)
355360
}
356361
})
357-
return {
358-
globals,
359-
root: { definition: root, value },
360-
trees,
361-
type: contextType,
362-
}
363-
}
364-
const context = {
365-
globals,
366-
root: { definition: root },
367-
trees,
368-
type: contextType,
362+
return { ...context, value }
369363
}
370364
// Rule name(s)
371365
if (typeof value === 'string') {
372-
return identifiers.reduce(
366+
value = [value]
367+
}
368+
if (Array.isArray(value)) {
369+
return value.reduce(
373370
(context, name) => {
374371
const { root, rule } = context
375372
const contextDefinition = rule ? rule.definition.value : root.definition
@@ -864,7 +861,7 @@ function parseComponentValueList(input) {
864861

865862
/**
866863
* @param {Stream|string|object[]} input
867-
* @param {CSSRuleImpl|Element|object|string} context
864+
* @param {CSSRuleImpl|CSSFontFeatureValuesMap|Element|object|string|string[]} context
868865
* @returns {SyntaxError|object|null}
869866
* @see {@link https://drafts.csswg.org/css-syntax-3/#parse-a-declaration}
870867
*
@@ -880,7 +877,7 @@ function parseDeclaration(input, context) {
880877

881878
/**
882879
* @param {Stream|string|object[]} input
883-
* @param {CSSRuleImpl|CSSStyleSheet} context
880+
* @param {CSSRuleImpl|CSSStyleSheetImpl|object|string|string[]} context
884881
* @returns {SyntaxError|CSSRuleImpl}
885882
* @see {@link https://drafts.csswg.org/css-syntax-3/#parse-a-rule}
886883
*/
@@ -906,7 +903,7 @@ function parseRule(input, context) {
906903

907904
/**
908905
* @param {Stream|string|object[]} input
909-
* @param {CSSRuleImpl|Element} context
906+
* @param {CSSRuleImpl|CSSFontFeatureValuesMap|Element|object|string|string[]} context
910907
* @returns {object[]}
911908
*/
912909
function parseDeclarationBlock(input, context) {
@@ -918,7 +915,7 @@ function parseDeclarationBlock(input, context) {
918915

919916
/**
920917
* @param {Stream|string|object[]} input
921-
* @param {CSSRuleImpl|Element} context
918+
* @param {CSSRuleImpl|CSSFontFeatureValuesMap|Element|object|string|string[]} context
922919
* @returns {object[]}
923920
* @see {@link https://drafts.csswg.org/css-syntax-3/#parse-a-blocks-contents}
924921
*/
@@ -1030,7 +1027,7 @@ function parseCSSValueSubstitution(input, context) {
10301027
/**
10311028
* @param {Stream|string|object[]} value
10321029
* @param {object|string} definition
1033-
* @param {object} context
1030+
* @param {CSSRuleImpl|CSSFontFeatureValuesMap|Element|object|string|string[]} [context]
10341031
* @returns {SyntaxError|object|object[]|null}
10351032
* @see {@link https://drafts.csswg.org/cssom-1/#parse-a-css-value}
10361033
*/
@@ -1053,7 +1050,7 @@ function parseCSSDeclarationValue(value, definition, context) {
10531050
* @param {string} name
10541051
* @param {string} value
10551052
* @param {boolean} important
1056-
* @param {CSSRuleImpl|Element|string} context
1053+
* @param {CSSRuleImpl|CSSFontFeatureValuesMap|Element|object|string|string[]} context
10571054
* @returns {object|null}
10581055
*/
10591056
function parseCSSDeclaration(name, value, important, context) {
@@ -1112,7 +1109,7 @@ function parseCSSStyleSheet(rules) {
11121109
/**
11131110
* @param {Stream|string|object[]} input
11141111
* @param {string} definition
1115-
* @param {CSSRuleImpl|Element|string} [context]
1112+
* @param {CSSRuleImpl|CSSFontFeatureValuesMap|CSSStyleSheetImpl|Element|object|string|string[]} [context]
11161113
* @param {string} [strategy]
11171114
* @returns {SyntaxError|object|object[]|null}
11181115
* @see {@link https://drafts.csswg.org/css-syntax-3/#css-parse-something-according-to-a-css-grammar}
@@ -1154,7 +1151,7 @@ function parseCSSGrammar(input, definition, context, strategy = 'backtrack') {
11541151
/**
11551152
* @param {Stream|string|object[]} input
11561153
* @param {object|string} grammar
1157-
* @param {CSSRuleImpl|Element|string} [context]
1154+
* @param {CSSRuleImpl|CSSFontFeatureValuesMap|CSSStyleSheetImpl|Element|object|string|string[]} [context]
11581155
* @returns {object[]|null}
11591156
* @see {@link https://drafts.csswg.org/css-syntax-3/#css-parse-a-comma-separated-list-according-to-a-css-grammar}
11601157
*/

scripts/extract.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ const excluded = {
567567
'<mask-source>',
568568
],
569569
'css-values-5': [
570-
// TODO: add support for `<boolean-expr[<test>]`
570+
// TODO: add support for `<boolean-expr[<test>]>`
571571
'<if()>',
572572
'<if-condition>',
573573
'<if-test>',

0 commit comments

Comments
 (0)