diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index d15604214..bd8cf4127 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -1658,7 +1658,7 @@ pub struct ImportDeclaration<'a> { pub specifiers: Vec<'a, ImportDeclarationSpecifier>, pub source: StringLiteral, pub assertions: Option>, // Some(vec![]) for empty assertion - pub import_kind: Option, // `import type { foo } from 'bar'` + pub import_kind: ImportOrExportKind, // `import type { foo } from 'bar'` } #[derive(Debug, PartialEq, Eq, Hash)] @@ -1732,13 +1732,13 @@ pub struct ExportNamedDeclaration<'a> { pub declaration: Option>, pub specifiers: Vec<'a, ExportSpecifier>, pub source: Option, - pub export_kind: Option, // `export type { foo }` + pub export_kind: ImportOrExportKind, // `export type { foo }` } impl<'a> ExportNamedDeclaration<'a> { #[must_use] pub fn is_typescript_syntax(&self) -> bool { - self.export_kind == Some(ImportOrExportKind::Type) + self.export_kind == ImportOrExportKind::Type || self.declaration.as_ref().map_or(false, Declaration::is_typescript_syntax) } } @@ -1760,7 +1760,7 @@ pub struct ExportAllDeclaration<'a> { pub exported: Option, pub source: StringLiteral, pub assertions: Option>, // Some(vec![]) for empty assertion - pub export_kind: Option, // `export type *` + pub export_kind: ImportOrExportKind, // `export type *` } #[derive(Debug, PartialEq, Eq, Hash)] diff --git a/crates/oxc_ast/src/ast_builder.rs b/crates/oxc_ast/src/ast_builder.rs index 85a3deb97..ba84c9057 100644 --- a/crates/oxc_ast/src/ast_builder.rs +++ b/crates/oxc_ast/src/ast_builder.rs @@ -793,7 +793,7 @@ impl<'a> AstBuilder<'a> { specifiers: Vec<'a, ImportDeclarationSpecifier>, source: StringLiteral, assertions: Option>, - import_kind: Option, + import_kind: ImportOrExportKind, ) -> Box<'a, ImportDeclaration<'a>> { self.alloc(ImportDeclaration { span, specifiers, source, assertions, import_kind }) } @@ -803,8 +803,8 @@ impl<'a> AstBuilder<'a> { span: Span, exported: Option, source: StringLiteral, - assertions: Option>, // Some(vec![]) for empty assertion - export_kind: Option, + assertions: Option>, + export_kind: ImportOrExportKind, ) -> Box<'a, ExportAllDeclaration<'a>> { self.alloc(ExportAllDeclaration { span, exported, source, assertions, export_kind }) } @@ -824,7 +824,7 @@ impl<'a> AstBuilder<'a> { declaration: Option>, specifiers: Vec<'a, ExportSpecifier>, source: Option, - export_kind: Option, // `export type { foo }` + export_kind: ImportOrExportKind, ) -> Box<'a, ExportNamedDeclaration<'a>> { self.alloc(ExportNamedDeclaration { span, declaration, specifiers, source, export_kind }) } diff --git a/crates/oxc_parser/src/js/module.rs b/crates/oxc_parser/src/js/module.rs index 6e90f0feb..17f1db15f 100644 --- a/crates/oxc_parser/src/js/module.rs +++ b/crates/oxc_parser/src/js/module.rs @@ -277,7 +277,7 @@ impl<'a> Parser<'a> { Some(declaration), self.ast.new_vec(), None, - None, + ImportOrExportKind::Value, )) } @@ -407,11 +407,10 @@ impl<'a> Parser<'a> { } } - fn parse_import_or_export_kind(&mut self) -> Option { + fn parse_import_or_export_kind(&mut self) -> ImportOrExportKind { if !self.ts_enabled() { - return None; + return ImportOrExportKind::Value; } - // import type { bar } from 'foo'; // import type * as React from 'react'; // import type ident from 'foo'; @@ -419,9 +418,9 @@ impl<'a> Parser<'a> { if matches!(self.peek_kind(), Kind::LCurly | Kind::Star | Kind::Ident) && self.eat(Kind::Type) { - return Some(ImportOrExportKind::Type); + ImportOrExportKind::Type + } else { + ImportOrExportKind::Value } - - Some(ImportOrExportKind::Value) } } diff --git a/crates/oxc_semantic/src/module_record/builder.rs b/crates/oxc_semantic/src/module_record/builder.rs index c53dba043..27d64521c 100644 --- a/crates/oxc_semantic/src/module_record/builder.rs +++ b/crates/oxc_semantic/src/module_record/builder.rs @@ -160,7 +160,7 @@ impl ModuleRecordBuilder { } fn visit_import_declaration(&mut self, decl: &ImportDeclaration) { - if decl.import_kind.map_or(false, |kind| kind.is_type()) { + if decl.import_kind.is_type() { return; } let module_request = NameSpan::new(decl.source.value.clone(), decl.source.span); @@ -242,7 +242,7 @@ impl ModuleRecordBuilder { } fn visit_export_named_declaration(&mut self, decl: &ExportNamedDeclaration) { - if decl.export_kind.map_or(false, |kind| kind.is_type()) { + if decl.export_kind.is_type() { return; } // ignore all TypeScript syntax as they overload