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