Skip to content

Commit

Permalink
Add export namespace declaration support
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleidawave committed Oct 5, 2024
1 parent 4f7802f commit 68a6250
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions checker/src/synthesis/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub(crate) fn synthesise_declaration<T: crate::ReadFromFS>(
| parser::declarations::export::Exportable::Function(_)
| parser::declarations::export::Exportable::EnumDeclaration(_)
| parser::declarations::export::Exportable::Interface(_)
| parser::declarations::export::Exportable::Namespace(_)
| parser::declarations::export::Exportable::TypeAlias(_) => {}
}
}
Expand Down
14 changes: 14 additions & 0 deletions parser/src/declarations/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub enum Exportable {
Interface(InterfaceDeclaration),
TypeAlias(TypeAlias),
EnumDeclaration(EnumDeclaration),
#[cfg(feature = "full-typescript")]
Namespace(crate::types::namespace::Namespace),
Parts(Vec<ImportExportPart<ExportDeclaration>>),
ImportAll {
r#as: Option<VariableIdentifier>,
Expand Down Expand Up @@ -226,6 +228,14 @@ impl ASTNode for ExportDeclaration {
position,
})
} else {
#[cfg(feature = "full-typescript")]
if reader.is_keyword("namespace") {
let namespace = crate::types::namespace::Namespace::from_reader(reader)?;
let position = start.union(namespace.get_position());

return Ok(Self::Item { exported: Exportable::Namespace(namespace), position });
}

todo!("{:?}", reader.get_current().get(..20))
// }
// Token(TSXToken::Keyword(kw), _) if kw.is_in_function_header() => {
Expand Down Expand Up @@ -279,6 +289,10 @@ impl ASTNode for ExportDeclaration {
Exportable::EnumDeclaration(enum_declaration) => {
enum_declaration.to_string_from_buffer(buf, options, local);
}
#[cfg(feature = "full-typescript")]
Exportable::Namespace(namespace) => {
namespace.to_string_from_buffer(buf, options, local);
}
Exportable::Parts(parts) => {
super::import_export_parts_to_string_from_buffer(
parts, buf, options, local,
Expand Down

0 comments on commit 68a6250

Please sign in to comment.