feat(css/ast): Improve types related to url tokens (#3444)

This commit is contained in:
Alexander Akait 2022-02-04 07:05:44 +03:00 committed by GitHub
parent 51f2202e9e
commit 49564d9b5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 884 additions and 79 deletions

View File

@ -62,6 +62,8 @@ pub enum Token {
Url {
name: JsWord,
raw_name: JsWord,
before: JsWord,
after: JsWord,
value: JsWord,
raw_value: JsWord,
},

View File

@ -156,6 +156,8 @@ pub enum UrlValue {
#[ast_node("UrlValueRaw")]
pub struct UrlValueRaw {
pub span: Span,
pub before: JsWord,
pub after: JsWord,
pub value: JsWord,
pub raw: JsWord,
}

View File

@ -1101,11 +1101,15 @@ where
Token::Url {
raw_name,
raw_value,
before,
after,
..
} => {
self.wr.write_raw(None, raw_name)?;
punct!(self, "(");
self.wr.write_raw(None, before)?;
self.wr.write_raw(None, raw_value)?;
self.wr.write_raw(None, after)?;
punct!(self, ")");
}
Token::BadUrl {
@ -1179,7 +1183,19 @@ where
#[emitter]
fn emit_url_value_raw(&mut self, n: &UrlValueRaw) -> Result {
self.wr.write_raw(Some(n.span), &n.raw)?;
if !self.config.minify {
self.wr.write_raw(Some(n.span), &n.before)?;
}
if self.config.minify {
self.wr.write_raw(Some(n.span), &n.value)?;
} else {
self.wr.write_raw(Some(n.span), &n.raw)?;
}
if !self.config.minify {
self.wr.write_raw(Some(n.span), &n.after)?;
}
}
#[emitter]

View File

@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf},
};
use swc_common::{FileName, Span};
use swc_css_ast::{Number, Str, Stylesheet};
use swc_css_ast::{Number, Str, Stylesheet, UrlValueRaw};
use swc_css_codegen::{
writer::basic::{BasicCssWriter, BasicCssWriterConfig},
CodeGenerator, CodegenConfig, Emit,
@ -101,6 +101,14 @@ impl VisitMut for NormalizeTest {
*n = Default::default()
}
fn visit_mut_url_value_raw(&mut self, n: &mut UrlValueRaw) {
n.visit_mut_children_with(self);
n.before = "".into();
n.after = "".into();
n.raw = "".into();
}
fn visit_mut_number(&mut self, n: &mut Number) {
n.visit_mut_children_with(self);

View File

@ -0,0 +1,8 @@
@unknown {}
@unknown url(image.png) {}
@unknown url( image.png ) {}
@unknown url("image.png") {}
@unknown url( image.png img ) {}
@unknown url( image.png"" img ) {}
@unknown url( image.png\ img ) {}
@unknown url( image.png\) ) {}

View File

@ -0,0 +1,8 @@
@unknown {}
@unknown url(image.png) {}
@unknown url( image.png ) {}
@unknown url("image.png") {}
@unknown url( image.png img ) {}
@unknown url( image.png"" img ) {}
@unknown url( image.png\ img ) {}
@unknown url( image.png\) ) {}

View File

@ -0,0 +1 @@
@unknown {}@unknown url(image.png) {}@unknown url( image.png ) {}@unknown url("image.png") {}@unknown url( image.png img ) {}@unknown url( image.png"" img ) {}@unknown url( image.png\ img ) {}@unknown url( image.png\) ) {}

View File

@ -1099,10 +1099,10 @@ transition: color .15s ease-in}
.debug * {outline: 1px solid gold}
.debug-white * {outline: 1px solid white}
.debug-black * {outline: 1px solid black}
.debug-grid {background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVR4AWPAC97/9x0eCsAEPgwAVLshdpENIxcAAAAASUVORK5CYII= ) repeat top left}
.debug-grid-16 {background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMklEQVR4AWOgCLz/b0epAa6UGuBOqQHOQHLUgFEDnAbcBZ4UGwDOkiCnkIhdgNgNxAYAiYlD+8sEuo8AAAAASUVORK5CYII= ) repeat top left}
.debug-grid-8-solid {background: white url(data:image/gif;base64,R0lGODdhCAAIAPEAAADw/wDx/////wAAACwAAAAACAAIAAACDZQvgaeb/lxbAIKA8y0AOw== ) repeat top left}
.debug-grid-16-solid {background: white url(data:image/gif;base64,R0lGODdhEAAQAPEAAADw/wDx/xXy/////ywAAAAAEAAQAAACIZyPKckYDQFsb6ZqD85jZ2+BkwiRFKehhqQCQgDHcgwEBQA7 ) repeat top left}
.debug-grid {background: transparent url( data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVR4AWPAC97/9x0eCsAEPgwAVLshdpENIxcAAAAASUVORK5CYII= ) repeat top left}
.debug-grid-16 {background: transparent url( data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMklEQVR4AWOgCLz/b0epAa6UGuBOqQHOQHLUgFEDnAbcBZ4UGwDOkiCnkIhdgNgNxAYAiYlD+8sEuo8AAAAASUVORK5CYII= ) repeat top left}
.debug-grid-8-solid {background: white url( data:image/gif;base64,R0lGODdhCAAIAPEAAADw/wDx/////wAAACwAAAAACAAIAAACDZQvgaeb/lxbAIKA8y0AOw== ) repeat top left}
.debug-grid-16-solid {background: white url( data:image/gif;base64,R0lGODdhEAAQAPEAAADw/wDx/xXy/////ywAAAAAEAAQAAACIZyPKckYDQFsb6ZqD85jZ2+BkwiRFKehhqQCQgDHcgwEBQA7 ) repeat top left}
@media screen and (min-width: 30em) {.aspect-ratio-ns {height: 0;
position: relative}
.aspect-ratio--16x9-ns {padding-bottom: 56.25%}

File diff suppressed because one or more lines are too long

View File

@ -23,6 +23,19 @@ div {
background: src("http://www.example.com/pinkish.gif");
background: SRC("http://www.example.com/pinkish.gif");
background: src(var(--foo));
background: url( https://example.com/image.png );
background: u\rl( https://example.com/image.png );
background: url(
https://example.com/image.png
);
background: url(
https://example.com/image.png
);
background: url(image.png\D799);
}
div {

View File

@ -16,5 +16,18 @@ background: url('');
--foo: "http://www.example.com/pinkish.gif";
background: src("http://www.example.com/pinkish.gif");
background: SRC("http://www.example.com/pinkish.gif");
background: src( var(--foo))}
background: src( var(--foo));
background: url( https://example.com/image.png );
background: u\rl( https://example.com/image.png );
background: url(
https://example.com/image.png
);
background: url(
https://example.com/image.png
);
background: url(image.png\D799)}
div {background: url(foo.img) red}

View File

@ -1 +1 @@
div{background:url(https://example.com/image.png);background:URL(https://example.com/image.png);background:\URL(https://example.com/image.png);background:url("https://example.com/image.png");background:url("https://example.com/image.png");background:URL("https://example.com/image.png");background:\URL("https://example.com/image.png");background:url(data:image/png;base64,iRxVB0);background:url(#IDofSVGpath);background:url("//aa.com/img.svg"prefetch);background:url("//aa.com/img.svg"foo bar baz func(test));background:url("http://example.com/image.svg"param(--color var(--primary-color)));background:url();background:url("");background:url("");--foo:"http://www.example.com/pinkish.gif";background:src("http://www.example.com/pinkish.gif");background:SRC("http://www.example.com/pinkish.gif");background:src(var(--foo))}div{background:url(foo.img)red}
div{background:url(https://example.com/image.png);background:URL(https://example.com/image.png);background:\URL(https://example.com/image.png);background:url("https://example.com/image.png");background:url("https://example.com/image.png");background:URL("https://example.com/image.png");background:\URL("https://example.com/image.png");background:url(data:image/png;base64,iRxVB0);background:url(#IDofSVGpath);background:url("//aa.com/img.svg"prefetch);background:url("//aa.com/img.svg"foo bar baz func(test));background:url("http://example.com/image.svg"param(--color var(--primary-color)));background:url();background:url("");background:url("");--foo:"http://www.example.com/pinkish.gif";background:src("http://www.example.com/pinkish.gif");background:SRC("http://www.example.com/pinkish.gif");background:src(var(--foo));background:url(https://example.com/image.png);background:u\rl(https://example.com/image.png);background:url(https://example.com/image.png);background:url(https://example.com/image.png);background:url(image.png힙)}div{background:url(foo.img)red}

View File

@ -182,7 +182,7 @@ where
}
// Consume a name, and set the <hash-token>s value to the returned string.
let name = self.read_name()?;
let ident_sequence = self.read_ident_sequence()?;
match hash_token {
Token::Hash {
@ -190,8 +190,8 @@ where
ref mut raw,
..
} => {
*value = name.0;
*raw = name.1;
*value = ident_sequence.0;
*raw = ident_sequence.1;
}
_ => {
unreachable!();
@ -309,11 +309,11 @@ where
// create an <at-keyword-token> with its value set to the returned value, and
// return it.
if self.would_start_ident(first, second, third)? {
let name = self.read_name()?;
let ident_sequence = self.read_ident_sequence()?;
return Ok(Token::AtKeyword {
value: name.0,
raw: name.1,
value: ident_sequence.0,
raw: ident_sequence.1,
});
}
@ -454,7 +454,7 @@ where
};
// Consume a name. Set the <dimension-token>s unit to the returned value.
let name = self.read_name()?;
let ident_sequence = self.read_ident_sequence()?;
match token {
Token::Dimension {
@ -462,8 +462,8 @@ where
ref mut raw_unit,
..
} => {
*unit = name.0;
*raw_unit = name.1;
*unit = ident_sequence.0;
*raw_unit = ident_sequence.1;
}
_ => {
unreachable!();
@ -498,20 +498,23 @@ where
// <bad-url-token>.
fn read_ident_like(&mut self) -> LexResult<Token> {
// Consume a name, and let string be the result.
let name = self.read_name()?;
let ident_sequence = self.read_ident_sequence()?;
// If strings value is an ASCII case-insensitive match for "url", and the next
// input code point is U+0028 LEFT PARENTHESIS ((), consume it.
if name.0.to_ascii_lowercase() == js_word!("url") && self.next() == Some('(') {
if ident_sequence.0.to_ascii_lowercase() == js_word!("url") && self.next() == Some('(') {
self.consume();
let start_whitespace = self.input.cur_pos();
let mut whitespaces = String::new();
// While the next two input code points are whitespace, consume the next input
// code point.
while let (Some(next), Some(next_next)) = (self.next(), self.next_next()) {
if is_whitespace(next) && is_whitespace(next_next) {
self.consume();
whitespaces.push(next);
} else {
break;
}
@ -531,19 +534,19 @@ where
self.last_pos = Some(start_whitespace);
return Ok(Token::Function {
value: name.0,
raw: name.1,
value: ident_sequence.0,
raw: ident_sequence.1,
});
}
Some('"' | '\'') => {
return Ok(Token::Function {
value: name.0,
raw: name.1,
value: ident_sequence.0,
raw: ident_sequence.1,
});
}
// Otherwise, consume a url token, and return it.
_ => {
return self.read_url(name);
return self.read_url(ident_sequence, whitespaces);
}
}
}
@ -553,16 +556,16 @@ where
self.consume();
return Ok(Token::Function {
value: name.0,
raw: name.1,
value: ident_sequence.0,
raw: ident_sequence.1,
});
}
// Otherwise, create an <ident-token> with its value set to string and return
// it.
Ok(Token::Ident {
value: name.0,
raw: name.1,
value: ident_sequence.0,
raw: ident_sequence.1,
})
}
@ -658,7 +661,7 @@ where
// This section describes how to consume a url token from a stream of code
// points. It returns either a <url-token> or a <bad-url-token>.
fn read_url(&mut self, name: (JsWord, JsWord)) -> LexResult<Token> {
fn read_url(&mut self, name: (JsWord, JsWord), mut before: String) -> LexResult<Token> {
// Initially create a <url-token> with its value set to the empty string.
let mut value = String::new();
let mut raw = String::new();
@ -667,6 +670,8 @@ where
while let Some(c) = self.next() {
if is_whitespace(c) {
self.consume();
before.push(c);
} else {
break;
}
@ -685,6 +690,8 @@ where
raw_name: name.1,
value: value.into(),
raw_value: raw.into(),
before: before.into(),
after: "".into(),
});
}
@ -696,6 +703,8 @@ where
raw_name: name.1,
value: value.into(),
raw_value: raw.into(),
before: before.into(),
after: "".into(),
});
}
@ -716,8 +725,6 @@ where
}
}
raw.push_str(&whitespaces);
// if the next input code point is U+0029 RIGHT PARENTHESIS ()) or EOF, consume
// it and return the <url-token> (if EOF was encountered, this is a parse
// error);
@ -730,6 +737,8 @@ where
raw_name: name.1,
value: value.into(),
raw_value: raw.into(),
before: before.into(),
after: whitespaces.into(),
});
}
None => {
@ -738,12 +747,15 @@ where
raw_name: name.1,
value: value.into(),
raw_value: raw.into(),
before: before.into(),
after: whitespaces.into(),
});
}
_ => {}
}
value.push_str(&whitespaces);
raw.push_str(&whitespaces);
// otherwise, consume the remnants of a bad url, create a <bad-url-token>, and
// return it.
@ -755,8 +767,8 @@ where
return Ok(Token::BadUrl {
name: name.0,
raw_name: name.1,
value: value.into(),
raw_value: raw.into(),
value: (before.to_owned() + &raw.to_owned()).into(),
raw_value: (before.to_owned() + &&raw.to_owned()).into(),
});
}
@ -777,8 +789,8 @@ where
return Ok(Token::BadUrl {
name: name.0,
raw_name: name.1,
value: value.into(),
raw_value: raw.into(),
value: (before.to_owned() + &raw.to_owned()).into(),
raw_value: (before.to_owned() + &&raw.to_owned()).into(),
});
}
@ -806,8 +818,8 @@ where
return Ok(Token::BadUrl {
name: name.0,
raw_name: name.1,
value: value.into(),
raw_value: raw.into(),
value: (before.to_owned() + &raw.to_owned()).into(),
raw_value: (before.to_owned() + &&raw.to_owned()).into(),
});
}
}
@ -1034,11 +1046,11 @@ where
}
}
// Consume a name
// This section describes how to consume a name from a stream of code points. It
// returns a string containing the largest name that can be formed from adjacent
// code points in the stream, starting from the first.
fn read_name(&mut self) -> LexResult<(JsWord, JsWord)> {
// Consume an ident sequence
// This section describes how to consume an ident sequence from a stream of code
// points. It returns a string containing the largest name that can be formed
// from adjacent code points in the stream, starting from the first.
fn read_ident_sequence(&mut self) -> LexResult<(JsWord, JsWord)> {
// Let result initially be an empty string.
let mut raw = String::new();
let mut value = String::new();

View File

@ -764,20 +764,27 @@ where
raw_name,
value,
raw_value,
before,
after,
} => {
let name_length = raw_name.len() as u32;
let name = Ident {
// TODO add additional fields in lexer to keep original spaces and fix span
span: swc_common::Span::new(span.lo, span.lo + BytePos(3), Default::default()),
span: swc_common::Span::new(
span.lo,
span.lo + BytePos(name_length),
Default::default(),
),
value: name,
raw: raw_name,
};
let value = Some(UrlValue::Raw(UrlValueRaw {
span: swc_common::Span::new(
span.lo + BytePos(4),
span.lo + BytePos(name_length + 1),
span.hi - BytePos(1),
Default::default(),
),
before,
after,
value,
raw: raw_value,
}));

View File

@ -117,6 +117,8 @@
"end": 79,
"ctxt": 0
},
"before": "",
"after": "",
"value": "./style.css",
"raw": "./style.css"
},
@ -239,6 +241,8 @@
"end": 179,
"ctxt": 0
},
"before": "",
"after": "",
"value": "./style.css",
"raw": "./style.css"
},
@ -1235,6 +1239,8 @@
"end": 849,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -1355,6 +1361,8 @@
"end": 922,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -1395,6 +1403,8 @@
"end": 945,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -1435,8 +1445,10 @@
"end": 969,
"ctxt": 0
},
"before": "",
"after": " ",
"value": "test.css",
"raw": "test.css "
"raw": "test.css"
},
"modifiers": null
},
@ -1475,6 +1487,8 @@
"end": 993,
"ctxt": 0
},
"before": " ",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -1515,8 +1529,10 @@
"end": 1018,
"ctxt": 0
},
"before": " ",
"after": " ",
"value": "test.css",
"raw": "test.css "
"raw": "test.css"
},
"modifiers": null
},
@ -1555,8 +1571,10 @@
"end": 1043,
"ctxt": 0
},
"before": "\n",
"after": "\n",
"value": "test.css",
"raw": "test.css\n"
"raw": "test.css"
},
"modifiers": null
},
@ -1595,6 +1613,8 @@
"end": 1058,
"ctxt": 0
},
"before": "",
"after": "",
"value": "",
"raw": ""
},
@ -1841,6 +1861,8 @@
"end": 1200,
"ctxt": 0
},
"before": "",
"after": "",
"value": "",
"raw": ""
},
@ -1961,6 +1983,8 @@
"end": 1257,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -2067,6 +2091,8 @@
"end": 1315,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -2173,6 +2199,8 @@
"end": 1374,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -2279,6 +2307,8 @@
"end": 1431,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -2385,6 +2415,8 @@
"end": 1510,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -2531,6 +2563,8 @@
"end": 1617,
"ctxt": 0
},
"before": "",
"after": "",
"value": "~package/test.css",
"raw": "~package/test.css"
},
@ -2771,6 +2805,8 @@
"end": 1932,
"ctxt": 0
},
"before": "",
"after": "",
"value": "~package/tilde.css",
"raw": "~package/tilde.css"
},
@ -2811,6 +2847,8 @@
"end": 1971,
"ctxt": 0
},
"before": "",
"after": "",
"value": "~aliasesImport/alias.css",
"raw": "~aliasesImport/alias.css"
},
@ -2891,6 +2929,8 @@
"end": 2023,
"ctxt": 0
},
"before": "",
"after": "",
"value": "./test.css",
"raw": "./test.css"
},
@ -3480,6 +3520,8 @@
"end": 2583,
"ctxt": 0
},
"before": "",
"after": "",
"value": "./test test.css",
"raw": "./test\\ test.css"
},
@ -3520,6 +3562,8 @@
"end": 2617,
"ctxt": 0
},
"before": "",
"after": "",
"value": "./test%20test.css",
"raw": "./t\\65st%20test.css"
},
@ -3682,8 +3726,10 @@
"end": 2813,
"ctxt": 0
},
"before": " ",
"after": " ",
"value": "test.css",
"raw": "test.css "
"raw": "test.css"
},
"modifiers": null
},
@ -3783,6 +3829,8 @@
"end": 2946,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css?foo=bar",
"raw": "test.css?foo=bar"
},
@ -3823,6 +3871,8 @@
"end": 2982,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css?foo=bar#hash",
"raw": "test.css?foo=bar#hash"
},
@ -3863,6 +3913,8 @@
"end": 3011,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css?#hash",
"raw": "test.css?#hash"
},
@ -4249,8 +4301,10 @@
"end": 3304,
"ctxt": 0
},
"before": " ",
"after": " ",
"value": "./test.css",
"raw": "./test.css "
"raw": "./test.css"
},
"modifiers": null
},
@ -4430,6 +4484,8 @@
"end": 3638,
"ctxt": 0
},
"before": "",
"after": "",
"value": "data:text/css;charset=utf-8,a%20%7B%0D%0A%20%20color%3A%20red%3B%0D%0A%7D",
"raw": "data:text/css;charset=utf-8,a%20%7B%0D%0A%20%20color%3A%20red%3B%0D%0A%7D"
},
@ -4470,6 +4526,8 @@
"end": 3671,
"ctxt": 0
},
"before": "",
"after": "",
"value": "package/first.css",
"raw": "package/first.css"
},
@ -4510,6 +4568,8 @@
"end": 3704,
"ctxt": 0
},
"before": "",
"after": "",
"value": "package/second.css",
"raw": "package/second.css"
},
@ -6552,6 +6612,8 @@
"end": 5195,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -6592,6 +6654,8 @@
"end": 5246,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -6632,6 +6696,8 @@
"end": 5283,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},
@ -6738,6 +6804,8 @@
"end": 5368,
"ctxt": 0
},
"before": "",
"after": "",
"value": "test.css",
"raw": "test.css"
},

