Properly emit quotes after interpolation
This commit is contained in:
parent
465ac1b381
commit
fba6f2eb73
@ -107,6 +107,13 @@ impl Token {
|
||||
pos: Pos::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_symbol(s: Symbol) -> Self {
|
||||
Token {
|
||||
kind: TokenKind::Symbol(s),
|
||||
pos: Pos::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IsWhitespace for Token {
|
||||
|
22
src/style.rs
22
src/style.rs
@ -1,4 +1,4 @@
|
||||
use crate::common::{Pos, Scope, Symbol};
|
||||
use crate::common::{Pos, QuoteKind, Scope, Symbol};
|
||||
use crate::error::SassResult;
|
||||
use crate::selector::Selector;
|
||||
use crate::utils::{devour_whitespace, parse_interpolation, parse_quoted_string};
|
||||
@ -87,12 +87,20 @@ impl<'a> StyleParser<'a> {
|
||||
ref q @ TokenKind::Symbol(Symbol::DoubleQuote)
|
||||
| ref q @ TokenKind::Symbol(Symbol::SingleQuote) => {
|
||||
let q = q.clone();
|
||||
let tok = toks.next().unwrap();
|
||||
style.push(tok.clone());
|
||||
style.push(Token::from_string(
|
||||
parse_quoted_string(toks, scope, q)?.unquote().to_string(),
|
||||
));
|
||||
style.push(tok);
|
||||
toks.next();
|
||||
let (s, q) = if let Value::Ident(s, q) = parse_quoted_string(toks, scope, q)? {
|
||||
(s, q)
|
||||
} else {
|
||||
unreachable!()
|
||||
};
|
||||
let quote_kind = Token::from_symbol(match q {
|
||||
QuoteKind::Single => Symbol::SingleQuote,
|
||||
QuoteKind::Double => Symbol::DoubleQuote,
|
||||
_ => unreachable!(),
|
||||
});
|
||||
style.push(quote_kind.clone());
|
||||
style.push(Token::from_string(s));
|
||||
style.push(quote_kind);
|
||||
continue;
|
||||
}
|
||||
TokenKind::Symbol(Symbol::OpenCurlyBrace)
|
||||
|
@ -28,3 +28,8 @@ test!(
|
||||
"a {\n color: #{\"''\"};\n}\n",
|
||||
"a {\n color: '';\n}\n"
|
||||
);
|
||||
test!(
|
||||
single_quotes_converted_to_double_when_interpolated,
|
||||
"a {\n color: '#{foo}';\n}\n",
|
||||
"a {\n color: \"foo\";\n}\n"
|
||||
);
|
||||
|
@ -3,6 +3,8 @@
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
test!(single_quote, "a {\n color: 'foo';\n}\n");
|
||||
test!(double_quote, "a {\n color: \"foo\";\n}\n");
|
||||
test!(comma_list_ident, "a {\n color: foo, bar, baz;\n}\n");
|
||||
test!(space_list_ident, "a {\n color: foo bar baz;\n}\n");
|
||||
test!(comma_list_number, "a {\n color: 1, 2, 3;\n}\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user