LibWeb/CSS: Stop inserting whitespace when serializing component values

Now that we don't remove whitespace when parsing, we don't need to
artificially insert it back in again when serializing. We do now need
to trim leading and trailing whitespace from UnresolvedStyleValues, as
this previously was done as part of the whitespace insertion.

This makes our serialization of UnresolvedStyleValues more correct and
gets us a few WPT passes for each property in the Typed OM tests.
This commit is contained in:
Sam Atkins 2025-10-30 16:14:54 +00:00
parent 427d7fabd7
commit 61a0898f5f
Notes: github-actions[bot] 2025-11-03 11:25:01 +00:00
13 changed files with 45 additions and 53 deletions

View file

@ -199,11 +199,9 @@ String serialize_a_css_declaration(StringView property, StringView value, Import
} }
// https://drafts.csswg.org/css-syntax/#serialization // https://drafts.csswg.org/css-syntax/#serialization
String serialize_a_series_of_component_values(ReadonlySpan<Parser::ComponentValue> component_values, InsertWhitespace insert_whitespace) String serialize_a_series_of_component_values(ReadonlySpan<Parser::ComponentValue> component_values)
{ {
// FIXME: There are special rules here where we should insert a comment between certain tokens. Do that! // FIXME: There are special rules here where we should insert a comment between certain tokens. Do that!
if (insert_whitespace == InsertWhitespace::Yes)
return MUST(Infra::strip_and_collapse_whitespace(MUST(String::join(' ', component_values))));
return MUST(String::join(""sv, component_values)); return MUST(String::join(""sv, component_values));
} }

View file

@ -47,11 +47,6 @@ void serialize_a_comma_separated_list(StringBuilder& builder, Vector<T> const& i
String serialize_a_css_declaration(StringView property, StringView value, Important = Important::No); String serialize_a_css_declaration(StringView property, StringView value, Important = Important::No);
enum class InsertWhitespace : u8 { String serialize_a_series_of_component_values(ReadonlySpan<Parser::ComponentValue>);
No,
Yes,
};
// FIXME: Remove InsertWhitespace param once style value parsing stops discarding whitespace tokens.
String serialize_a_series_of_component_values(ReadonlySpan<Parser::ComponentValue>, InsertWhitespace = InsertWhitespace::No);
} }

View file

@ -45,7 +45,7 @@ String UnresolvedStyleValue::to_string(SerializationMode) const
if (m_original_source_text.has_value()) if (m_original_source_text.has_value())
return *m_original_source_text; return *m_original_source_text;
return serialize_a_series_of_component_values(m_values, InsertWhitespace::Yes); return MUST(serialize_a_series_of_component_values(m_values).trim_ascii_whitespace());
} }
bool UnresolvedStyleValue::equals(StyleValue const& other) const bool UnresolvedStyleValue::equals(StyleValue const& other) const
@ -145,8 +145,7 @@ private:
void serialize_unserialized_values() void serialize_unserialized_values()
{ {
// FIXME: Stop inserting whitespace once we stop removing it during parsing. m_reified_values.append(serialize_a_series_of_component_values(m_unserialized_values));
m_reified_values.append(serialize_a_series_of_component_values(m_unserialized_values, InsertWhitespace::Yes));
m_unserialized_values.clear_with_capacity(); m_unserialized_values.clear_with_capacity();
} }

View file

@ -2,12 +2,12 @@ Harness status: OK
Found 16 tests Found 16 tests
7 Pass 10 Pass
9 Fail 6 Fail
Fail var() references work with registered properties Fail var() references work with registered properties
Fail References to registered var()-properties work in registered lists Pass References to registered var()-properties work in registered lists
Fail References to mixed registered and unregistered var()-properties work in registered lists Pass References to mixed registered and unregistered var()-properties work in registered lists
Fail Registered lists may be concatenated Pass Registered lists may be concatenated
Fail Font-relative units are absolutized when substituting Fail Font-relative units are absolutized when substituting
Fail Calc expressions are resolved when substituting Fail Calc expressions are resolved when substituting
Fail Lists with relative units are absolutized when substituting Fail Lists with relative units are absolutized when substituting

View file