View File

@ -85,6 +85,8 @@
"end": 79,
"ctxt": 0
},
"before": "",
"after": "",
"value": "http://www.w3.org/1999/xhtml",
"raw": "http://www.w3.org/1999/xhtml"
},
@ -170,6 +172,8 @@
"end": 175,
"ctxt": 0
},
"before": "",
"after": "",
"value": "http://www.w3.org/2000/svg",
"raw": "http://www.w3.org/2000/svg"
},

View File

@ -753,6 +753,8 @@
"end": 314,
"ctxt": 0
},
"before": "",
"after": "",
"value": "value",
"raw": "value"
},
@ -782,6 +784,8 @@
"end": 324,
"ctxt": 0
},
"before": "",
"after": "",
"value": "value",
"raw": "value"
},

View File

@ -112,6 +112,8 @@
"end": 20,
"ctxt": 0
},
"before": "",
"after": "",
"value": "aج",
"raw": "a\\62c"
},

View File

@ -37,6 +37,8 @@
"end": 19,
"ctxt": 0
},
"before": "",
"after": "",
"value": "foo.css",
"raw": "foo.css"
},

View File

@ -112,6 +112,8 @@
"end": 21,
"ctxt": 0
},
"before": "",
"after": "",
"value": "abc",
"raw": "a\\62 c"
},

