mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(semantic): make jsdoc building optional (turned off by default) (#3955)
This commit is contained in:
parent
31e4c3b33e
commit
f64ad4b7c2
6 changed files with 17 additions and 3 deletions
|
|
@ -269,6 +269,7 @@ impl Runtime {
|
|||
// The semantic model is not built at this stage.
|
||||
let semantic_builder = SemanticBuilder::new(source_text, source_type)
|
||||
.with_cfg(true)
|
||||
.with_build_jsdoc(true)
|
||||
.with_trivias(trivias)
|
||||
.with_check_syntax_error(check_syntax_errors)
|
||||
.build_module_record(path.to_path_buf(), program);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use crate::{
|
|||
reference::{Reference, ReferenceFlag, ReferenceId},
|
||||
scope::{ScopeFlags, ScopeId, ScopeTree},
|
||||
symbol::{SymbolFlags, SymbolId, SymbolTable},
|
||||
Semantic,
|
||||
JSDocFinder, Semantic,
|
||||
};
|
||||
|
||||
macro_rules! control_flow {
|
||||
|
|
@ -70,6 +70,7 @@ pub struct SemanticBuilder<'a> {
|
|||
|
||||
pub label_builder: LabelBuilder<'a>,
|
||||
|
||||
build_jsdoc: bool,
|
||||
jsdoc: JSDocBuilder<'a>,
|
||||
|
||||
check_syntax_error: bool,
|
||||
|
|
@ -109,6 +110,7 @@ impl<'a> SemanticBuilder<'a> {
|
|||
symbols: SymbolTable::default(),
|
||||
module_record: Arc::new(ModuleRecord::default()),
|
||||
label_builder: LabelBuilder::default(),
|
||||
build_jsdoc: false,
|
||||
jsdoc: JSDocBuilder::new(source_text, trivias),
|
||||
check_syntax_error: false,
|
||||
cfg: None,
|
||||
|
|
@ -130,6 +132,12 @@ impl<'a> SemanticBuilder<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_build_jsdoc(mut self, yes: bool) -> Self {
|
||||
self.build_jsdoc = yes;
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_cfg(mut self, cfg: bool) -> Self {
|
||||
self.cfg = if cfg { Some(ControlFlowGraphBuilder::default()) } else { None };
|
||||
|
|
@ -167,6 +175,8 @@ impl<'a> SemanticBuilder<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
let jsdoc = if self.build_jsdoc { self.jsdoc.build() } else { JSDocFinder::default() };
|
||||
|
||||
let semantic = Semantic {
|
||||
source_text: self.source_text,
|
||||
source_type: self.source_type,
|
||||
|
|
@ -176,7 +186,7 @@ impl<'a> SemanticBuilder<'a> {
|
|||
symbols: self.symbols,
|
||||
classes: self.class_table_builder.build(),
|
||||
module_record: Arc::clone(&self.module_record),
|
||||
jsdoc: self.jsdoc.build(),
|
||||
jsdoc,
|
||||
unused_labels: self.label_builder.unused_node_ids,
|
||||
cfg: self.cfg.map(ControlFlowGraphBuilder::build),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -247,6 +247,7 @@ mod test {
|
|||
let program = allocator.alloc(ret.program);
|
||||
let semantic = SemanticBuilder::new(source_text, source_type)
|
||||
.with_trivias(ret.trivias)
|
||||
.with_build_jsdoc(true)
|
||||
.build(program)
|
||||
.semantic;
|
||||
semantic
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use oxc_span::{GetSpan, Span};
|
|||
use super::parser::JSDoc;
|
||||
use crate::AstNode;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct JSDocFinder<'a> {
|
||||
/// JSDocs by Span
|
||||
attached: BTreeMap<Span, Vec<JSDoc<'a>>>,
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ mod test {
|
|||
let program = allocator.alloc(ret.program);
|
||||
let semantic = SemanticBuilder::new(source_text, source_type)
|
||||
.with_trivias(ret.trivias)
|
||||
.with_build_jsdoc(true)
|
||||
.build(program)
|
||||
.semantic;
|
||||
semantic
|
||||
|
|
|
|||
|
|
@ -195,6 +195,7 @@ mod test {
|
|||
let program = allocator.alloc(ret.program);
|
||||
let semantic = SemanticBuilder::new(source_text, source_type)
|
||||
.with_trivias(ret.trivias)
|
||||
.with_build_jsdoc(true)
|
||||
.build(program)
|
||||
.semantic;
|
||||
semantic
|
||||
|
|
|
|||
Loading…
Reference in a new issue