diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 2daa582f3b1..873809c8598 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -452,26 +452,7 @@ } pub fn parse_declared<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { - input.look_for_var_functions(); - let start = input.position(); - let specified = parse_specified(context, input); - if specified.is_err() { - while let Ok(_) = input.next() {} // Look for var() after the error. - } - let var = input.seen_var_functions(); - if specified.is_err() && var { - input.reset(start); - let (first_token_type, css) = - ::custom_properties::parse_non_custom_with_var(input)?; - return Ok(PropertyDeclaration::WithVariables(LonghandId::${property.camel_case}, - Arc::new(UnparsedValue { - css: css.into_owned(), - first_token_type: first_token_type, - url_data: context.url_data.clone(), - from_shorthand: None, - }))) - } - specified.map(|s| PropertyDeclaration::${property.camel_case}(s)) + parse_specified(context, input).map(PropertyDeclaration::${property.camel_case}) } % endif } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 6cd81d663b7..a2b272e4b6f 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1521,32 +1521,44 @@ impl PropertyDeclaration { Ok(()) } PropertyId::Longhand(id) => { - if let Ok(keyword) = input.try(|i| CSSWideKeyword::parse(context, i)) { - declarations.push(PropertyDeclaration::CSSWideKeyword(id, keyword)); - Ok(()) - } else { - match id { - % for property in data.longhands: - LonghandId::${property.camel_case} => { - % if not property.derived_from: - match longhands::${property.ident}::parse_declared(context, input) { - Ok(value) => { - declarations.push(value); - Ok(()) - }, - Err(_) => { - Err(PropertyDeclarationParseError::InvalidValue( - "${property.ident}".into() - )) - } - } - % else: - Err(PropertyDeclarationParseError::UnknownProperty) - % endif - } - % endfor - } - } + input.try(|i| CSSWideKeyword::parse(context, i)).map(|keyword| { + PropertyDeclaration::CSSWideKeyword(id, keyword) + }).or_else(|_| { + input.look_for_var_functions(); + let start = input.position(); + input.parse_entirely(|input| { + match id { + % for property in data.longhands: + LonghandId::${property.camel_case} => { + % if not property.derived_from: + longhands::${property.ident}::parse_declared(context, input) + % else: + Err(PropertyDeclarationParseError::UnknownProperty) + % endif + } + % endfor + } + }).or_else(|_| { + while let Ok(_) = input.next() {} // Look for var() after the error. + if input.seen_var_functions() { + input.reset(start); + let (first_token_type, css) = + ::custom_properties::parse_non_custom_with_var(input).map_err(|_| { + PropertyDeclarationParseError::InvalidValue(id.name().into()) + })?; + Ok(PropertyDeclaration::WithVariables(id, Arc::new(UnparsedValue { + css: css.into_owned(), + first_token_type: first_token_type, + url_data: context.url_data.clone(), + from_shorthand: None, + }))) + } else { + Err(PropertyDeclarationParseError::InvalidValue(id.name().into())) + } + }) + }).map(|declaration| { + declarations.push(declaration) + }) } PropertyId::Shorthand(id) => { if let Ok(keyword) = input.try(|i| CSSWideKeyword::parse(context, i)) {