View File

@ -112,6 +112,8 @@
"end": 17,
"ctxt": 0
},
"before": "",
"after": "",
"value": ",",
"raw": "\\,"
},

View File

@ -37,6 +37,8 @@
"end": 19,
"ctxt": 0
},
"before": "",
"after": "",
"value": "foo.css",
"raw": "foo.css"
},

View File

@ -112,6 +112,8 @@
"end": 18,
"ctxt": 0
},
"before": "",
"after": "",
"value": ",",
"raw": "\\2c"
},

View File

@ -112,6 +112,8 @@
"end": 21,
"ctxt": 0
},
"before": "",
"after": "",
"value": "abc",
"raw": "\\61 bc"
},

View File

@ -37,6 +37,8 @@
"end": 12,
"ctxt": 0
},
"before": "",
"after": "",
"value": "",
"raw": ""
},

View File

@ -112,6 +112,8 @@
"end": 20,
"ctxt": 0
},
"before": "",
"after": "",
"value": "憼",
"raw": "\\61bc"
},

View File

@ -112,6 +112,8 @@
"end": 108,
"ctxt": 0
},
"before": "",
"after": "",
"value": "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
"raw": "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
},
@ -512,6 +514,8 @@
"end": 487,
"ctxt": 0
},
"before": "",
"after": "",
"value": "",
"raw": ""
},
@ -562,6 +566,8 @@
"end": 519,
"ctxt": 0
},
"before": " ",
"after": "",
"value": "",
"raw": ""
},
@ -862,6 +868,8 @@
"end": 733,
"ctxt": 0
},
"before": "",
"after": "",
"value": "./image.png",
"raw": "./image.png"
},
@ -912,8 +920,10 @@
"end": 779,
"ctxt": 0
},
"before": " ",
"after": " ",
"value": "./image.png",
"raw": "./image.png "
"raw": "./image.png"
},
"modifiers": null
}
@ -962,8 +972,10 @@
"end": 828,
"ctxt": 0
},
"before": " ",
"after": " ",
"value": "./image2.png",
"raw": "./image\\32.png "
"raw": "./image\\32.png"
},
"modifiers": null
}
@ -1012,8 +1024,10 @@
"end": 887,
"ctxt": 0
},
"before": " \n ",
"after": " \n ",
"value": "./image2.png",
"raw": "./image\\32.png \n "
"raw": "./image\\32.png"
},
"modifiers": null
}
@ -1062,8 +1076,10 @@
"end": 973,
"ctxt": 0
},
"before": "\n \n \n \n ",
"after": "\n \n \n \n ",
"value": "./image2.png",
"raw": "./image\\32.png\n \n \n \n "
"raw": "./image\\32.png"
},
"modifiers": null
}
@ -1112,8 +1128,10 @@
"end": 1038,
"ctxt": 0
},
"before": " \n\n\n\n ",
"after": "\n\n\n\n ",
"value": "./image2.png",
"raw": "./image\\32.png\n\n\n\n "
"raw": "./image\\32.png"
},
"modifiers": null
}
@ -1162,6 +1180,8 @@
"end": 1075,
"ctxt": 0
},
"before": "",
"after": "",
"value": "image.png\u0001",
"raw": "image.png\\0001"
},
@ -1212,6 +1232,8 @@
"end": 1109,
"ctxt": 0
},
"before": "",
"after": "",
"value": "image.png\u0001",
"raw": "image.png\\1"
},
@ -1262,6 +1284,8 @@
"end": 1146,
"ctxt": 0
},
"before": "",
"after": "",
"value": "image.png힙",
"raw": "image.png\\D799"
},
@ -1312,6 +1336,8 @@
"end": 1183,
"ctxt": 0
},
"before": "",
"after": "",
"value": "image.png",
"raw": "image.png\\E000"
},
@ -1362,6 +1388,8 @@
"end": 1222,
"ctxt": 0
},
"before": "",
"after": "",
"value": "image.png􏿿",
"raw": "image.png\\10FFFF"
},
@ -1412,6 +1440,8 @@
"end": 1247,
"ctxt": 0
},
"before": "",
"after": "",
"value": "18",
"raw": "18"
},

