Skip to content

Commit 4e5837a

Browse files
committed
Do not define CSSPropertyRule.initialValue as nullable
It should return empty string instead of null, when the descriptor is omitted. w3c/css-houdini-drafts#1115
1 parent f9c236c commit 4e5837a

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

__tests__/stylesheet.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ describe('CSS grammar', () => {
10031003
expect(rule.cssRules).toBeUndefined()
10041004
expect(rule.style).toBeUndefined()
10051005
expect(rule.color).toBeUndefined()
1006-
expect(rule.initialValue).toBeNull()
1006+
expect(rule.initialValue).toBe('')
10071007
expect(rule.inherits).toBe('true')
10081008
expect(rule.syntax).toBe('"*"')
10091009
})
@@ -2118,7 +2118,7 @@ describe('CSSPropertyRule', () => {
21182118
expect(rule.name).toBe('--custom')
21192119
expect(rule.syntax).toBe('"*"')
21202120
expect(rule.inherits).toBe('true')
2121-
expect(rule.initialValue).toBeNull()
2121+
expect(rule.initialValue).toBe('')
21222122
})
21232123
})
21242124
describe('CSSScopeRule', () => {

lib/cssom/CSSPropertyRule-impl.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ class CSSPropertyRuleImpl extends CSSRuleImpl {
1717
super(globalObject, args, privateData)
1818
const { prelude, value } = privateData
1919
this.name = serializeCSSComponentValue(prelude)
20-
value.declarations.forEach(({ name, value }) =>
21-
this[cssPropertyToIDLAttribute(name)] = serializeCSSValue({ name, value }))
22-
this.initialValue ??= null
20+
value.declarations.forEach(({ name, value }) => {
21+
let attribute = cssPropertyToIDLAttribute(name)
22+
if (attribute === 'initialValue') {
23+
attribute = `_${attribute}`
24+
}
25+
this[attribute] = serializeCSSValue({ name, value })
26+
})
2327
}
2428

2529
/**
@@ -28,14 +32,22 @@ class CSSPropertyRuleImpl extends CSSRuleImpl {
2832
* @see {@link https://drafts.css-houdini.org/css-properties-values-api-1/#serialize-a-csspropertyrule}
2933
*/
3034
get cssText() {
31-
const { inherits, initialValue, name, syntax } = this
35+
const { inherits, _initialValue, name, syntax } = this
3236
let string = `@property ${name} { syntax: ${syntax}; inherits: ${inherits}; `
33-
if (initialValue !== null) {
34-
string += `initial-value: ${initialValue}; `
37+
if (_initialValue !== undefined) {
38+
string += `initial-value: ${_initialValue}; `
3539
}
3640
string += '}'
3741
return string
3842
}
43+
44+
/**
45+
* @see {@link https://drafts.css-houdini.org/css-properties-values-api-1/#dom-csspropertyrule-initialvalue}
46+
* @see {@link https://github.com/w3c/css-houdini-drafts/issues/1115}
47+
*/
48+
get initialValue() {
49+
return this._initialValue ?? ''
50+
}
3951
}
4052

4153
module.exports = {

lib/cssom/CSSPropertyRule.webidl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

22
// https://drafts.css-houdini.org/css-properties-values-api-1/#csspropertyrule
3+
// https://github.com/w3c/css-houdini-drafts/issues/1115
34
[Exposed=Window]
45
interface CSSPropertyRule : CSSRule {
56
readonly attribute boolean inherits;
6-
readonly attribute CSSOMString? initialValue;
7+
readonly attribute CSSOMString initialValue;
78
readonly attribute CSSOMString name;
89
readonly attribute CSSOMString syntax;
910
};

0 commit comments

Comments
 (0)