modules use their own scope for module imports

this is a potentially breaking bugfix
This commit is contained in:
Connor Skees 2021-07-30 22:49:58 -04:00
parent 100e7bad54
commit d101a36f0c
2 changed files with 41 additions and 1 deletions

View File

@ -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,
@ -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()?;

View File

@ -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;";