View File

@ -1703,6 +1703,8 @@
"Url": {
"name": "url",
"raw_name": "url",
"before": "",
"after": "",
"value": "foo.png",
"raw_value": "foo.png"
}

View File

@ -1210,7 +1210,7 @@ error: Tokens
15 | :unknown(url(foo.png)) {}
| ^^^^^^^^^^^^
error: Url { name: Atom('url' type=static), raw_name: Atom('url' type=static), value: Atom('foo.png' type=inline), raw_value: Atom('foo.png' type=inline) }
error: Url { name: Atom('url' type=static), raw_name: Atom('url' type=static), before: Atom('' type=static), after: Atom('' type=static), value: Atom('foo.png' type=inline), raw_value: Atom('foo.png' type=inline) }
--> $DIR/tests/fixture/selector/pseudo-class/unknown/input.css:15:10
|
15 | :unknown(url(foo.png)) {}

View File

@ -1703,6 +1703,8 @@
"Url": {
"name": "url",
"raw_name": "url",
"before": "",
"after": "",
"value": "foo.png",
"raw_value": "foo.png"
}

View File

@ -1210,7 +1210,7 @@ error: Tokens
15 | ::unknown(url(foo.png)) {}
| ^^^^^^^^^^^^
error: Url { name: Atom('url' type=static), raw_name: Atom('url' type=static), value: Atom('foo.png' type=inline), raw_value: Atom('foo.png' type=inline) }
error: Url { name: Atom('url' type=static), raw_name: Atom('url' type=static), before: Atom('' type=static), after: Atom('' type=static), value: Atom('foo.png' type=inline), raw_value: Atom('foo.png' type=inline) }
--> $DIR/tests/fixture/selector/pseudo-element/unknown/input.css:15:11
|
15 | ::unknown(url(foo.png)) {}