@ -2,7 +2,8 @@ Harness status: OK
Found 16 tests Found 16 tests
16 Fail 3 Pass
13 Fail
Fail Normalizing "var(--A)" on a CSS property returns correct CSSUnparsedValue Fail Normalizing "var(--A)" on a CSS property returns correct CSSUnparsedValue
Fail Normalizing "var(--A)" on a shorthand returns correct CSSUnparsedValue Fail Normalizing "var(--A)" on a shorthand returns correct CSSUnparsedValue
Fail Normalizing "var(--A)" on a list-valued property returns correct CSSUnparsedValue Fail Normalizing "var(--A)" on a list-valued property returns correct CSSUnparsedValue
@ -15,7 +16,7 @@ Fail Normalizing "var(--A, var(--B))" on a CSS property returns correct CSSUnpar
Fail Normalizing "var(--A, var(--B))" on a shorthand returns correct CSSUnparsedValue Fail Normalizing "var(--A, var(--B))" on a shorthand returns correct CSSUnparsedValue
Fail Normalizing "var(--A, var(--B))" on a list-valued property returns correct CSSUnparsedValue Fail Normalizing "var(--A, var(--B))" on a list-valued property returns correct CSSUnparsedValue
Fail Normalizing "var(--A, var(--B))" on a custom property returns correct CSSUnparsedValue Fail Normalizing "var(--A, var(--B))" on a custom property returns correct CSSUnparsedValue
Fail Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a CSS property returns correct CSSUnparsedValue Pass Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a CSS property returns correct CSSUnparsedValue
Fail Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a shorthand returns correct CSSUnparsedValue Fail Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a shorthand returns correct CSSUnparsedValue
Fail Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a list-valued property returns correct CSSUnparsedValue Pass Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a list-valued property returns correct CSSUnparsedValue
Fail Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a custom property returns correct CSSUnparsedValue Pass Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a custom property returns correct CSSUnparsedValue

View file

@ -2,13 +2,13 @@ Harness status: OK
Found 37 tests Found 37 tests
35 Pass 36 Pass
2 Fail 1 Fail
Pass Can set 'color' to CSS-wide keywords: initial Pass Can set 'color' to CSS-wide keywords: initial
Pass Can set 'color' to CSS-wide keywords: inherit Pass Can set 'color' to CSS-wide keywords: inherit
Pass Can set 'color' to CSS-wide keywords: unset Pass Can set 'color' to CSS-wide keywords: unset
Pass Can set 'color' to CSS-wide keywords: revert Pass Can set 'color' to CSS-wide keywords: revert
Fail Can set 'color' to var() references: var(--A) Pass Can set 'color' to var() references: var(--A)
Fail Can set 'color' to the 'currentcolor' keyword: currentcolor Fail Can set 'color' to the 'currentcolor' keyword: currentcolor
Pass Setting 'color' to a length: 0px throws TypeError Pass Setting 'color' to a length: 0px throws TypeError
Pass Setting 'color' to a length: -3.14em throws TypeError Pass Setting 'color' to a length: -3.14em throws TypeError

View file

@ -2,13 +2,13 @@ Harness status: OK
Found 69 tests Found 69 tests
64 Pass 65 Pass
5 Fail 4 Fail
Pass Can set 'cursor' to CSS-wide keywords: initial Pass Can set 'cursor' to CSS-wide keywords: initial
Pass Can set 'cursor' to CSS-wide keywords: inherit Pass Can set 'cursor' to CSS-wide keywords: inherit
Pass Can set 'cursor' to CSS-wide keywords: unset Pass Can set 'cursor' to CSS-wide keywords: unset
Pass Can set 'cursor' to CSS-wide keywords: revert Pass Can set 'cursor' to CSS-wide keywords: revert
Fail Can set 'cursor' to var() references: var(--A) Pass Can set 'cursor' to var() references: var(--A)
Pass Can set 'cursor' to the 'auto' keyword: auto Pass Can set 'cursor' to the 'auto' keyword: auto
Pass Can set 'cursor' to the 'default' keyword: default Pass Can set 'cursor' to the 'default' keyword: default
Pass Can set 'cursor' to the 'none' keyword: none Pass Can set 'cursor' to the 'none' keyword: none

View file

@ -2,13 +2,12 @@ Harness status: OK
Found 56 tests Found 56 tests
55 Pass 56 Pass
1 Fail
Pass Can set 'display' to CSS-wide keywords: initial Pass Can set 'display' to CSS-wide keywords: initial
Pass Can set 'display' to CSS-wide keywords: inherit Pass Can set 'display' to CSS-wide keywords: inherit
Pass Can set 'display' to CSS-wide keywords: unset Pass Can set 'display' to CSS-wide keywords: unset
Pass Can set 'display' to CSS-wide keywords: revert Pass Can set 'display' to CSS-wide keywords: revert
Fail Can set 'display' to var() references: var(--A) Pass Can set 'display' to var() references: var(--A)
Pass Can set 'display' to the 'none' keyword: none Pass Can set 'display' to the 'none' keyword: none
Pass Can set 'display' to the 'block' keyword: block Pass Can set 'display' to the 'block' keyword: block
Pass Can set 'display' to the 'inline' keyword: inline Pass Can set 'display' to the 'inline' keyword: inline

