Skip to content

Commit f0e7acc

Browse files
committed
refactor(syntax): change ModuleRecord::not_esm to has_module_syntax (#7579)
1 parent 18519de commit f0e7acc

9 files changed

Lines changed: 21 additions & 20 deletions

File tree

crates/oxc_linter/src/module_record.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type FxDashMap<K, V> = DashMap<K, V, FxBuildHasher>;
2424
/// * <https://tc39.es/ecma262/#cyclic-module-record>
2525
#[derive(Default)]
2626
pub struct ModuleRecord {
27-
/// This module has no import / export statements
28-
pub not_esm: bool,
27+
/// This module has ESM syntax: `import` and `export`.
28+
pub has_module_syntax: bool,
2929

3030
/// Resolved absolute path to this module record
3131
pub resolved_absolute_path: PathBuf,
@@ -99,7 +99,7 @@ impl fmt::Debug for ModuleRecord {
9999
.unwrap_or_default();
100100
let loaded_modules = format!("{{ {loaded_modules} }}");
101101
f.debug_struct("ModuleRecord")
102-
.field("not_esm", &self.not_esm)
102+
.field("has_module_syntax", &self.has_module_syntax)
103103
.field("resolved_absolute_path", &self.resolved_absolute_path)
104104
.field("requested_modules", &self.requested_modules)
105105
.field("loaded_modules", &loaded_modules)
@@ -434,7 +434,7 @@ impl ModuleRecord {
434434
_semantic: &Semantic,
435435
) -> Self {
436436
Self {
437-
not_esm: other.not_esm,
437+
has_module_syntax: other.has_module_syntax,
438438
resolved_absolute_path: path.to_path_buf(),
439439
requested_modules: other
440440
.requested_modules

crates/oxc_linter/src/rules/import/default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Rule for Default {
6262
let Some(remote_module_record_ref) = module_record.loaded_modules.get(specifier) else {
6363
continue;
6464
};
65-
if remote_module_record_ref.not_esm {
65+
if !remote_module_record_ref.has_module_syntax {
6666
continue;
6767
}
6868
if !remote_module_record_ref

crates/oxc_linter/src/rules/import/named.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Rule for Named {
102102
continue;
103103
};
104104
let remote_module_record = remote_module_record_ref.value();
105-
if remote_module_record.not_esm {
105+
if !remote_module_record.has_module_syntax {
106106
continue;
107107
}
108108
let import_span = import_name.span();
@@ -140,7 +140,7 @@ impl Rule for Named {
140140
continue;
141141
};
142142
let remote_module_record = remote_module_record_ref.value();
143-
if remote_module_record.not_esm {
143+
if !remote_module_record.has_module_syntax {
144144
continue;
145145
}
146146
// Check remote bindings

crates/oxc_linter/src/rules/import/namespace.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ impl Rule for Namespace {
118118

119119
fn run_once(&self, ctx: &LintContext<'_>) {
120120
let module_record = ctx.module_record();
121-
module_record.import_entries.iter().for_each(|entry| {
121+
122+
if !module_record.has_module_syntax {
123+
return;
124+
}
125+
126+
for entry in &module_record.import_entries {
122127
let (source, module) = match &entry.import_name {
123128
ImportImportName::NamespaceObject => {
124129
let source = entry.module_request.name();
@@ -151,10 +156,6 @@ impl Rule for Namespace {
151156
}
152157
};
153158

154-
if module.not_esm {
155-
return;
156-
}
157-
158159
let Some(symbol_id) = ctx.scopes().get_root_binding(entry.local_name.name()) else {
159160
return;
160161
};
@@ -213,7 +214,7 @@ impl Rule for Namespace {
213214
}
214215
}
215216
});
216-
});
217+
}
217218
}
218219
}
219220

crates/oxc_linter/src/rules/import/no_namespace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Rule for NoNamespace {
9999
fn run_once(&self, ctx: &LintContext<'_>) {
100100
let module_record = ctx.module_record();
101101

102-
if module_record.not_esm {
102+
if !module_record.has_module_syntax {
103103
return;
104104
}
105105

crates/oxc_linter/src/rules/import/unambiguous.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ declare_oxc_lint!(
4848
/// <https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/unambiguous.md>
4949
impl Rule for Unambiguous {
5050
fn run_once(&self, ctx: &LintContext<'_>) {
51-
if ctx.module_record().not_esm {
51+
if !ctx.module_record().has_module_syntax {
5252
ctx.diagnostic(unambiguous_diagnostic(Span::default()));
5353
}
5454
}

crates/oxc_linter/src/rules/oxc/no_barrel_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Rule for NoBarrelFile {
7272
fn run_once(&self, ctx: &LintContext<'_>) {
7373
let module_record = ctx.module_record();
7474

75-
if module_record.not_esm {
75+
if !module_record.has_module_syntax {
7676
return;
7777
}
7878

crates/oxc_parser/src/module_record.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'a> ModuleRecordBuilder<'a> {
173173
}
174174

175175
pub fn visit_module_declaration(&mut self, module_decl: &ModuleDeclaration<'a>) {
176-
self.module_record.not_esm = false;
176+
self.module_record.has_module_syntax = true;
177177
match module_decl {
178178
ModuleDeclaration::ImportDeclaration(import_decl) => {
179179
self.visit_import_declaration(import_decl);

crates/oxc_syntax/src/module_record.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use rustc_hash::FxHashMap;
1414
/// * <https://tc39.es/ecma262/#cyclic-module-record>
1515
#[derive(Debug)]
1616
pub struct ModuleRecord<'a> {
17-
/// This module has no import / export statements
18-
pub not_esm: bool,
17+
/// This module has ESM syntax: `import` and `export`.
18+
pub has_module_syntax: bool,
1919

2020
/// `[[RequestedModules]]`
2121
///
@@ -61,7 +61,7 @@ impl<'a> ModuleRecord<'a> {
6161
/// Constructor
6262
pub fn new(allocator: &'a Allocator) -> Self {
6363
Self {
64-
not_esm: true,
64+
has_module_syntax: false,
6565
requested_modules: FxHashMap::default(),
6666
import_entries: Vec::new_in(allocator),
6767
local_export_entries: Vec::new_in(allocator),

0 commit comments

Comments
 (0)