@@ -1042,7 +1042,7 @@ void Parser::consume_a_function_and_do_nothing(TokenStream<Token>& input)
10421042
10431043// https://drafts.csswg.org/css-syntax/#consume-declaration
10441044template <typename T>
1045- Optional<Declaration> Parser::consume_a_declaration (TokenStream<T>& input, Nested nested)
1045+ Optional<Declaration> Parser::consume_a_declaration (TokenStream<T>& input, Nested nested, SaveOriginalText save_full_text )
10461046{
10471047 // To consume a declaration from a token stream input, given an optional bool nested (default false):
10481048
@@ -1054,6 +1054,7 @@ Optional<Declaration> Parser::consume_a_declaration(TokenStream<T>& input, Neste
10541054 .name {},
10551055 .value {},
10561056 };
1057+ auto start_token_index = input.current_index ();
10571058
10581059 // 1. If the next token is an <ident-token>, consume a token from input and set decl’s name to the token’s value.
10591060 if (input.next_token ().is (Token::Type::Ident)) {
@@ -1177,8 +1178,17 @@ Optional<Declaration> Parser::consume_a_declaration(TokenStream<T>& input, Neste
11771178 }
11781179
11791180 // 9. If decl is valid in the current context, return it; otherwise return nothing.
1180- if (is_valid_in_the_current_context (declaration))
1181+ if (is_valid_in_the_current_context (declaration)) {
1182+ // AD-HOC: Assemble source tokens.
1183+ if (save_full_text == SaveOriginalText::Yes) {
1184+ StringBuilder original_full_text;
1185+ for (auto & token : input.tokens_since (start_token_index))
1186+ original_full_text.append (token.to_string ());
1187+
1188+ declaration.original_full_text = original_full_text.to_string_without_validation ();
1189+ }
11811190 return declaration;
1191+ }
11821192 return {};
11831193}
11841194
@@ -1929,8 +1939,8 @@ template Vector<RuleOrListOfDeclarations> Parser::consume_a_blocks_contents(Toke
19291939template Vector<ComponentValue> Parser::consume_a_list_of_component_values (TokenStream<ComponentValue>&, Optional<Token::Type>, Nested);
19301940template Vector<ComponentValue> Parser::consume_a_list_of_component_values (TokenStream<Token>&, Optional<Token::Type>, Nested);
19311941
1932- template Optional<Declaration> Parser::consume_a_declaration (TokenStream<Token>&, Nested);
1933- template Optional<Declaration> Parser::consume_a_declaration (TokenStream<ComponentValue>&, Nested);
1942+ template Optional<Declaration> Parser::consume_a_declaration (TokenStream<Token>&, Nested, SaveOriginalText );
1943+ template Optional<Declaration> Parser::consume_a_declaration (TokenStream<ComponentValue>&, Nested, SaveOriginalText );
19341944
19351945template void Parser::consume_the_remnants_of_a_bad_declaration (TokenStream<Token>&, Nested);
19361946template void Parser::consume_the_remnants_of_a_bad_declaration (TokenStream<ComponentValue>&, Nested);
0 commit comments