Skip to content

Commit 3ead329

Browse files
committed
feat(semantic): put jsdoc behind linter feature, remove runtime flag
The compiler pipeline do not need jsdocs.
1 parent 71af1aa commit 3ead329

File tree

9 files changed

+23
-24
lines changed

9 files changed

+23
-24
lines changed

crates/oxc/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ let SemanticBuilderReturn {
101101
errors: semantic_errors,
102102
} = SemanticBuilder::new()
103103
.with_check_syntax_error(true) // Enable extra syntax error checking
104-
.with_build_jsdoc(true) // Enable JSDoc parsing
105104
.with_cfg(true) // Build a Control Flow Graph
106105
.build(&program); // Produce the `Semantic`
107106

crates/oxc_linter/src/service/runtime.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,6 @@ impl Runtime {
993993
let semantic_ret = SemanticBuilder::new()
994994
.with_cfg(true)
995995
.with_scope_tree_child_ids(true)
996-
.with_build_jsdoc(true)
997996
.with_check_syntax_error(check_syntax_errors)
998997
.build(allocator.alloc(ret.program));
999998

crates/oxc_semantic/src/builder.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ use oxc_syntax::{
2424
symbol::{SymbolFlags, SymbolId},
2525
};
2626

27+
#[cfg(feature = "linter")]
28+
use crate::jsdoc::JSDocBuilder;
2729
use crate::{
28-
JSDocFinder, Semantic,
30+
Semantic,
2931
binder::{Binder, ModuleInstanceState},
3032
checker,
3133
class::ClassTableBuilder,
3234
diagnostics::redeclaration,
33-
jsdoc::JSDocBuilder,
3435
label::UnusedLabels,
3536
node::AstNodes,
3637
scoping::{Bindings, Scoping},
@@ -89,7 +90,7 @@ pub struct SemanticBuilder<'a> {
8990
pub(crate) unresolved_references: UnresolvedReferencesStack<'a>,
9091

9192
unused_labels: UnusedLabels<'a>,
92-
build_jsdoc: bool,
93+
#[cfg(feature = "linter")]
9394
jsdoc: JSDocBuilder<'a>,
9495
stats: Option<Stats>,
9596
excess_capacity: f64,
@@ -143,7 +144,7 @@ impl<'a> SemanticBuilder<'a> {
143144
scoping,
144145
unresolved_references: UnresolvedReferencesStack::new(),
145146
unused_labels: UnusedLabels::default(),
146-
build_jsdoc: false,
147+
#[cfg(feature = "linter")]
147148
jsdoc: JSDocBuilder::default(),
148149
stats: None,
149150
excess_capacity: 0.0,
@@ -171,13 +172,6 @@ impl<'a> SemanticBuilder<'a> {
171172
self
172173
}
173174

174-
/// Enable/disable JSDoc parsing.
175-
#[must_use]
176-
pub fn with_build_jsdoc(mut self, yes: bool) -> Self {
177-
self.build_jsdoc = yes;
178-
self
179-
}
180-
181175
/// Enable or disable building a [`ControlFlowGraph`].
182176
///
183177
/// [`ControlFlowGraph`]: oxc_cfg::ControlFlowGraph
@@ -236,7 +230,8 @@ impl<'a> SemanticBuilder<'a> {
236230
pub fn build(mut self, program: &'a Program<'a>) -> SemanticBuilderReturn<'a> {
237231
self.source_text = program.source_text;
238232
self.source_type = program.source_type;
239-
if self.build_jsdoc {
233+
#[cfg(feature = "linter")]
234+
{
240235
self.jsdoc = JSDocBuilder::new(self.source_text, &program.comments);
241236
}
242237

@@ -290,7 +285,8 @@ impl<'a> SemanticBuilder<'a> {
290285
self.unresolved_references.into_root().into_iter().map(|(k, v)| (k.as_str(), v)),
291286
);
292287

293-
let jsdoc = if self.build_jsdoc { self.jsdoc.build() } else { JSDocFinder::default() };
288+
#[cfg(feature = "linter")]
289+
let jsdoc = self.jsdoc.build();
294290

295291
#[cfg(debug_assertions)]
296292
self.unused_labels.assert_empty();
@@ -303,6 +299,7 @@ impl<'a> SemanticBuilder<'a> {
303299
nodes: self.nodes,
304300
scoping: self.scoping,
305301
classes: self.class_table_builder.build(),
302+
#[cfg(feature = "linter")]
306303
jsdoc,
307304
unused_labels: self.unused_labels.labels,
308305
#[cfg(feature = "cfg")]
@@ -327,8 +324,12 @@ impl<'a> SemanticBuilder<'a> {
327324
}
328325

329326
fn create_ast_node(&mut self, kind: AstKind<'a>) {
327+
#[cfg(not(feature = "linter"))]
328+
let flags = self.current_node_flags;
329+
#[cfg(feature = "linter")]
330330
let mut flags = self.current_node_flags;
331-
if self.build_jsdoc && self.jsdoc.retrieve_attached_jsdoc(&kind) {
331+
#[cfg(feature = "linter")]
332+
if self.jsdoc.retrieve_attached_jsdoc(&kind) {
332333
flags |= NodeFlags::JSDoc;
333334
}
334335

crates/oxc_semantic/src/jsdoc/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ mod test {
207207
) -> Semantic<'a> {
208208
let source_type = source_type.unwrap_or_default();
209209
let ret = Parser::new(allocator, source_text, source_type).parse();
210-
SemanticBuilder::new().with_build_jsdoc(true).build(allocator.alloc(ret.program)).semantic
210+
SemanticBuilder::new().build(allocator.alloc(ret.program)).semantic
211211
}
212212

213213
fn get_jsdocs<'a>(

crates/oxc_semantic/src/jsdoc/parser/jsdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ mod test {
4545
fn build_semantic<'a>(allocator: &'a Allocator, source_text: &'a str) -> Semantic<'a> {
4646
let source_type = SourceType::default();
4747
let ret = Parser::new(allocator, source_text, source_type).parse();
48-
SemanticBuilder::new().with_build_jsdoc(true).build(allocator.alloc(ret.program)).semantic
48+
SemanticBuilder::new().build(allocator.alloc(ret.program)).semantic
4949
}
5050

5151
#[test]

crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ mod test {
194194
fn build_semantic<'a>(allocator: &'a Allocator, source_text: &'a str) -> Semantic<'a> {
195195
let source_type = SourceType::default();
196196
let ret = Parser::new(allocator, source_text, source_type).parse();
197-
SemanticBuilder::new().with_build_jsdoc(true).build(allocator.alloc(ret.program)).semantic
197+
SemanticBuilder::new().build(allocator.alloc(ret.program)).semantic
198198
}
199199

200200
#[test]

crates/oxc_semantic/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ mod checker;
3232
mod class;
3333
mod diagnostics;
3434
mod is_global_reference;
35+
#[cfg(feature = "linter")]
3536
mod jsdoc;
3637
mod label;
3738
mod node;
@@ -43,6 +44,7 @@ mod unresolved_stack;
4344
pub use ast_types_bitset::AstTypesBitset;
4445
pub use builder::{SemanticBuilder, SemanticBuilderReturn};
4546
pub use is_global_reference::IsGlobalReference;
47+
#[cfg(feature = "linter")]
4648
pub use jsdoc::{JSDoc, JSDocFinder, JSDocTag};
4749
pub use node::{AstNode, AstNodes};
4850
pub use scoping::Scoping;
@@ -80,6 +82,7 @@ pub struct Semantic<'a> {
8082
irregular_whitespaces: Box<[Span]>,
8183

8284
/// Parsed JSDoc comments.
85+
#[cfg(feature = "linter")]
8386
jsdoc: JSDocFinder<'a>,
8487

8588
unused_labels: Vec<NodeId>,
@@ -162,6 +165,7 @@ impl<'a> Semantic<'a> {
162165
/// Parsed [`JSDoc`] comments.
163166
///
164167
/// Will be empty if JSDoc parsing is disabled.
168+
#[cfg(feature = "linter")]
165169
pub fn jsdoc(&self) -> &JSDocFinder<'a> {
166170
&self.jsdoc
167171
}

tasks/benchmark/benches/linter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ fn bench_linter(criterion: &mut Criterion) {
3232
let parser_ret = Parser::new(&allocator, source_text, source_type).parse();
3333
let path = Path::new("");
3434
let semantic_ret = SemanticBuilder::new()
35-
.with_build_jsdoc(true)
3635
.with_scope_tree_child_ids(true)
3736
.with_cfg(true)
3837
.build(&parser_ret.program);

tasks/benchmark/benches/semantic.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ fn bench_semantic(criterion: &mut Criterion) {
2929
// We return `errors` to be dropped outside of the measured section, as usually
3030
// code would have no errors. One of our benchmarks `cal.com.tsx` has a lot of errors,
3131
// but that's atypical, so don't want to include it in benchmark time.
32-
let ret = SemanticBuilder::new()
33-
.with_build_jsdoc(true)
34-
.with_check_syntax_error(true)
35-
.build(&program);
32+
let ret = SemanticBuilder::new().with_check_syntax_error(true).build(&program);
3633
let ret = black_box(ret);
3734
ret.errors
3835
});

0 commit comments

Comments
 (0)