Skip to content

Commit

Permalink
Improve support for css @import.
Browse files Browse the repository at this point in the history
The arg may be an `url(...)` function call.
  • Loading branch information
kaj committed Nov 17, 2024
1 parent c445195 commit e0a800d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions rsass/src/css/item.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{AtRule, Comment, CssString, MediaRule, Rule, Value};
use super::{AtRule, Comment, MediaRule, Rule, Value};
use crate::output::CssBuf;
use std::io::{self, Write};

Expand Down Expand Up @@ -62,20 +62,20 @@ impl From<MediaRule> for Item {
/// An `@import` rule in css.
#[derive(Clone, Debug)]
pub struct Import {
name: CssString,
name: Value,
args: Value,
}

impl Import {
/// Create a new `@import`.
pub fn new(name: CssString, args: Value) -> Self {
pub fn new(name: Value, args: Value) -> Self {
Self { name, args }
}

/// Write this comment to a css output buffer.
pub(crate) fn write(&self, buf: &mut CssBuf) -> io::Result<()> {
buf.do_indent_no_nl();
write!(buf, "@import {}", self.name)?;
write!(buf, "@import {}", &self.name.format(buf.format()))?;
if !self.args.is_null() {
write!(buf, " {}", self.args.format(buf.format()))?;
}
Expand Down
4 changes: 2 additions & 2 deletions rsass/src/output/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::cssdest::CssDestination;
use super::CssData;
use crate::css::{self, AtRule, Import, SelectorCtx};
use crate::css::{self, AtRule, Import, SelectorCtx, Value};
use crate::error::ResultPos;
use crate::input::{Context, Loader, Parsed, SourceKind};
use crate::sass::{get_global_module, Expose, Item, UseAs};
Expand Down Expand Up @@ -198,7 +198,7 @@ fn handle_item(
}
}
let args = args.evaluate(scope.clone())?;
dest.push_import(Import::new(name, args));
dest.push_import(Import::new(Value::Literal(name), args));
}
}
Item::AtRoot(ref selectors, ref body) => {
Expand Down
2 changes: 1 addition & 1 deletion rsass/src/parser/css/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn import2(input: Span) -> PResult<Import> {
map(
delimited(
opt_spacelike,
strings::css_string_any,
values::string_or_call,
// TODO: Media arguments!
opt(terminated(opt_spacelike, tag(";"))),
),
Expand Down
2 changes: 1 addition & 1 deletion rsass/src/parser/css/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn single(input: Span) -> PResult<Value> {
}
}

fn string_or_call(input: Span) -> PResult<Value> {
pub fn string_or_call(input: Span) -> PResult<Value> {
let (rest, string) = strings::css_string_any(input)?;
if string.quotes().is_none() {
if let Ok((rest, _)) = terminated(tag("("), opt_spacelike)(rest) {
Expand Down
2 changes: 1 addition & 1 deletion rsass/tests/spec/css/plain/error/statement/at_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ mod import {
}

#[test]
#[ignore] // wrong error
#[ignore] // missing error
fn interpolated() {
let runner = runner().with_cwd("interpolated");
assert_eq!(
Expand Down
2 changes: 0 additions & 2 deletions rsass/tests/spec/css/plain/import/in_css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mod url {
}

#[test]
#[ignore] // unexepected error
fn quoted() {
let runner = runner().with_cwd("quoted");
assert_eq!(
Expand All @@ -30,7 +29,6 @@ mod url {
);
}
#[test]
#[ignore] // unexepected error
fn unquoted() {
let runner = runner().with_cwd("unquoted");
assert_eq!(
Expand Down

0 comments on commit e0a800d

Please sign in to comment.