mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Detect var() in shorthand declarations.
This commit is contained in:
parent
6ed5b561df
commit
40e6cc118e
4 changed files with 13 additions and 127 deletions
|
@ -270,6 +270,8 @@ fn parse_var_function<'i, 't>(input: &mut Parser<'i, 't>,
|
||||||
let name = try!(input.expect_ident());
|
let name = try!(input.expect_ident());
|
||||||
let name = try!(parse_name(&name));
|
let name = try!(parse_name(&name));
|
||||||
if input.try(|input| input.expect_comma()).is_ok() {
|
if input.try(|input| input.expect_comma()).is_ok() {
|
||||||
|
// Exclude `!` and `;` at the top level
|
||||||
|
// https://drafts.csswg.org/css-syntax/#typedef-declaration-value
|
||||||
try!(input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| {
|
try!(input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| {
|
||||||
// At least one non-comment token.
|
// At least one non-comment token.
|
||||||
try!(input.next_including_whitespace());
|
try!(input.next_including_whitespace());
|
||||||
|
|
|
@ -14,7 +14,7 @@ use std::mem;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use cssparser::{Parser, Color, RGBA, AtRuleParser, DeclarationParser,
|
use cssparser::{Parser, Color, RGBA, AtRuleParser, DeclarationParser, Delimiter,
|
||||||
DeclarationListParser, parse_important, ToCss, TokenSerializationType};
|
DeclarationListParser, parse_important, ToCss, TokenSerializationType};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use util::logical_geometry::{LogicalMargin, PhysicalSide, WritingMode};
|
use util::logical_geometry::{LogicalMargin, PhysicalSide, WritingMode};
|
||||||
|
@ -4846,7 +4846,10 @@ pub mod shorthands {
|
||||||
-> Result<(), ()> {
|
-> Result<(), ()> {
|
||||||
input.look_for_var_functions();
|
input.look_for_var_functions();
|
||||||
let start = input.position();
|
let start = input.position();
|
||||||
let value = parse_value(context, input);
|
let value = input.parse_entirely(|input| parse_value(context, input));
|
||||||
|
if value.is_err() {
|
||||||
|
while let Ok(_) = input.next() {} // Look for var() after the error.
|
||||||
|
}
|
||||||
let var = input.seen_var_functions();
|
let var = input.seen_var_functions();
|
||||||
if let Ok(value) = value {
|
if let Ok(value) = value {
|
||||||
% for sub_property in shorthand.sub_properties:
|
% for sub_property in shorthand.sub_properties:
|
||||||
|
@ -5663,10 +5666,12 @@ impl<'a, 'b> DeclarationParser for PropertyDeclarationParser<'a, 'b> {
|
||||||
|
|
||||||
fn parse_value(&self, name: &str, input: &mut Parser) -> Result<(Vec<PropertyDeclaration>, bool), ()> {
|
fn parse_value(&self, name: &str, input: &mut Parser) -> Result<(Vec<PropertyDeclaration>, bool), ()> {
|
||||||
let mut results = vec![];
|
let mut results = vec![];
|
||||||
match PropertyDeclaration::parse(name, self.context, input, &mut results) {
|
try!(input.parse_until_before(Delimiter::Bang, |input| {
|
||||||
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration => {}
|
match PropertyDeclaration::parse(name, self.context, input, &mut results) {
|
||||||
_ => return Err(())
|
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration => Ok(()),
|
||||||
}
|
_ => Err(())
|
||||||
|
}
|
||||||
|
}));
|
||||||
let important = input.try(parse_important).is_ok();
|
let important = input.try(parse_important).is_ok();
|
||||||
Ok((results, important))
|
Ok((results, important))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,116 +0,0 @@
|
||||||
[test_variable_serialization_specified.html]
|
|
||||||
type: testharness
|
|
||||||
[`var(--a)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) ` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var( --a ) ` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a, )` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a,/**/a)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`1px var(--a)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) 1px` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`something 3px url(whereever) calc(var(--a) + 1px)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a)var(--b)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a, var(--b, var(--c, black)))` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) <!--` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`--> var(--a)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`{ [ var(--a) \] }` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`[;\] var(--a)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a,(;))` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`VAR(--a)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--0)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--\\30)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--\\d800)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--\\ffffff)` is unchanged by specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a` becomes `var(--a)` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a , ` becomes `var(--a , )` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a, ` becomes `var(--a, )` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a, var(--b` becomes `var(--a, var(--b))` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a /* unclosed comment` becomes `var(--a /* unclosed comment*/)` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a /* unclosed comment *` becomes `var(--a /* unclosed comment */)` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`[{(((var(--a` becomes `[{(((var(--a))))}\]` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a, "unclosed string` becomes `var(--a, "unclosed string")` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a, 'unclosed string` becomes `var(--a, 'unclosed string')` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) "unclosed string\\` becomes `var(--a) "unclosed string"` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) 'unclosed string\\` becomes `var(--a) 'unclosed string'` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) \\` becomes `var(--a) \\<5C>` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) url(unclosedurl` becomes `var(--a) url(unclosedurl)` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) url('unclosedurl` becomes `var(--a) url('unclosedurl')` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) url("unclosedurl` becomes `var(--a) url("unclosedurl")` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) url(unclosedurl\\` becomes `var(--a) url(unclosedurl\\<5C>)` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) url('unclosedurl\\` becomes `var(--a) url('unclosedurl')` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[`var(--a) url("unclosedurl\\` becomes `var(--a) url("unclosedurl")` in specified value serialization]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -104,11 +104,6 @@ function test_specified_value_serialization(value, expected) {
|
||||||
div1.style.removeProperty("margin");
|
div1.style.removeProperty("margin");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
function test(f) { f() }
|
|
||||||
function assert_equals(a, b, m) { if (a == b) { console.log("`"+a+"`", "`"+b+"`", m) } }
|
|
||||||
*/
|
|
||||||
|
|
||||||
values_with_unchanged_specified_value_serialization.forEach(function(value) {
|
values_with_unchanged_specified_value_serialization.forEach(function(value) {
|
||||||
test(function() { test_specified_value_serialization(value, value) },
|
test(function() { test_specified_value_serialization(value, value) },
|
||||||
"`" + value + "` is unchanged by specified value serialization");
|
"`" + value + "` is unchanged by specified value serialization");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue