Skip to content

Commit

Permalink
modules use their own scope for module imports
Browse files Browse the repository at this point in the history
this is a potentially breaking bugfix
  • Loading branch information
connorskees committed Jul 31, 2021
1 parent 100e7ba commit d101a36
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/parse/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
builtin::modules::{
declare_module_color, declare_module_list, declare_module_map, declare_module_math,
declare_module_meta, declare_module_selector, declare_module_string, Module, ModuleConfig,
Modules,
},
common::Identifier,
error::SassResult,
Expand Down Expand Up @@ -138,7 +139,7 @@ impl<'a, 'b> Parser<'a, 'b> {
extender: self.extender,
content_scopes: self.content_scopes,
options: self.options,
modules: self.modules,
modules: &mut Modules::default(),
module_config: config,
}
.parse()?;
Expand Down
39 changes: 39 additions & 0 deletions tests/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,45 @@ fn use_variable_redeclaration_private() {
);
}

#[test]
fn use_cannot_see_modules_imported_by_other_modules() {
let input = r#"
@use "use_cannot_see_modules_imported_by_other_modules__a" as a;
@use "use_cannot_see_modules_imported_by_other_modules__b" as b;"#;

tempfile!(
"use_cannot_see_modules_imported_by_other_modules__a.scss",
"$a: green;"
);
tempfile!(
"use_cannot_see_modules_imported_by_other_modules__b.scss",
"a { color: a.$a; }"
);

assert_err!("Error: There is no module with the namespace \"a\".", input);
}

#[test]
fn use_modules_imported_by_other_modules_does_not_cause_conflict() {
let input = r#"
@use "use_modules_imported_by_other_modules_does_not_cause_conflict__a" as a;
@use "use_modules_imported_by_other_modules_does_not_cause_conflict__b" as b;"#;

tempfile!(
"use_modules_imported_by_other_modules_does_not_cause_conflict__a.scss",
"$a: red;"
);
tempfile!(
"use_modules_imported_by_other_modules_does_not_cause_conflict__b.scss",
"@use \"use_modules_imported_by_other_modules_does_not_cause_conflict__a\" as a; a { color: a.$a; }"
);

assert_eq!(
"a {\n color: red;\n}\n",
&grass::from_string(input.to_string(), &grass::Options::default()).expect(input)
);
}

#[test]
fn use_variable_redeclaration_builtin() {
let input = "@use \"sass:math\";\nmath.$e: red;";
Expand Down

0 comments on commit d101a36

Please sign in to comment.