View File

@ -130,6 +130,8 @@
"end": 37,
"ctxt": 0
},
"before": "",
"after": "",
"value": "foo.jpg",
"raw": "foo.jpg"
},

View File

@ -23,4 +23,17 @@ div {
background: src("http://www.example.com/pinkish.gif");
background: SRC("http://www.example.com/pinkish.gif");
background: src(var(--foo));
background: url( https://example.com/image.png );
background: u\rl( https://example.com/image.png );
background: url(
https://example.com/image.png
);
background: url(
https://example.com/image.png
);
background: URL(https://example.com/ima\)ge.png);
}

View File

@ -2,7 +2,7 @@
"type": "Stylesheet",
"span": {
"start": 0,
"end": 1022,
"end": 1335,
"ctxt": 0
},
"rules": [
@ -10,7 +10,7 @@
"type": "QualifiedRule",
"span": {
"start": 0,
"end": 1021,
"end": 1334,
"ctxt": 0
},
"prelude": {
@ -66,7 +66,7 @@
"type": "Block",
"span": {
"start": 4,
"end": 1021,
"end": 1334,
"ctxt": 0
},
"value": [
@ -112,6 +112,8 @@
"end": 55,
"ctxt": 0
},
"before": "",
"after": "",
"value": "https://example.com/image.png",
"raw": "https://example.com/image.png"
},
@ -162,6 +164,8 @@
"end": 107,
"ctxt": 0
},
"before": "",
"after": "",
"value": "https://example.com/image.png",
"raw": "https://example.com/image.png"
},
@ -199,7 +203,7 @@
"type": "Identifier",
"span": {
"start": 126,
"end": 129,
"end": 130,
"ctxt": 0
},
"value": "URL",
@ -208,10 +212,12 @@
"value": {
"type": "UrlValueRaw",
"span": {
"start": 130,
"start": 131,
"end": 160,
"ctxt": 0
},
"before": "",
"after": "",
"value": "https://example.com/image.png",
"raw": "https://example.com/image.png"
},
@ -462,6 +468,8 @@
"end": 428,
"ctxt": 0
},
"before": "",
"after": "",
"value": "data:image/png;base64,iRxVB0",
"raw": "data:image/png;base64,iRxVB0"
},
@ -512,6 +520,8 @@
"end": 463,
"ctxt": 0
},
"before": "",
"after": "",
"value": "#IDofSVGpath",
"raw": "#IDofSVGpath"
},
@ -845,6 +855,8 @@
"end": 765,
"ctxt": 0
},
"before": "",
"after": "",
"value": "",
"raw": ""
},
@ -1168,6 +1180,266 @@
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 1024,
"end": 1076,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 1024,
"end": 1034,
"ctxt": 0
},
"value": "background",
"raw": "background"
},
"value": [
{
"type": "Url",
"span": {
"start": 1036,
"end": 1076,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 1036,
"end": 1039,
"ctxt": 0
},
"value": "url",
"raw": "url"
},
"value": {
"type": "UrlValueRaw",
"span": {
"start": 1040,
"end": 1075,
"ctxt": 0
},
"before": " ",
"after": " ",
"value": "https://example.com/image.png",
"raw": "https://example.com/image.png"
},
"modifiers": null
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 1082,
"end": 1135,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 1082,
"end": 1092,
"ctxt": 0
},
"value": "background",
"raw": "background"
},
"value": [
{
"type": "Url",
"span": {
"start": 1094,
"end": 1135,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 1094,
"end": 1098,
"ctxt": 0
},
"value": "url",
"raw": "u\\rl"
},
"value": {
"type": "UrlValueRaw",
"span": {
"start": 1099,
"end": 1134,
"ctxt": 0
},
"before": " ",
"after": " ",
"value": "https://example.com/image.png",
"raw": "https://example.com/image.png"
},
"modifiers": null
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 1141,
"end": 1219,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 1141,
"end": 1151,
"ctxt": 0
},
"value": "background",
"raw": "background"
},
"value": [
{
"type": "Url",
"span": {
"start": 1153,
"end": 1219,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 1153,
"end": 1156,
"ctxt": 0
},
"value": "url",
"raw": "url"
},
"value": {
"type": "UrlValueRaw",
"span": {
"start": 1157,
"end": 1218,
"ctxt": 0
},
"before": " \n ",
"after": " \n ",
"value": "https://example.com/image.png",
"raw": "https://example.com/image.png"
},
"modifiers": null
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 1225,
"end": 1277,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 1225,
"end": 1235,
"ctxt": 0
},
"value": "background",
"raw": "background"
},
"value": [
{
"type": "Url",
"span": {
"start": 1237,
"end": 1277,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 1237,
"end": 1240,
"ctxt": 0
},
"value": "url",
"raw": "url"
},
"value": {
"type": "UrlValueRaw",
"span": {
"start": 1241,
"end": 1276,
"ctxt": 0
},
"before": "\n\n\n",
"after": "\n\n\n",
"value": "https://example.com/image.png",
"raw": "https://example.com/image.png"
},
"modifiers": null
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 1283,
"end": 1331,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 1283,
"end": 1293,
"ctxt": 0
},
"value": "background",
"raw": "background"
},
"value": [
{
"type": "Url",
"span": {
"start": 1295,
"end": 1331,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 1295,
"end": 1298,
"ctxt": 0
},
"value": "URL",
"raw": "URL"
},
"value": {
"type": "UrlValueRaw",
"span": {
"start": 1299,
"end": 1330,
"ctxt": 0
},
"before": "",
"after": "",
"value": "https://example.com/ima)ge.png",
"raw": "https://example.com/ima\\)ge.png"
},
"modifiers": null
}
],
"important": null
}
]
}

