Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: improve small file
  • Loading branch information
Dunqing committed Jul 19, 2024
commit f573c3463ef3b527458038f91f14dffe42faa89c
14 changes: 10 additions & 4 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,24 @@ impl<'a> SemanticBuilder<'a> {
if self.source_type.is_typescript_definition() {
let scope_id = self.scope.add_scope(None, AstNodeId::DUMMY, ScopeFlags::Top);
program.scope_id.set(Some(scope_id));
}

if self.source_text.len() < 4000 {
self.nodes.reserve(self.source_text.split_ascii_whitespace().count());
self.scope.reserve(program.body.len());
self.symbols.reserve(program.body.len(), program.body.len());
} else {
let mut collector = Collector::default();
collector.visit_program(program);
self.nodes.reserve(collector.node);
self.scope.reserve(collector.scope);
self.symbols.reserve(collector.symbol, collector.reference);
self.visit_program(program);
}

// Checking syntax error on module record requires scope information from the previous AST pass
if self.check_syntax_error {
checker::check_module_record(&self);
}
// Checking syntax error on module record requires scope information from the previous AST pass
if self.check_syntax_error {
checker::check_module_record(&self);
}

debug_assert_eq!(self.current_scope_depth, 0);
Expand Down