Skip to content

Commit 5227c28

Browse files
committed
Minor things
1 parent 8379129 commit 5227c28

14 files changed

Lines changed: 37 additions & 39 deletions

doc/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,23 @@ Before the introduction of these at-rules and nested style and group rules, it c
116116
Instead of modifying this behavior to interpret rules, the CSSWG decided to represent lists of declarations appearing after a nested rule, with a `CSSStyleDeclaration` contained in `CSSNestedDeclarations`, which is a "transparent" rule that only contains this list of declarations.
117117

118118
```css
119-
/* CSSStyleRule { */
119+
/* CSSStyleRule { */
120120
style {
121-
/* CSSStyleRule.style { */
121+
/* .style: { */
122122
foo: 1;
123123
bar: 1;
124124
/* } */
125-
/* CSSStyleRule.cssRules { */
125+
/* .cssRules: [ */
126126
@media all {}
127127
/* CSSNestedDeclarations { */
128-
/* CSSNestedDeclarations.style { */
128+
/* .style { */
129129
baz: 1;
130130
qux: 1;
131-
/* } */
132-
/* } */
133-
/* } */
131+
/* }, */
132+
/* }, */
133+
/* ], */
134134
}
135+
/* } */
135136
```
136137

137138
`CSSStyleDeclaration` is now extended by subclasses defined with a restricted set of property and descriptor attributes: `CSSStyleProperties`, `CSSFontFaceDescriptors`, `CSSPageDescriptors`, etc. Their names also helped to remove confusion about the context in which these declarations are accepted.
@@ -174,7 +175,7 @@ To overcome these challenges, this library defines the following requirements fo
174175

175176
A CSS parser must validate rules and declarations *in the context*, which is not defined anywhere nor passed as an argument.
176177

177-
When grouping at-rules like `@media` and `@supports` are nested in a style rule, the grammar of their block value changes. When using `CSSRule.insertRule()`, the node representing `CSSRule` does not exist. So the context must be initialized with its CSSOM representation.
178+
When grouping at-rules like `@media` and `@supports` are nested in a style rule, the grammar of their block value changes. When using `CSSGroupingRule.insertRule()`, the node representing `CSSGroupingRule` does not exist. So the context must be initialized with its CSSOM representation.
178179

179180
The context representation must allow accessing the parent rule definition, which must tell:
180181

lib/cssom/CSSFontFeatureValuesMap-impl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default class CSSFontFeatureValuesMapImpl {
1717
* @param {object} privateData
1818
*/
1919
constructor(globalObject, args, { name, node, parentRule, parentStyleSheet }) {
20+
this._globalObject = globalObject
2021
this.parentRule = parentRule
2122
this.parentStyleSheet = parentStyleSheet
2223
if (node) {

lib/cssom/CSSRuleList-impl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default class CSSRuleListImpl {
1212
* @param {object} privateData
1313
*/
1414
constructor(globalObject, args, { rules }) {
15+
this._globalObject = globalObject
1516
this._rules = rules
1617
}
1718

lib/cssom/MediaList-impl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function parseMediaQuery(input) {
3131
export default class MediaListImpl {
3232

3333
constructor(globalObject, args, { list = createList([], ',', ['<media-query-list>']) }) {
34+
this._globalObject = globalObject
3435
this._list = list
3536
}
3637

lib/error.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,14 @@ export const UPDATE_LOCKED_STYLESHEET_ERROR = {
7878

7979
/**
8080
* @param {object} description
81-
* @param {boolean} [silent]
8281
* @returns {DOMException|Error}
8382
*/
84-
export function create({ context, message, name, type: Type = SyntaxError }, silent = !environment.test) {
83+
export function create({ message, name, type: Type = 'SyntaxError' }) {
8584
if (name) {
8685
return new DOMException(message, name)
8786
}
88-
if (!silent) {
89-
if (context) {
90-
console.log(`---\n\n${context}\n\n---`)
91-
}
92-
console.error(`${Type.name}: ${message}`)
87+
if (environment.test) {
88+
console.error(`${Type}: ${message}`)
9389
}
9490
return new Type(message)
9591
}

lib/match/media.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function matchFeature(feature, operator, value, window) {
177177
case 'update':
178178
return value === 'fast'
179179
default:
180-
throw Error('Unhandled feature')
180+
throw RangeError('Unexpected feature')
181181
}
182182
}
183183

lib/parse/definition.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { isDigit, isIdentifierCharacter, startsWithIdentifier } from '../utils/s
55
import Stream from './stream.js'
66
import arbitrary from './arbitrary.js'
77
import { canonicalize } from '../values/dimensions.js'
8-
import { create as error } from '../error.js'
98
import forgiving from '../values/forgiving.js'
109
import properties from '../properties/definitions.js'
1110
import types from '../values/definitions.js'
@@ -83,7 +82,7 @@ function consumeRange(chars, infinity = Infinity) {
8382
break
8483
}
8584
}
86-
throw error({ message: `Missing "${closingToken}"` })
85+
throw SyntaxError(`Missing "${closingToken}"`)
8786
}
8887

8988
/**

lib/parse/grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function match(node) {
212212
case 'token':
213213
return matchToken(node)
214214
default:
215-
throw RangeError('Unrecognized node definition type')
215+
throw RangeError('Unexpected node definition type')
216216
}
217217
}
218218

lib/parse/parser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function isInvalidNamespaceRule(list, rule) {
126126
}
127127

128128
/**
129-
* @param {CSSRuleListImpl[]} list
129+
* @param {CSSRuleImpl[]} list
130130
* @param {string} input
131131
* @param {number} index
132132
* @param {object} context
@@ -172,17 +172,17 @@ function insertRule(list, input, index, context, allowImport) {
172172
}
173173

174174
/**
175-
* @param {CSSRuleListImpl[]} list
175+
* @param {CSSRuleImpl[]} list
176176
* @param {number} index
177177
* @see {@link https://drafts.csswg.org/cssom-1/#remove-a-css-rule}
178178
*/
179179
function removeRule(list, index) {
180180
if (list.length <= index) {
181-
throw error(INVALID_RULE_INDEX_ERROR, true)
181+
throw error(INVALID_RULE_INDEX_ERROR)
182182
}
183183
const rule = list[index]
184184
if (isInvalidNamespaceRule(list, rule)) {
185-
throw error(INVALID_NAMESPACE_STATE_ERROR, true)
185+
throw error(INVALID_NAMESPACE_STATE_ERROR)
186186
}
187187
list.splice(index, 1)
188188
rule.parentStyleSheet = null

lib/parse/simplify.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { canonicalize, getCanonicalUnitFromType } from '../values/dimensions.js'
55
import { clamp, isNegativeZero, round, sign, toDegrees, toRadians } from '../utils/math.js'
66
import { getCalculationType, matchNumericType, types as numericTypes } from './types.js'
77
import { isCalculation, isCombinable, isList, isNumeric, isOmitted } from '../utils/value.js'
8-
import { create as error } from '../error.js'
98

109
/**
1110
* @param {object} node
@@ -290,7 +289,7 @@ export function simplifyCalculation(node, resolutionType) {
290289
}
291290
}).value, ['<calc-value'])
292291
default:
293-
throw error({ message: `Unrecognized math function "${name}"` })
292+
throw SyntaxError(`Unexpected math function "${name}"`)
294293
}
295294
} else if (name === 'min' || name === 'max') {
296295
if (value.length === 1) {

0 commit comments

Comments
 (0)