View file

@ -2,13 +2,13 @@ Harness status: OK
Found 32 tests Found 32 tests
29 Pass 30 Pass
3 Fail 2 Fail
Pass Can set 'line-height' to CSS-wide keywords: initial Pass Can set 'line-height' to CSS-wide keywords: initial
Pass Can set 'line-height' to CSS-wide keywords: inherit Pass Can set 'line-height' to CSS-wide keywords: inherit
Pass Can set 'line-height' to CSS-wide keywords: unset Pass Can set 'line-height' to CSS-wide keywords: unset
Pass Can set 'line-height' to CSS-wide keywords: revert Pass Can set 'line-height' to CSS-wide keywords: revert
Fail Can set 'line-height' to var() references: var(--A) Pass Can set 'line-height' to var() references: var(--A)
Pass Can set 'line-height' to the 'normal' keyword: normal Pass Can set 'line-height' to the 'normal' keyword: normal
Pass Can set 'line-height' to a length: 0px Pass Can set 'line-height' to a length: 0px
Pass Can set 'line-height' to a length: -3.14em Pass Can set 'line-height' to a length: -3.14em

View file

@ -2,13 +2,13 @@ Harness status: OK
Found 161 tests Found 161 tests
152 Pass 156 Pass
9 Fail 5 Fail
Pass Can set 'margin-top' to CSS-wide keywords: initial Pass Can set 'margin-top' to CSS-wide keywords: initial
Pass Can set 'margin-top' to CSS-wide keywords: inherit Pass Can set 'margin-top' to CSS-wide keywords: inherit
Pass Can set 'margin-top' to CSS-wide keywords: unset Pass Can set 'margin-top' to CSS-wide keywords: unset
Pass Can set 'margin-top' to CSS-wide keywords: revert Pass Can set 'margin-top' to CSS-wide keywords: revert
Fail Can set 'margin-top' to var() references: var(--A) Pass Can set 'margin-top' to var() references: var(--A)
Pass Can set 'margin-top' to the 'auto' keyword: auto Pass Can set 'margin-top' to the 'auto' keyword: auto
Pass Can set 'margin-top' to a percent: 0% Pass Can set 'margin-top' to a percent: 0%
Pass Can set 'margin-top' to a percent: -3.14% Pass Can set 'margin-top' to a percent: -3.14%
@ -40,7 +40,7 @@ Pass Can set 'margin-left' to CSS-wide keywords: initial
Pass Can set 'margin-left' to CSS-wide keywords: inherit Pass Can set 'margin-left' to CSS-wide keywords: inherit
Pass Can set 'margin-left' to CSS-wide keywords: unset Pass Can set 'margin-left' to CSS-wide keywords: unset
Pass Can set 'margin-left' to CSS-wide keywords: revert Pass Can set 'margin-left' to CSS-wide keywords: revert
Fail Can set 'margin-left' to var() references: var(--A) Pass Can set 'margin-left' to var() references: var(--A)
Pass Can set 'margin-left' to the 'auto' keyword: auto Pass Can set 'margin-left' to the 'auto' keyword: auto
Pass Can set 'margin-left' to a percent: 0% Pass Can set 'margin-left' to a percent: 0%
Pass Can set 'margin-left' to a percent: -3.14% Pass Can set 'margin-left' to a percent: -3.14%
@ -72,7 +72,7 @@ Pass Can set 'margin-right' to CSS-wide keywords: initial
Pass Can set 'margin-right' to CSS-wide keywords: inherit Pass Can set 'margin-right' to CSS-wide keywords: inherit
Pass Can set 'margin-right' to CSS-wide keywords: unset Pass Can set 'margin-right' to CSS-wide keywords: unset
Pass Can set 'margin-right' to CSS-wide keywords: revert Pass Can set 'margin-right' to CSS-wide keywords: revert
Fail Can set 'margin-right' to var() references: var(--A) Pass Can set 'margin-right' to var() references: var(--A)
Pass Can set 'margin-right' to the 'auto' keyword: auto Pass Can set 'margin-right' to the 'auto' keyword: auto
Pass Can set 'margin-right' to a percent: 0% Pass Can set 'margin-right' to a percent: 0%
Pass Can set 'margin-right' to a percent: -3.14% Pass Can set 'margin-right' to a percent: -3.14%
@ -104,7 +104,7 @@ Pass Can set 'margin-bottom' to CSS-wide keywords: initial
Pass Can set 'margin-bottom' to CSS-wide keywords: inherit Pass Can set 'margin-bottom' to CSS-wide keywords: inherit
Pass Can set 'margin-bottom' to CSS-wide keywords: unset Pass Can set 'margin-bottom' to CSS-wide keywords: unset
Pass Can set 'margin-bottom' to CSS-wide keywords: revert Pass Can set 'margin-bottom' to CSS-wide keywords: revert
Fail Can set 'margin-bottom' to var() references: var(--A) Pass Can set 'margin-bottom' to var() references: var(--A)
Pass Can set 'margin-bottom' to the 'auto' keyword: auto Pass Can set 'margin-bottom' to the 'auto' keyword: auto
Pass Can set 'margin-bottom' to a percent: 0% Pass Can set 'margin-bottom' to a percent: 0%
Pass Can set 'margin-bottom' to a percent: -3.14% Pass Can set 'margin-bottom' to a percent: -3.14%

