diff --git a/crates/oxc_parser/src/lib.rs b/crates/oxc_parser/src/lib.rs index e10e84355b328..7dbeddc73eb45 100644 --- a/crates/oxc_parser/src/lib.rs +++ b/crates/oxc_parser/src/lib.rs @@ -418,7 +418,7 @@ impl<'a> ParserImpl<'a> { state: ParserState::new(), ctx: Self::default_context(source_type, options), ast: AstBuilder::new(allocator), - module_record_builder: ModuleRecordBuilder::new(allocator), + module_record_builder: ModuleRecordBuilder::new(allocator, source_type), is_ts: source_type.is_typescript(), } } @@ -466,13 +466,11 @@ impl<'a> ParserImpl<'a> { } let (module_record, module_record_errors) = self.module_record_builder.build(); if errors.len() != 1 { - errors.reserve(self.lexer.errors.len() + self.errors.len()); + errors + .reserve(self.lexer.errors.len() + self.errors.len() + module_record_errors.len()); errors.extend(self.lexer.errors); errors.extend(self.errors); - // Skip checking for exports in TypeScript { - if !self.source_type.is_typescript() { - errors.extend(module_record_errors); - } + errors.extend(module_record_errors); } let irregular_whitespaces = self.lexer.trivia_builder.irregular_whitespaces.into_boxed_slice(); diff --git a/crates/oxc_parser/src/module_record.rs b/crates/oxc_parser/src/module_record.rs index 78fd9fb0928a1..b08ac53f1e48b 100644 --- a/crates/oxc_parser/src/module_record.rs +++ b/crates/oxc_parser/src/module_record.rs @@ -9,15 +9,17 @@ use crate::diagnostics; pub struct ModuleRecordBuilder<'a> { allocator: &'a Allocator, + source_type: SourceType, module_record: ModuleRecord<'a>, export_entries: Vec<'a, ExportEntry<'a>>, exported_bindings_duplicated: Vec<'a, NameSpan<'a>>, } impl<'a> ModuleRecordBuilder<'a> { - pub fn new(allocator: &'a Allocator) -> Self { + pub fn new(allocator: &'a Allocator, source_type: SourceType) -> Self { Self { allocator, + source_type, module_record: ModuleRecord::new(allocator), export_entries: Vec::new_in(allocator), exported_bindings_duplicated: Vec::new_in(allocator), @@ -35,6 +37,11 @@ impl<'a> ModuleRecordBuilder<'a> { pub fn errors(&self) -> std::vec::Vec { let mut errors = vec![]; + // Skip checking for exports in TypeScript + if self.source_type.is_typescript() { + return errors; + } + let module_record = &self.module_record; // It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries. diff --git a/tasks/track_memory_allocations/allocs_parser.snap b/tasks/track_memory_allocations/allocs_parser.snap index b722757854cbf..4b031738a5bfa 100644 --- a/tasks/track_memory_allocations/allocs_parser.snap +++ b/tasks/track_memory_allocations/allocs_parser.snap @@ -2,7 +2,7 @@ File | File size || Sys allocs | Sys reallocs | ------------------------------------------------------------------------------------------------------------------------------------------- checker.ts | 2.92 MB || 9672 | 21 || 267681 | 22847 -cal.com.tsx | 1.06 MB || 2211 | 62 || 138162 | 13699 +cal.com.tsx | 1.06 MB || 1083 | 49 || 138162 | 13699 RadixUIAdoptionSection.jsx | 2.52 kB || 1 | 0 || 365 | 66