move module variable parsing to module file

This commit is contained in:
Connor Skees 2020-08-07 02:03:43 -04:00
parent 438abe52be
commit a7ccb4d6d3
2 changed files with 40 additions and 37 deletions

View File

@ -11,7 +11,6 @@ use crate::{
AtRuleKind, SupportsRule, UnknownAtRule,
},
builtin::modules::{ModuleConfig, Modules},
common::Identifier,
error::SassResult,
scope::{Scope, Scopes},
selector::{
@ -133,41 +132,6 @@ impl<'a> Parser<'a> {
}
}
fn parse_module_variable_redeclaration(&mut self, module: Identifier) -> SassResult<()> {
let variable = self
.parse_identifier_no_interpolation(false)?
.map_node(|n| n.into());
self.whitespace_or_comment();
self.expect_char(':')?;
let VariableValue {
val_toks,
global,
default,
} = self.parse_variable_value()?;
if global {
return Err((
"!global isn't allowed for variables in other modules.",
variable.span,
)
.into());
}
if default {
return Ok(());
}
let value = self.parse_value_from_vec(val_toks, true)?;
self.modules
.get_mut(module, variable.span)?
.update_var(variable, value.node)?;
Ok(())
}
fn parse_stmt(&mut self) -> SassResult<Vec<Stmt>> {
let mut stmts = Vec::new();
while let Some(Token { kind, pos }) = self.toks.peek() {

View File

@ -9,9 +9,10 @@ use crate::{
declare_module_color, declare_module_list, declare_module_map, declare_module_math,
declare_module_meta, declare_module_selector, declare_module_string, Module, ModuleConfig,
},
common::Identifier,
error::SassResult,
lexer::Lexer,
parse::{common::Comment, Parser, Stmt},
parse::{common::Comment, Parser, Stmt, VariableValue},
scope::Scope,
utils::peek_ident_no_interpolation,
Token,
@ -248,4 +249,42 @@ impl<'a> Parser<'a> {
Ok(comments)
}
pub(super) fn parse_module_variable_redeclaration(
&mut self,
module: Identifier,
) -> SassResult<()> {
let variable = self
.parse_identifier_no_interpolation(false)?
.map_node(|n| n.into());
self.whitespace_or_comment();
self.expect_char(':')?;
let VariableValue {
val_toks,
global,
default,
} = self.parse_variable_value()?;
if global {
return Err((
"!global isn't allowed for variables in other modules.",
variable.span,
)
.into());
}
if default {
return Ok(());
}
let value = self.parse_value_from_vec(val_toks, true)?;
self.modules
.get_mut(module, variable.span)?
.update_var(variable, value.node)?;
Ok(())
}
}