View file

@ -2,13 +2,13 @@ Harness status: OK
Found 124 tests Found 124 tests
116 Pass 120 Pass
8 Fail 4 Fail
Pass Can set 'padding-top' to CSS-wide keywords: initial Pass Can set 'padding-top' to CSS-wide keywords: initial
Pass Can set 'padding-top' to CSS-wide keywords: inherit Pass Can set 'padding-top' to CSS-wide keywords: inherit
Pass Can set 'padding-top' to CSS-wide keywords: unset Pass Can set 'padding-top' to CSS-wide keywords: unset
Pass Can set 'padding-top' to CSS-wide keywords: revert Pass Can set 'padding-top' to CSS-wide keywords: revert
Fail Can set 'padding-top' to var() references: var(--A) Pass Can set 'padding-top' to var() references: var(--A)
Pass Can set 'padding-top' to a percent: 0% Pass Can set 'padding-top' to a percent: 0%
Fail Can set 'padding-top' to a percent: -3.14% Fail Can set 'padding-top' to a percent: -3.14%
Pass Can set 'padding-top' to a percent: 3.14% Pass Can set 'padding-top' to a percent: 3.14%
@ -39,7 +39,7 @@ Pass Can set 'padding-left' to CSS-wide keywords: initial
Pass Can set 'padding-left' to CSS-wide keywords: inherit Pass Can set 'padding-left' to CSS-wide keywords: inherit
Pass Can set 'padding-left' to CSS-wide keywords: unset Pass Can set 'padding-left' to CSS-wide keywords: unset
Pass Can set 'padding-left' to CSS-wide keywords: revert Pass Can set 'padding-left' to CSS-wide keywords: revert
Fail Can set 'padding-left' to var() references: var(--A) Pass Can set 'padding-left' to var() references: var(--A)
Pass Can set 'padding-left' to a percent: 0% Pass Can set 'padding-left' to a percent: 0%
Fail Can set 'padding-left' to a percent: -3.14% Fail Can set 'padding-left' to a percent: -3.14%
Pass Can set 'padding-left' to a percent: 3.14% Pass Can set 'padding-left' to a percent: 3.14%
@ -70,7 +70,7 @@ Pass Can set 'padding-right' to CSS-wide keywords: initial
Pass Can set 'padding-right' to CSS-wide keywords: inherit Pass Can set 'padding-right' to CSS-wide keywords: inherit
Pass Can set 'padding-right' to CSS-wide keywords: unset Pass Can set 'padding-right' to CSS-wide keywords: unset
Pass Can set 'padding-right' to CSS-wide keywords: revert Pass Can set 'padding-right' to CSS-wide keywords: revert
Fail Can set 'padding-right' to var() references: var(--A) Pass Can set 'padding-right' to var() references: var(--A)
Pass Can set 'padding-right' to a percent: 0% Pass Can set 'padding-right' to a percent: 0%
Fail Can set 'padding-right' to a percent: -3.14% Fail Can set 'padding-right' to a percent: -3.14%
Pass Can set 'padding-right' to a percent: 3.14% Pass Can set 'padding-right' to a percent: 3.14%
@ -101,7 +101,7 @@ Pass Can set 'padding-bottom' to CSS-wide keywords: initial
Pass Can set 'padding-bottom' to CSS-wide keywords: inherit Pass Can set 'padding-bottom' to CSS-wide keywords: inherit
Pass Can set 'padding-bottom' to CSS-wide keywords: unset Pass Can set 'padding-bottom' to CSS-wide keywords: unset
Pass Can set 'padding-bottom' to CSS-wide keywords: revert Pass Can set 'padding-bottom' to CSS-wide keywords: revert
Fail Can set 'padding-bottom' to var() references: var(--A) Pass Can set 'padding-bottom' to var() references: var(--A)
Pass Can set 'padding-bottom' to a percent: 0% Pass Can set 'padding-bottom' to a percent: 0%
Fail Can set 'padding-bottom' to a percent: -3.14% Fail Can set 'padding-bottom' to a percent: -3.14%
Pass Can set 'padding-bottom' to a percent: 3.14% Pass Can set 'padding-bottom' to a percent: 3.14%

