refactor(syntax): change ModuleRecord::not_esm to has_module_syntax (#7579)

This commit is contained in:
Boshen committed 2024-12-02 09:32:57 +00:00
1 parent 18519dea33
commit f0e7acc68b
9 files changed
+21 -20

No files matched your search

+4 -4
View File
@@ -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,
@@ -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)
@@ -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
@@ -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
+2 -2
View File
@@ -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();
@@ -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
@@ -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();
@@ -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;
};
@@ -213,7 +214,7 @@ impl Rule for Namespace {
}
}
});
});
}
}
}
@@ -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;
}
@@ -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()));
}
}
@@ -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;
}
+1 -1
View File
@@ -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);
+3 -3
View File
@@ -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]]`
///
@@ -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),