View File

@ -6,8 +6,8 @@ error: Stylesheet
3 | | background: URL(https://example.com/image.png);
4 | | background: \URL(https://example.com/image.png);
... |
25 | | background: src(var(--foo));
26 | | }
38 | | background: URL(https://example.com/ima\)ge.png);
39 | | }
| |__^
error: Rule
@ -18,8 +18,8 @@ error: Rule
3 | | background: URL(https://example.com/image.png);
4 | | background: \URL(https://example.com/image.png);
... |
25 | | background: src(var(--foo));
26 | | }
38 | | background: URL(https://example.com/ima\)ge.png);
39 | | }
| |_^
error: QualifiedRule
@ -30,8 +30,8 @@ error: QualifiedRule
3 | | background: URL(https://example.com/image.png);
4 | | background: \URL(https://example.com/image.png);
... |
25 | | background: src(var(--foo));
26 | | }
38 | | background: URL(https://example.com/ima\)ge.png);
39 | | }
| |_^
error: SelectorList
@ -73,8 +73,8 @@ error: Block
3 | | background: URL(https://example.com/image.png);
4 | | background: \URL(https://example.com/image.png);
... |
25 | | background: src(var(--foo));
26 | | }
38 | | background: URL(https://example.com/ima\)ge.png);
39 | | }
| |_^
error: Declaration
@ -207,19 +207,19 @@ error: Ident
--> $DIR/tests/fixture/value/url/input.css:4:17
|
4 | background: \URL(https://example.com/image.png);
| ^^^
| ^^^^
error: UrlValue
--> $DIR/tests/fixture/value/url/input.css:4:21
--> $DIR/tests/fixture/value/url/input.css:4:22
|
4 | background: \URL(https://example.com/image.png);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: UrlValueRaw
--> $DIR/tests/fixture/value/url/input.css:4:21
--> $DIR/tests/fixture/value/url/input.css:4:22
|
4 | background: \URL(https://example.com/image.png);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Declaration
--> $DIR/tests/fixture/value/url/input.css:5:5
@ -1133,3 +1133,291 @@ error: DashedIdent
25 | background: src(var(--foo));
| ^^^^^
error: Declaration
--> $DIR/tests/fixture/value/url/input.css:26:5
|
26 | background: url( https://example.com/image.png );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: DeclarationName
--> $DIR/tests/fixture/value/url/input.css:26:5
|
26 | background: url( https://example.com/image.png );
| ^^^^^^^^^^
error: Ident
--> $DIR/tests/fixture/value/url/input.css:26:5
|
26 | background: url( https://example.com/image.png );
| ^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/value/url/input.css:26:17
|
26 | background: url( https://example.com/image.png );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Url
--> $DIR/tests/fixture/value/url/input.css:26:17
|
26 | background: url( https://example.com/image.png );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Ident
--> $DIR/tests/fixture/value/url/input.css:26:17
|
26 | background: url( https://example.com/image.png );
| ^^^
error: UrlValue
--> $DIR/tests/fixture/value/url/input.css:26:21
|
26 | background: url( https://example.com/image.png );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: UrlValueRaw
--> $DIR/tests/fixture/value/url/input.css:26:21
|
26 | background: url( https://example.com/image.png );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Declaration
--> $DIR/tests/fixture/value/url/input.css:27:5
|
27 | background: u\rl( https://example.com/image.png );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: DeclarationName
--> $DIR/tests/fixture/value/url/input.css:27:5
|
27 | background: u\rl( https://example.com/image.png );
| ^^^^^^^^^^
error: Ident
--> $DIR/tests/fixture/value/url/input.css:27:5
|
27 | background: u\rl( https://example.com/image.png );
| ^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/value/url/input.css:27:17
|
27 | background: u\rl( https://example.com/image.png );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Url
--> $DIR/tests/fixture/value/url/input.css:27:17
|
27 | background: u\rl( https://example.com/image.png );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Ident
--> $DIR/tests/fixture/value/url/input.css:27:17
|
27 | background: u\rl( https://example.com/image.png );
| ^^^^
error: UrlValue
--> $DIR/tests/fixture/value/url/input.css:27:22
|
27 | background: u\rl( https://example.com/image.png );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: UrlValueRaw
--> $DIR/tests/fixture/value/url/input.css:27:22
|
27 | background: u\rl( https://example.com/image.png );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Declaration
--> $DIR/tests/fixture/value/url/input.css:28:5
|
28 | / background: url(
29 | | https://example.com/image.png
30 | | );
| |_____^
error: DeclarationName
--> $DIR/tests/fixture/value/url/input.css:28:5
|
28 | background: url(
| ^^^^^^^^^^
error: Ident
--> $DIR/tests/fixture/value/url/input.css:28:5
|
28 | background: url(
| ^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/value/url/input.css:28:17
|
28 | background: url(
| _________________^
29 | | https://example.com/image.png
30 | | );
| |_____^
error: Url
--> $DIR/tests/fixture/value/url/input.css:28:17
|
28 | background: url(
| _________________^
29 | | https://example.com/image.png
30 | | );
| |_____^
error: Ident
--> $DIR/tests/fixture/value/url/input.css:28:17
|
28 | background: url(
| ^^^
error: UrlValue
--> $DIR/tests/fixture/value/url/input.css:28:21
|
28 | background: url(
| _____________________^
29 | | https://example.com/image.png
30 | | );
| |____^
error: UrlValueRaw
--> $DIR/tests/fixture/value/url/input.css:28:21
|
28 | background: url(
| _____________________^
29 | | https://example.com/image.png
30 | | );
| |____^
error: Declaration
--> $DIR/tests/fixture/value/url/input.css:31:5
|
31 | / background: url(
32 | |
33 | |
34 | | https://example.com/image.png
35 | |
36 | |
37 | | );
| |_^
error: DeclarationName
--> $DIR/tests/fixture/value/url/input.css:31:5
|
31 | background: url(
| ^^^^^^^^^^
error: Ident
--> $DIR/tests/fixture/value/url/input.css:31:5
|
31 | background: url(
| ^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/value/url/input.css:31:17
|
31 | background: url(
| _________________^
32 | |
33 | |
34 | | https://example.com/image.png
35 | |
36 | |
37 | | );
| |_^
error: Url
--> $DIR/tests/fixture/value/url/input.css:31:17
|
31 | background: url(
| _________________^
32 | |
33 | |
34 | | https://example.com/image.png
35 | |
36 | |
37 | | );
| |_^
error: Ident
--> $DIR/tests/fixture/value/url/input.css:31:17
|
31 | background: url(
| ^^^
error: UrlValue
--> $DIR/tests/fixture/value/url/input.css:31:21
|
31 | background: url(
| _____________________^
32 | |
33 | |
34 | | https://example.com/image.png
35 | |
36 | |
37 | | );
| |_
error: UrlValueRaw
--> $DIR/tests/fixture/value/url/input.css:31:21
|
31 | background: url(
| _____________________^
32 | |
33 | |
34 | | https://example.com/image.png
35 | |
36 | |
37 | | );
| |_
error: Declaration
--> $DIR/tests/fixture/value/url/input.css:38:5
|
38 | background: URL(https://example.com/ima\)ge.png);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: DeclarationName
--> $DIR/tests/fixture/value/url/input.css:38:5
|
38 | background: URL(https://example.com/ima\)ge.png);
| ^^^^^^^^^^
error: Ident
--> $DIR/tests/fixture/value/url/input.css:38:5
|
38 | background: URL(https://example.com/ima\)ge.png);
| ^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/value/url/input.css:38:17
|
38 | background: URL(https://example.com/ima\)ge.png);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Url
--> $DIR/tests/fixture/value/url/input.css:38:17
|
38 | background: URL(https://example.com/ima\)ge.png);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Ident
--> $DIR/tests/fixture/value/url/input.css:38:17
|
38 | background: URL(https://example.com/ima\)ge.png);
| ^^^
error: UrlValue
--> $DIR/tests/fixture/value/url/input.css:38:21
|
38 | background: URL(https://example.com/ima\)ge.png);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: UrlValueRaw
--> $DIR/tests/fixture/value/url/input.css:38:21
|
38 | background: URL(https://example.com/ima\)ge.png);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -121,8 +121,8 @@
"BadUrl": {
"name": "url",
"raw_name": "url",
"value": "./image.jpg a ",
"raw_value": "./image.jpg a "
"value": " ./image.jpg a ",
"raw_value": " ./image.jpg a "
}
}
}

View File

@ -222,6 +222,8 @@
"end": 124,
"ctxt": 0
},
"before": "",
"after": "",
"value": "image.png<6E>",
"raw": "image.png\\999999"
},
@ -272,6 +274,8 @@
"end": 158,
"ctxt": 0
},
"before": "",
"after": "",
"value": "image.png<6E>",
"raw": "image.png\\0"
},
@ -322,6 +326,8 @@
"end": 195,
"ctxt": 0
},
"before": "",
"after": "",
"value": "image.png<6E>",
"raw": "image.png\\D800"
},
@ -372,6 +378,8 @@
"end": 232,
"ctxt": 0
},
"before": "",
"after": "",
"value": "image.png<6E>",
"raw": "image.png\\DFFF"
},
@ -422,6 +430,8 @@
"end": 271,
"ctxt": 0
},
"before": "",
"after": "",
"value": "image.png<6E>",
"raw": "image.png\\11FFFF"
},

View File

@ -183,6 +183,8 @@ define!({
pub struct UrlValueRaw {
pub span: Span,
pub before: JsWord,
pub after: JsWord,
pub value: JsWord,
pub raw: JsWord,
}