View file

@ -2,13 +2,13 @@ Harness status: OK
Found 33 tests Found 33 tests
31 Pass 32 Pass
2 Fail 1 Fail
Pass Can set 'transform' to CSS-wide keywords: initial Pass Can set 'transform' to CSS-wide keywords: initial
Pass Can set 'transform' to CSS-wide keywords: inherit Pass Can set 'transform' to CSS-wide keywords: inherit
Pass Can set 'transform' to CSS-wide keywords: unset Pass Can set 'transform' to CSS-wide keywords: unset
Pass Can set 'transform' to CSS-wide keywords: revert Pass Can set 'transform' to CSS-wide keywords: revert
Fail Can set 'transform' to var() references: var(--A) Pass Can set 'transform' to var() references: var(--A)
Pass Can set 'transform' to the 'none' keyword: none Pass Can set 'transform' to the 'none' keyword: none
Pass Can set 'transform' to a transform: translate(50%, 50%) Pass Can set 'transform' to a transform: translate(50%, 50%)
Pass Can set 'transform' to a transform: perspective(10em) Pass Can set 'transform' to a transform: perspective(10em)

View file

@ -2,13 +2,13 @@ Harness status: OK
Found 95 tests Found 95 tests
89 Pass 92 Pass
6 Fail 3 Fail
Pass Can set 'width' to CSS-wide keywords: initial Pass Can set 'width' to CSS-wide keywords: initial
Pass Can set 'width' to CSS-wide keywords: inherit Pass Can set 'width' to CSS-wide keywords: inherit
Pass Can set 'width' to CSS-wide keywords: unset Pass Can set 'width' to CSS-wide keywords: unset
Pass Can set 'width' to CSS-wide keywords: revert Pass Can set 'width' to CSS-wide keywords: revert
Fail Can set 'width' to var() references: var(--A) Pass Can set 'width' to var() references: var(--A)
Pass Can set 'width' to the 'auto' keyword: auto Pass Can set 'width' to the 'auto' keyword: auto
Pass Can set 'width' to a percent: 0% Pass Can set 'width' to a percent: 0%
Fail Can set 'width' to a percent: -3.14% Fail Can set 'width' to a percent: -3.14%
@ -40,7 +40,7 @@ Pass Can set 'min-width' to CSS-wide keywords: initial
Pass Can set 'min-width' to CSS-wide keywords: inherit Pass Can set 'min-width' to CSS-wide keywords: inherit
Pass Can set 'min-width' to CSS-wide keywords: unset Pass Can set 'min-width' to CSS-wide keywords: unset
Pass Can set 'min-width' to CSS-wide keywords: revert Pass Can set 'min-width' to CSS-wide keywords: revert
Fail Can set 'min-width' to var() references: var(--A) Pass Can set 'min-width' to var() references: var(--A)
Pass Can set 'min-width' to a percent: 0% Pass Can set 'min-width' to a percent: 0%
Fail Can set 'min-width' to a percent: -3.14% Fail Can set 'min-width' to a percent: -3.14%
Pass Can set 'min-width' to a percent: 3.14% Pass Can set 'min-width' to a percent: 3.14%
@ -71,7 +71,7 @@ Pass Can set 'max-width' to CSS-wide keywords: initial
Pass Can set 'max-width' to CSS-wide keywords: inherit Pass Can set 'max-width' to CSS-wide keywords: inherit
Pass Can set 'max-width' to CSS-wide keywords: unset Pass Can set 'max-width' to CSS-wide keywords: unset
Pass Can set 'max-width' to CSS-wide keywords: revert Pass Can set 'max-width' to CSS-wide keywords: revert
Fail Can set 'max-width' to var() references: var(--A) Pass Can set 'max-width' to var() references: var(--A)
Pass Can set 'max-width' to the 'none' keyword: none Pass Can set 'max-width' to the 'none' keyword: none
Pass Can set 'max-width' to a percent: 0% Pass Can set 'max-width' to a percent: 0%
Fail Can set 'max-width' to a percent: -3.14% Fail Can set 'max-width' to a percent: -3.14%