Skip to content

Commit 9497a2d

Browse files
authored
fix: adjust_options with both data and file (#29)
1 parent feef290 commit 9497a2d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/legacy/api.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,9 @@ impl From<LegacyOptions> for StringOptions {
440440
impl LegacyOptions {
441441
pub(crate) fn adjust_options(mut self) -> Self {
442442
if let Some(file) = &self.file {
443-
if self.indented_syntax.is_some() || self.importers.is_some() {
443+
if self.data.is_none()
444+
&& (self.indented_syntax.is_some() || self.importers.is_some())
445+
{
444446
self.data = Some(fs::read_to_string(file).unwrap());
445447
self.indented_syntax = Some(self.indented_syntax.unwrap_or_default());
446448
}

tests/compile_spec.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,22 @@ mod compile_string {
500500
assert_eq!(err.span().unwrap().start.line, 0);
501501
assert_eq!(err.span().unwrap().url.as_ref().unwrap(), &url);
502502
}
503+
504+
#[test]
505+
fn with_multi_span_errors() {
506+
let sandbox = Sandbox::default();
507+
let url = sandbox.path().join("foo.scss").to_url();
508+
509+
let mut sass = Sass::new(exe_path()).unwrap();
510+
let err = sass
511+
.compile_string(
512+
"@use \"sass:math\"; @use \"sass:math\"",
513+
StringOptionsBuilder::default().url(url.clone()).build(),
514+
)
515+
.unwrap_err();
516+
assert_eq!(err.span().unwrap().start.line, 0);
517+
assert_eq!(err.span().unwrap().url.as_ref().unwrap(), &url);
518+
}
503519
}
504520
}
505521
}

0 commit comments

Comments
 (0)