Parse and format import package shorthand

The original proposal [1] suggested dropping the package shorthand,
but we later decided to keep it [2] to improve UX.

[1] https://docs.google.com/document/d/1E_77fO-44BtoBtXoVeWyGh1xN2KRTWTu8q6i25RNNx0/edit?usp=sharing
[2] 385104011
This commit is contained in:
Agus Zubiaga 2023-12-06 21:39:00 -03:00
parent c56091ee3e
commit 65ce811587
No known key found for this signature in database
15 changed files with 349 additions and 115 deletions

View file

@ -458,8 +458,8 @@ pub enum ValueDef<'a> {
/// e.g. `import InternalHttp as Http exposing [Req]`.
ModuleImport {
name: Loc<Spaced<'a, crate::header::ModuleName<'a>>>,
alias: Option<Loc<Spaced<'a, crate::header::ModuleName<'a>>>>,
name: Loc<Spaced<'a, ImportedModuleName<'a>>>,
alias: Option<Loc<Spaced<'a, ImportAlias<'a>>>>,
exposed: Option<(
&'a [CommentOrNewline<'a>],
Collection<'a, Loc<Spaced<'a, crate::header::ExposedName<'a>>>>,
@ -467,6 +467,25 @@ pub enum ValueDef<'a> {
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ImportedModuleName<'a> {
pub package: Option<&'a str>,
pub name: &'a str,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ImportAlias<'a>(&'a str);
impl<'a> ImportAlias<'a> {
pub const fn new(name: &'a str) -> Self {
ImportAlias(name)
}
pub const fn as_str(&'a self) -> &'a str {
self.0
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Defs<'a> {
pub tags: std::vec::Vec<EitherIndex<TypeDef<'a>, ValueDef<'a>>>,
@ -1803,13 +1822,10 @@ impl<'a> Malformed for ValueDef<'a> {
preceding_comment: _,
} => condition.is_malformed(),
ValueDef::ModuleImport {
name,
alias,
name: _,
alias: _,
exposed: _,
} => {
name.value.item().contains_dot()
|| alias.map_or(false, |x| x.value.item().contains_dot())
}
} => false,
}
}
}