From b376ab4e8196ee56e738e5532e3a021de3751dfd Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Mon, 1 Dec 2025 14:27:50 +0000 Subject: [PATCH] LibWeb/CSS: Serialize Supports::Declaration as original representation Fixes some WPT tests that expected `supports(foo:bar)` to serialize as `supports(foo:bar)`, instead of `supports(foo: bar)` with a space between. Reading the original_full_text directly also lets us delete Declaration::to_string(), which was only used here. --- Libraries/LibWeb/CSS/Parser/Parser.cpp | 4 ++-- Libraries/LibWeb/CSS/Parser/Types.cpp | 17 ----------------- Libraries/LibWeb/CSS/Parser/Types.h | 3 --- .../parsing/supports-import-parsing.txt | 12 ++++++------ 4 files changed, 8 insertions(+), 28 deletions(-) diff --git a/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Libraries/LibWeb/CSS/Parser/Parser.cpp index 63d25a2f271..f975e5aa839 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -398,11 +398,11 @@ OwnPtr Parser::parse_supports_declaration(TokenStream part. auto transaction = tokens.begin_transaction(); tokens.discard_whitespace(); - if (auto declaration = consume_a_declaration(tokens); declaration.has_value()) { + if (auto declaration = consume_a_declaration(tokens, Nested::No, SaveOriginalText::Yes); declaration.has_value()) { tokens.discard_whitespace(); if (!tokens.has_next_token()) { transaction.commit(); - return Supports::Declaration::create(declaration->to_string(), convert_to_style_property(*declaration).has_value()); + return Supports::Declaration::create(declaration->original_full_text.release_value(), convert_to_style_property(*declaration).has_value()); } } return {}; diff --git a/Libraries/LibWeb/CSS/Parser/Types.cpp b/Libraries/LibWeb/CSS/Parser/Types.cpp index 27bc5313832..c652b7d21fa 100644 --- a/Libraries/LibWeb/CSS/Parser/Types.cpp +++ b/Libraries/LibWeb/CSS/Parser/Types.cpp @@ -12,23 +12,6 @@ namespace Web::CSS::Parser { -String Declaration::to_string() const -{ - if (original_value_text.has_value()) - return original_value_text.value(); - - StringBuilder builder; - - serialize_an_identifier(builder, name); - builder.append(": "sv); - builder.join(' ', value); - - if (important == Important::Yes) - builder.append(" !important"sv); - - return MUST(builder.to_string()); -} - String SimpleBlock::to_string() const { StringBuilder builder; diff --git a/Libraries/LibWeb/CSS/Parser/Types.h b/Libraries/LibWeb/CSS/Parser/Types.h index 3629edd9c38..ef9aa3796d4 100644 --- a/Libraries/LibWeb/CSS/Parser/Types.h +++ b/Libraries/LibWeb/CSS/Parser/Types.h @@ -58,9 +58,6 @@ struct Declaration { Important important = Important::No; Optional original_value_text = {}; Optional original_full_text = {}; - - // FIXME: Only needed by our janky @supports re-serialization-re-parse code. - String to_string() const; }; struct SubstitutionFunctionsPresence { diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/parsing/supports-import-parsing.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/parsing/supports-import-parsing.txt index 046ae1cdb5f..5abac3dba19 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/parsing/supports-import-parsing.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/parsing/supports-import-parsing.txt @@ -2,12 +2,12 @@ Harness status: OK Found 22 tests -16 Pass -6 Fail +20 Pass +2 Fail Pass @import url("nonexist.css") supports(); should be an invalid import rule due to an invalid supports() declaration Pass @import url("nonexist.css") supports(foo: bar); should be an invalid import rule due to an invalid supports() declaration -Fail @import url("nonexist.css") supports(display:block); should be a valid supports() import rule -Fail @import url("nonexist.css") supports((display:flex)); should be a valid supports() import rule +Pass @import url("nonexist.css") supports(display:block); should be a valid supports() import rule +Pass @import url("nonexist.css") supports((display:flex)); should be a valid supports() import rule Pass @import url("nonexist.css") supports(not (display: flex)); should be a valid supports() import rule Pass @import url("nonexist.css") supports((display: flex) and (display: block)); should be a valid supports() import rule Pass @import url("nonexist.css") supports((display: flex) or (display: block)); should be a valid supports() import rule @@ -23,6 +23,6 @@ Pass @import url("nonexist.css") supports(selector(p > a)); should be a valid su Pass @import url("nonexist.css") supports(selector(p + a)); should be a valid supports() import rule Pass @import url("nonexist.css") supports(font-tech(color-colrv1)); should be a valid supports() import rule Pass @import url("nonexist.css") supports(font-format(opentype)); should be a valid supports() import rule -Fail @import url(nonexist.css) supports(display:block); should be a valid supports() import rule -Fail @import "nonexist.css" supports(display:block); should be a valid supports() import rule +Pass @import url(nonexist.css) supports(display:block); should be a valid supports() import rule +Pass @import "nonexist.css" supports(display:block); should be a valid supports() import rule Pass @import url("nonexist.css") supports; should still be a valid import rule with an invalid supports() declaration \ No newline at end of file