Skip to content

Commit

Permalink
Do not define CSSPropertyRule.initialValue as nullable
Browse files Browse the repository at this point in the history
It should return empty string instead of null, when the descriptor is
omitted.

w3c/css-houdini-drafts#1115
  • Loading branch information
cdoublev committed Nov 4, 2024
1 parent f9c236c commit 4e5837a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions __tests__/stylesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ describe('CSS grammar', () => {
expect(rule.cssRules).toBeUndefined()
expect(rule.style).toBeUndefined()
expect(rule.color).toBeUndefined()
expect(rule.initialValue).toBeNull()
expect(rule.initialValue).toBe('')
expect(rule.inherits).toBe('true')
expect(rule.syntax).toBe('"*"')
})
Expand Down Expand Up @@ -2118,7 +2118,7 @@ describe('CSSPropertyRule', () => {
expect(rule.name).toBe('--custom')
expect(rule.syntax).toBe('"*"')
expect(rule.inherits).toBe('true')
expect(rule.initialValue).toBeNull()
expect(rule.initialValue).toBe('')
})
})
describe('CSSScopeRule', () => {
Expand Down
24 changes: 18 additions & 6 deletions lib/cssom/CSSPropertyRule-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ class CSSPropertyRuleImpl extends CSSRuleImpl {
super(globalObject, args, privateData)
const { prelude, value } = privateData
this.name = serializeCSSComponentValue(prelude)
value.declarations.forEach(({ name, value }) =>
this[cssPropertyToIDLAttribute(name)] = serializeCSSValue({ name, value }))
this.initialValue ??= null
value.declarations.forEach(({ name, value }) => {
let attribute = cssPropertyToIDLAttribute(name)
if (attribute === 'initialValue') {
attribute = `_${attribute}`
}
this[attribute] = serializeCSSValue({ name, value })
})
}

/**
Expand All @@ -28,14 +32,22 @@ class CSSPropertyRuleImpl extends CSSRuleImpl {
* @see {@link https://drafts.css-houdini.org/css-properties-values-api-1/#serialize-a-csspropertyrule}
*/
get cssText() {
const { inherits, initialValue, name, syntax } = this
const { inherits, _initialValue, name, syntax } = this
let string = `@property ${name} { syntax: ${syntax}; inherits: ${inherits}; `
if (initialValue !== null) {
string += `initial-value: ${initialValue}; `
if (_initialValue !== undefined) {
string += `initial-value: ${_initialValue}; `
}
string += '}'
return string
}

/**
* @see {@link https://drafts.css-houdini.org/css-properties-values-api-1/#dom-csspropertyrule-initialvalue}
* @see {@link https://github.com/w3c/css-houdini-drafts/issues/1115}
*/
get initialValue() {
return this._initialValue ?? ''
}
}

module.exports = {
Expand Down
3 changes: 2 additions & 1 deletion lib/cssom/CSSPropertyRule.webidl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

// https://drafts.css-houdini.org/css-properties-values-api-1/#csspropertyrule
// https://github.com/w3c/css-houdini-drafts/issues/1115
[Exposed=Window]
interface CSSPropertyRule : CSSRule {
readonly attribute boolean inherits;
readonly attribute CSSOMString? initialValue;
readonly attribute CSSOMString initialValue;
readonly attribute CSSOMString name;
readonly attribute CSSOMString syntax;
};

0 comments on commit 4e5837a

Please sign in to comment.