Skip to content

Commit 4e71f67

Browse files
committed
Minor things
1 parent 19c8d49 commit 4e71f67

File tree

15 files changed

+105
-100
lines changed

15 files changed

+105
-100
lines changed

__tests__/stylesheet.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('CSSStyleSheet.insertRule(), CSSStyleSheet.deleteRule()', () => {
144144
expect(() => styleSheet.deleteRule(0)).toThrow(ACCESS_THIRD_PARTY_STYLESHEET_ERROR)
145145
})
146146
it('throws an error when trying to insert/delete a rule while modifications on the style sheet are not allowed', () => {
147-
const styleSheet = new globalThis.CSSStyleSheet()
147+
const styleSheet = new globalThis.CSSStyleSheet
148148
styleSheet.replace('')
149149
expect(() => styleSheet.insertRule('style {}')).toThrow(UPDATE_LOCKED_STYLESHEET_ERROR)
150150
expect(() => styleSheet.deleteRule(0)).toThrow(UPDATE_LOCKED_STYLESHEET_ERROR)
@@ -159,7 +159,7 @@ describe('CSSStyleSheet.insertRule(), CSSStyleSheet.deleteRule()', () => {
159159
expect(() => styleSheet.insertRule('style {};')).toThrow(EXTRA_RULE_ERROR)
160160
})
161161
it('throws an error when trying to insert @import in a constructed style sheet', () => {
162-
const styleSheet = new globalThis.CSSStyleSheet()
162+
const styleSheet = new globalThis.CSSStyleSheet
163163
expect(() => styleSheet.insertRule('@import "./global.css";')).toThrow(INSERT_INVALID_IMPORT_ERROR)
164164
})
165165
it('throws an error when trying to insert/delete a rule at an index greater than the length of rules', () => {
@@ -245,13 +245,13 @@ describe('CSSStyleSheet.replace(), CSSStyleSheet.replaceSync()', () => {
245245
expect(() => styleSheet.replaceSync('')).toThrow(UPDATE_LOCKED_STYLESHEET_ERROR)
246246
})
247247
it('throws an error when trying to replace rules concurrently', async () => {
248-
const styleSheet = new globalThis.CSSStyleSheet()
248+
const styleSheet = new globalThis.CSSStyleSheet
249249
styleSheet.replace('')
250250
return expect(styleSheet.replace('')).rejects.toMatchObject(UPDATE_LOCKED_STYLESHEET_ERROR)
251251
})
252252
it('replaces a rule asynchronously/synchronously', async () => {
253253

254-
const styleSheet = new globalThis.CSSStyleSheet()
254+
const styleSheet = new globalThis.CSSStyleSheet
255255
const { cssRules } = styleSheet
256256

257257
expect(await styleSheet.replace('style { color: orange }')).toBe(styleSheet)
@@ -265,15 +265,15 @@ describe('CSSStyleSheet.replace(), CSSStyleSheet.replaceSync()', () => {
265265
})
266266
it('ignores opening and ending HTML comment tokens', () => {
267267

268-
const styleSheet = new globalThis.CSSStyleSheet()
268+
const styleSheet = new globalThis.CSSStyleSheet
269269

270270
styleSheet.replaceSync('<!-- style {} -->')
271271

272272
expect(styleSheet.cssRules).toHaveLength(1)
273273
})
274274
it('ignores import rules and invalid statements', () => {
275275

276-
const styleSheet = new globalThis.CSSStyleSheet()
276+
const styleSheet = new globalThis.CSSStyleSheet
277277

278278
styleSheet.replaceSync(`
279279
@import "./global.css";

__tests__/value.js

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
hash,
1414
ident,
1515
identToken,
16+
integer,
1617
keyword,
1718
length,
1819
list,
@@ -1165,7 +1166,7 @@ describe('<integer>', () => {
11651166
invalid.forEach(input => expect(parse('<integer [0,∞]>', input, false)).toBeNull())
11661167
})
11671168
test('representation', () => {
1168-
expect(parse('<integer>', '1', false)).toMatchObject(numberToken(1, ['<integer>']))
1169+
expect(parse('<integer>', '1', false)).toMatchObject(integer(1))
11691170
})
11701171
test('valid', () => {
11711172
const valid = [
@@ -3135,21 +3136,21 @@ describe('<counter-style-name>', () => {
31353136
expect(parse('<counter-style-name>', 'NAME')).toBe('NAME')
31363137
})
31373138
})
3138-
describe('<dashed-function-head>', () => {
3139+
describe('<custom-function-definition>', () => {
31393140
test('invalid', () => {
3140-
expect(parse('<dashed-function-head>', 'custom()', false)).toBeNull()
3141+
expect(parse('<custom-function-definition>', 'custom()', false)).toBeNull()
31413142
})
31423143
test('representation', () => {
31433144
const nameAndParameters = {
31443145
name: '--CUSTOM',
31453146
types: ['<function>'],
31463147
value: omitted,
31473148
}
3148-
const head = list([nameAndParameters, omitted], ' ', ['<dashed-function-head>'])
3149-
expect(parse('<dashed-function-head>', '--CUSTOM()', false)).toMatchObject(head)
3149+
const definition = list([nameAndParameters, omitted], ' ', ['<custom-function-definition>'])
3150+
expect(parse('<custom-function-definition>', '--CUSTOM()', false)).toMatchObject(definition)
31503151
})
31513152
test('valid', () => {
3152-
expect(parse('<dashed-function-head>', '--custom() returns type(*)')).toBe('--custom()')
3153+
expect(parse('<custom-function-definition>', '--custom() returns type(*)')).toBe('--custom()')
31533154
})
31543155
})
31553156
describe('<drop-shadow()>', () => {
@@ -3544,12 +3545,12 @@ describe('<mf-comparison>', () => {
35443545
})
35453546
describe('<mf-boolean>', () => {
35463547
test('invalid', () => {
3548+
expect(parse('<mf-boolean>', 'min-color', false, mediaRule)).toBeNull()
35473549
expect(parse('<mf-boolean>', 'min-orientation', false, mediaRule)).toBeNull()
3548-
expect(parse('<mf-boolean>', 'min-width', false, mediaRule)).toBeNull()
35493550
})
35503551
test('representation', () => {
3551-
expect(parse('<mf-boolean>', 'width', false, mediaRule))
3552-
.toMatchObject(ident('width', ['<mf-name>', '<mf-boolean>']))
3552+
expect(parse('<mf-boolean>', 'color', false, mediaRule))
3553+
.toMatchObject(ident('color', ['<mf-name>', '<mf-boolean>']))
35533554
})
35543555
test('valid', () => {
35553556
expect(parse('<mf-boolean>', 'orientation', true, mediaRule)).toBe('orientation')
@@ -3561,7 +3562,7 @@ describe('<mf-name>', () => {
35613562
expect(parse('<mf-name>', 'inline-size', false, mediaRule)).toBeNull()
35623563
})
35633564
test('representation', () => {
3564-
expect(parse('<mf-name>', 'width', false, mediaRule)).toMatchObject(ident('width', ['<mf-name>']))
3565+
expect(parse('<mf-name>', 'color', false, mediaRule)).toMatchObject(ident('color', ['<mf-name>']))
35653566
})
35663567
test('valid', () => {
35673568
const valid = [
@@ -3578,26 +3579,26 @@ describe('<mf-plain>', () => {
35783579
test('invalid', () => {
35793580
const invalid = [
35803581
'min-orientation: landscape',
3581-
'width: 1',
3582+
'color: red',
35823583
// Element-dependent numeric substitution
3583-
'width: calc-mix(0, 1px, 1px)',
3584-
'width: random(1px, 1px)',
3585-
'width: calc(1px * sibling-index())',
3584+
'color: calc-mix(0, 1, 1)',
3585+
'color: random(1, 1)',
3586+
'color: sibling-index()',
35863587
]
35873588
invalid.forEach(input => expect(parse('<mf-plain>', input, false, mediaRule)).toBeNull())
35883589
})
35893590
test('representation', () => {
3590-
const name = ident('width', ['<mf-name>'])
3591-
const value = length(1, 'px', ['<mf-value>'])
3591+
const name = ident('color', ['<mf-name>'])
3592+
const value = integer(1, ['<mf-value>'])
35923593
const feature = list([name, delimiter(':'), value], ' ', ['<mf-plain>'])
3593-
expect(parse('<mf-plain>', 'width: 1px', false, mediaRule)).toMatchObject(feature)
3594+
expect(parse('<mf-plain>', 'color: 1', false, mediaRule)).toMatchObject(feature)
35943595
})
35953596
test('valid', () => {
35963597
const valid = [
35973598
['orientation: PORTRAIT', 'orientation: portrait'],
35983599
['color: 1.0', 'color: 1'],
35993600
['min-width: 0', 'min-width: 0px'],
3600-
['width: calc(1px * 1)', 'width: calc(1px)'],
3601+
['color: calc(1 * 1)', 'color: calc(1)'],
36013602
['aspect-ratio: 1', 'aspect-ratio: 1 / 1'],
36023603
]
36033604
valid.forEach(([input, expected]) => expect(parse('<mf-plain>', input, true, mediaRule)).toBe(expected))
@@ -3607,33 +3608,33 @@ describe('<mf-range>', () => {
36073608
test('invalid', () => {
36083609
const invalid = [
36093610
// Prefixed <mf-name>
3610-
'min-width = 1px',
3611-
'1px < min-width < 1px',
3611+
'min-color = 1',
3612+
'1 < min-color < 1',
36123613
// Discrete <mf-name>
36133614
'orientation = 1',
36143615
'1 < orientation < 1',
36153616
// Invalid <mf-value>
3616-
'width = 1',
3617-
'1 < width < 1px',
3618-
'1px < width < 1',
3617+
'color = 1px',
3618+
'1 < color < 1px',
3619+
'1px < color < 1',
36193620
// Element-dependent numeric substitutions
3620-
'width < calc-mix(0, 1px, 1px)',
3621-
'width < random(1px, 1px)',
3622-
'width < calc(1px * sibling-index())',
3621+
'color < calc-mix(0, 1, 1)',
3622+
'color < random(1, 1)',
3623+
'color < sibling-index()',
36233624
]
36243625
invalid.forEach(input => expect(parse('<mf-range>', input, false, mediaRule)).toBeNull())
36253626
})
36263627
test('representation', () => {
3627-
const name = ident('width', ['<mf-name>'])
3628+
const name = ident('color', ['<mf-name>'])
36283629
const comparator = delimiter('=', ['<mf-eq>', '<mf-comparison>'])
3629-
const value = length(1, 'px', ['<mf-value>'])
3630+
const value = integer(1, ['<mf-value>'])
36303631
const range = list([name, comparator, value], ' ', ['<mf-range>'])
3631-
expect(parse('<mf-range>', 'width = 1px', false, mediaRule)).toMatchObject(range)
3632+
expect(parse('<mf-range>', 'color = 1', false, mediaRule)).toMatchObject(range)
36323633
})
36333634
test('valid', () => {
36343635
const valid = [
3635-
['width < 0', 'width < 0px'],
3636-
['width < calc(1px * 1)', 'width < calc(1px)'],
3636+
['color < 0', 'color < 0'],
3637+
['color < calc(1 * 1)', 'color < calc(1)'],
36373638
['0 < aspect-ratio < 1', '0 / 1 < aspect-ratio < 1 / 1'],
36383639
]
36393640
valid.forEach(([input, expected]) => expect(parse('<mf-range>', input, true, mediaRule)).toBe(expected))
@@ -3889,7 +3890,7 @@ describe('<step-easing-function>', () => {
38893890
expect(parse('<step-easing-function>', 'steps(1)', false)).toMatchObject({
38903891
name: 'steps',
38913892
types: ['<function>', '<steps()>', '<step-easing-function>'],
3892-
value: list([numberToken(1, ['<integer>']), omitted, omitted]),
3893+
value: list([integer(1), omitted, omitted]),
38933894
})
38943895
})
38953896
test('valid', () => {

doc/parse/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Each *parse* procedure from CSS Syntax is named a *parser entry point* and runs
137137
>
138138
> [...]
139139
140-
Entry points can receive a string, tokens, or component values, and output the expected structure: a component value, a declaration, a rule, or a list of them. They are not intended to be used at an intermediate step of the recursive parsing process, since some algorithms output high-level objects that are not a string, tokens, or component values.
140+
Entry points can receive a string, tokens, or component values, and output the expected structure: a component value, a declaration, a rule, or a list of them. They are not intended to be used at an intermediate step of the recursive parse process, since some algorithms output high-level objects that are not a string, tokens, or component values.
141141

142142
Algorithms for a rule and a declaration require validating them in the context against their grammar:
143143

doc/parse/value-data-structure.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ Consuming the input into tokens is the first parse step before consuming tokens
99

1010
A token represents either:
1111

12-
- a delimiter (a single code point, `<--`, or `-->`)
1312
- a numeric
1413
- an identifier (possibly prefixed with `#` or `@`)
1514
- a string (wrapped between `"` or `'`)
1615
- a specific sequence of code points (`<function-token>`, `<url-token>`, `<unicode-range-token>`)
16+
- a delimiter (a single code point, `<--`, or `-->`)
1717

1818
A token is defined in CSS Syntax with the following properties:
1919

2020
- `value`: a `Number` for numeric tokens, otherwise a `String`
21-
- `sign`: a `String` only for `<number-token>`, `<dimension-token>`, `<percentage-token>`
21+
- `sign`: a `String`, only for `<number-token>`, `<dimension-token>`, `<percentage-token>`
2222
- `type`: a `String`, only for `<hash-token>`, `<number-token>`, `<dimension-token>`
2323
- `unit`: a `String`, only for `<dimension-token>`
2424

25-
A component value is the same object than the consumed token, except a function or simple block, whose `value` is a list of component values. A function also has a `name` and a simple block has an `associatedToken`, which are both `String`.
25+
Except for functions and simple blocks, a component value is the same object than the consumed token: a preserved token. The `value` of functions and simple blocks is a list of component values. A function also has a `name` and a simple block has an `associatedToken`, which are both `String`.
2626

27-
A component value must expose its token type in order to be matched against a token production. Some production rules include token productions:
27+
A preserved token must expose its type in order to be matched against a token production. Some production rules directly include a token type:
2828

2929
- `<function-token>`
3030
- `<general-enclosed>`
@@ -42,20 +42,20 @@ A component value must expose its token type in order to be matched against a to
4242
- `<string-token>`
4343
- `<attribute-selector>`
4444

45-
**[Issue](https://github.com/w3c/csswg-drafts/issues/7016):** `<function-token>` cannot be matched because because any CSS input goes through *consume a component value* before grammar validation.
45+
**[Issue](https://github.com/w3c/csswg-drafts/issues/7016):** `<function-token>` cannot be matched because any CSS input goes through *consume a component value* before grammar validation.
4646

47-
A component value must expose its matched CSS type(s) in hierarchical order, to apply any associated parsing and serialization rule. For example, a component value matching `<percentage>` and `<alpha-value>` must serialize as a `<number>` to the shortest possible form, therefore `<alpha-value>` must be read before `<percentage>`.
47+
A component value must expose its matched CSS type(s) in parse order, to apply any associated parsing and serialization rule. For example, a component value matching `<percentage>` and `<alpha-value>` must serialize as a `<number>` to the shortest possible form rather than as a `<percentage>`, therefore `<alpha-value>` must be read before `<percentage>`.
4848

4949
---
5050

5151
All component values are represented as plain objects exposing token and CSS types with a `types` property, rather than using classes (eg. `CSSNumber`, `CSSDimension`, etc) or separate properties (eg. `tokenType` and `cssTypes`).
5252

53-
A `<percentage-token>` can also be considered as a dimension (cf. [#7381](https://github.com/w3c/csswg-drafts/issues/7381)), therefore it also has `unit`, to simplify parsing and serializing.
53+
A `<percentage-token>` can also be considered as a dimension (cf. [#7381](https://github.com/w3c/csswg-drafts/issues/7381)), therefore it is also implemented with a `unit` property, to simplify parsing and serializing.
5454

5555
In CSS Syntax:
5656

5757
- `<number-token>` and `<dimension-token>` are defined with a `type` that is either `integer` or `number`
58-
- `<*-integer>` and `<*-dimension>` (produced by `<an+b>`) match `<number-token>` and `<dimension-token>` whose `type` is `integer`
58+
- `<*-integer>` and `<*-dimension>` produced by `<an+b>` match `<number-token>` and `<dimension-token>` whose `type` is `integer`
5959
- `type` is `number` when the value is specified with `.` or the scientific notation (even `1.0` or `1e1`)
6060

6161
In this library, `<number-token>` and `<dimension-token>` do not have `type` and `<integer>`, `<*-integer>`, `<*-dimension>`, match a corresponding token whose `value` is an integer, which means `nth-child(1e1)` or `nth-child(1e1n)` should be discarded.
@@ -64,4 +64,4 @@ In this library, `<number-token>` and `<dimension-token>` do not have `type` and
6464

6565
A declaration is represented as a plain object with `types` including `<declaration>`, in order to be serialized when it appears in a list of component values (the prelude of `@supports`).
6666

67-
A rule is initially represented as a plain object with `types` including `rule`, either `at-rule` or `qualified-rule`, and an identifier prefixed with `@` that usually corresponds to the rule name. Then it is represented as an instance of a `CSSRule` subclass with an internal `types`.
67+
A rule and a style sheet are directly represented as a CSSOM object.

lib/cssom/CSSFontFeatureValuesMap-impl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CSSFontFeatureValuesMapImpl {
3131
[name, Array.isArray(value) ? [...value.map(component => component.value)] : [value.value]])
3232
this._map = new Map(entries)
3333
} else {
34-
this._map = new Map()
34+
this._map = new Map
3535
}
3636
}
3737

lib/parse/arbitrary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function matchAnyValue(input, restricted, stops = []) {
5252
* @returns {boolean}
5353
*/
5454
function isGeneralFunctionalNotation({ definition, input }) {
55-
return !(definition.name || input.current.name.startsWith('--'))
55+
return !definition.name && !input.current.name.startsWith('--')
5656
}
5757

5858
/**

lib/parse/grammar.js

Lines changed: 12 additions & 13 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 } = require('../utils/value.js')
4+
const { isDelimiter, 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')
@@ -228,37 +228,36 @@ function match(node, parser) {
228228
}
229229

230230
/**
231-
* @param {object} block
231+
* @param {object} component
232232
* @param {object} node
233233
* @param {object} parser
234234
* @returns {object|null}
235235
*/
236-
function matchSimpleBlock(block, node, parser) {
237-
const { associatedToken, types, value } = block
236+
function matchSimpleBlock(component, node, parser) {
238237
const { context, definition, input } = node
239-
if (types[0] === '<simple-block>' && associatedToken === definition.associatedToken) {
238+
if (isSimpleBlock(definition.associatedToken, component)) {
240239
const match = parser.parseCSSValue(
241-
new Stream(value, input.source),
240+
new Stream(component.value, input.source),
242241
definition.value,
243242
{ ...context, block: context })
244243
if (match instanceof SyntaxError) {
245244
return match
246245
}
247246
if (match) {
248-
return { ...block, value: match }
247+
return { ...component, value: match }
249248
}
250249
}
251250
return null
252251
}
253252

254253
/**
255-
* @param {object} fn
254+
* @param {object} component
256255
* @param {object} node
257256
* @param {object} parser
258257
* @returns {object|null}
259258
*/
260-
function matchFunction(fn, node, parser) {
261-
let { name, types, value } = fn
259+
function matchFunction(component, node, parser) {
260+
let { name, types, value } = component
262261
if (types[0] !== '<function>') {
263262
return null
264263
}
@@ -269,19 +268,19 @@ function matchFunction(fn, node, parser) {
269268
if (name === null || name instanceof SyntaxError) {
270269
return name
271270
}
272-
fn = { ...fn, name: name.value }
271+
component = { ...component, name: name.value }
273272
}
274273
if (definition.value) {
275274
value = new Stream(value, input.source)
276275
value = parser.parseCSSValue(value, definition.value, ctx)
277276
if (value === null || value instanceof SyntaxError) {
278277
return value
279278
}
280-
fn = { ...fn, value }
279+
component = { ...component, value }
281280
} else if (0 < value.length) {
282281
return null
283282
}
284-
return fn
283+
return component
285284
}
286285

287286
/**

0 commit comments

Comments
 (0)