Extend generic property descriptor handling#306
Conversation
domenic
left a comment
There was a problem hiding this comment.
LGTM with nits. We should merge soon because it is a nice progression on the test results.
However let me ask about your general strategy for the generic descriptor.
From my understanding of the CSS specs, the generic algorithm is:
- Each property lists a grammar. For example,
outline-offsethas a syntax of<length> - So, whenever parsing
outline-offset, per https://drafts.csswg.org/cssom/#parse-a-css-value , we first parse it generically, and then we check if the result matches<length>. If it does not, then we throw away the result. - If the result matches, then we append per https://drafts.csswg.org/cssom/#set-a-css-declaration, and later serialize per https://drafts.csswg.org/cssom/#serialize-a-css-value .
If we were to implement this in jsdom, I guess we would have the generic property descriptor use some totally generic parsing algorithm (maybe like cssTree.parse()?) and then we would check against the grammar from propertyDefinitions.js.
How does that compare to the strategy you are working on? Your strategy involves passing information about "dimension types" and "function types" per property, instead of passing the grammar. And you use them to decide on what parsing to do after the generic cssTree.parse(). I would like to learn more about this strategy and how it compares to the spec.
lib/utils/propertyDescriptors.js
Outdated
| * @param {object} opts - The options object. | ||
| * @param {boolean} opts.caseSensitive - True if value is case-sensitive, false otherwise. | ||
| * @param {object} [opts.dimensionTypes] - The dimension types object. | ||
| * @param {object} [opts.functionTypes] - The function types object. |
There was a problem hiding this comment.
Can you describe these in more detail? When will they be present, and what will they contain?
There was a problem hiding this comment.
opts.dimensionTypes is an object that contains CSS data type and optionally max / min ranges.
For example, <length> is defined as:
{
type: "length"
}
And <length [0, ∞]> is defined as:
{
type: "length",
max: null,
min: 0
}
type is used as a key to determine how to serialize the value.
If type is "length", it is passed to parseLength(), and if type is "percentage", it is passed to parsePercentage().
The same applies to opts.functionTypes, but currently only color and image have serialization methods, so type only has those two keys.
Note that parseLength() and parsePercentage() would be more accurately named serializeLength() and serializePercentage().
If requested, I will also rename those in this PR.
Renamed them.
There was a problem hiding this comment.
Nice, that helps!
Is the following accurate?
* @param {object} [opts.dimensionTypes={}] - A map containing information about the dimension types used by this property, if any. Keys are a type of dimension, which determines which serializer to use, and values are the information used by the serializer to serialize a parsed value.
* @param {object} [opts.functionTypes={}] - A map containing information about the function types used by this property, if any. Keys are a type of function, which determines which function to use; values are ignored.
There was a problem hiding this comment.
How about
A map containing ... -> A key-value pair containing ...
Co-authored-by: Domenic Denicola <d@domenic.me>
Co-authored-by: Domenic Denicola <d@domenic.me>
Co-authored-by: Domenic Denicola <d@domenic.me>
Co-authored-by: Domenic Denicola <d@domenic.me>
To be honest,
The changes in this PR simply serializes anything that can be serialized, of the things that were previously set as-is. |
|
I think I understand now. I couldn't find where the "match syntax" step was, but I see that it's in I'm happy to merge this after we get a nice descriptive comment for |
|
When using Claude Code to understand this PR better, it had a suggestion for us:
I don't know if this is helpful, and it can be done in a followup anyway. But I wanted to relay it. |
This is true, but there are actually more variations. |
Related #305
web-platform-tests/tests/css/cssom/serialize-values.html: