Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions crates/oxc_linter/src/module_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type FxDashMap<K, V> = DashMap<K, V, FxBuildHasher>;
/// * <https://tc39.es/ecma262/#cyclic-module-record>
#[derive(Default)]
pub struct ModuleRecord {
/// This module has no import / export statements
pub not_esm: bool,
/// This module has ESM syntax: `import` and `export`.
pub has_module_syntax: bool,

/// Resolved absolute path to this module record
pub resolved_absolute_path: PathBuf,
Expand Down Expand Up @@ -99,7 +99,7 @@ impl fmt::Debug for ModuleRecord {
.unwrap_or_default();
let loaded_modules = format!("{{ {loaded_modules} }}");
f.debug_struct("ModuleRecord")
.field("not_esm", &self.not_esm)
.field("has_module_syntax", &self.has_module_syntax)
.field("resolved_absolute_path", &self.resolved_absolute_path)
.field("requested_modules", &self.requested_modules)
.field("loaded_modules", &loaded_modules)
Expand Down Expand Up @@ -434,7 +434,7 @@ impl ModuleRecord {
_semantic: &Semantic,
) -> Self {
Self {
not_esm: other.not_esm,
has_module_syntax: other.has_module_syntax,
resolved_absolute_path: path.to_path_buf(),
requested_modules: other
.requested_modules
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/import/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Rule for Default {
let Some(remote_module_record_ref) = module_record.loaded_modules.get(specifier) else {
continue;
};
if remote_module_record_ref.not_esm {
if !remote_module_record_ref.has_module_syntax {
continue;
}
if !remote_module_record_ref
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/import/named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Rule for Named {
continue;
};
let remote_module_record = remote_module_record_ref.value();
if remote_module_record.not_esm {
if !remote_module_record.has_module_syntax {
continue;
}
let import_span = import_name.span();
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Rule for Named {
continue;
};
let remote_module_record = remote_module_record_ref.value();
if remote_module_record.not_esm {
if !remote_module_record.has_module_syntax {
continue;
}
// Check remote bindings
Expand Down
13 changes: 7 additions & 6 deletions crates/oxc_linter/src/rules/import/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ impl Rule for Namespace {

fn run_once(&self, ctx: &LintContext<'_>) {
let module_record = ctx.module_record();
module_record.import_entries.iter().for_each(|entry| {

if !module_record.has_module_syntax {
return;
}

for entry in &module_record.import_entries {
let (source, module) = match &entry.import_name {
ImportImportName::NamespaceObject => {
let source = entry.module_request.name();
Expand Down Expand Up @@ -151,10 +156,6 @@ impl Rule for Namespace {
}
};

if module.not_esm {
return;
}

let Some(symbol_id) = ctx.scopes().get_root_binding(entry.local_name.name()) else {
return;
};
Expand Down Expand Up @@ -213,7 +214,7 @@ impl Rule for Namespace {
}
}
});
});
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/import/no_namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Rule for NoNamespace {
fn run_once(&self, ctx: &LintContext<'_>) {
let module_record = ctx.module_record();

if module_record.not_esm {
if !module_record.has_module_syntax {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/import/unambiguous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ declare_oxc_lint!(
/// <https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/unambiguous.md>
impl Rule for Unambiguous {
fn run_once(&self, ctx: &LintContext<'_>) {
if ctx.module_record().not_esm {
if !ctx.module_record().has_module_syntax {
ctx.diagnostic(unambiguous_diagnostic(Span::default()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/oxc/no_barrel_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Rule for NoBarrelFile {
fn run_once(&self, ctx: &LintContext<'_>) {
let module_record = ctx.module_record();

if module_record.not_esm {
if !module_record.has_module_syntax {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/module_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl<'a> ModuleRecordBuilder<'a> {
}

pub fn visit_module_declaration(&mut self, module_decl: &ModuleDeclaration<'a>) {
self.module_record.not_esm = false;
self.module_record.has_module_syntax = true;
match module_decl {
ModuleDeclaration::ImportDeclaration(import_decl) => {
self.visit_import_declaration(import_decl);
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_syntax/src/module_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use rustc_hash::FxHashMap;
/// * <https://tc39.es/ecma262/#cyclic-module-record>
#[derive(Debug)]
pub struct ModuleRecord<'a> {
/// This module has no import / export statements
pub not_esm: bool,
/// This module has ESM syntax: `import` and `export`.
pub has_module_syntax: bool,

/// `[[RequestedModules]]`
///
Expand Down Expand Up @@ -61,7 +61,7 @@ impl<'a> ModuleRecord<'a> {
/// Constructor
pub fn new(allocator: &'a Allocator) -> Self {
Self {
not_esm: true,
has_module_syntax: false,
requested_modules: FxHashMap::default(),
import_entries: Vec::new_in(allocator),
local_export_entries: Vec::new_in(allocator),
Expand Down