diff --git a/crates/rspack_core/src/dependency/dependency_location.rs b/crates/rspack_core/src/dependency/dependency_location.rs new file mode 100644 index 00000000000..0addb9fb117 --- /dev/null +++ b/crates/rspack_core/src/dependency/dependency_location.rs @@ -0,0 +1,111 @@ +use std::{fmt, sync::Arc}; + +use derivative::Derivative; + +#[derive(Derivative)] +#[derivative(Debug, Clone)] +pub struct RealDependencyLocation { + pub end: u32, + pub start: u32, + #[derivative(Debug = "ignore")] + source: Option>, +} + +impl RealDependencyLocation { + pub fn new(start: u32, end: u32) -> Self { + RealDependencyLocation { + end, + start, + source: None, + } + } + + pub fn with_source(mut self, source: Arc) -> Self { + self.source = Some(source); + self + } +} + +impl From for RealDependencyLocation { + fn from(span: swc_core::common::Span) -> Self { + Self { + start: span.lo.0.saturating_sub(1), + end: span.hi.0.saturating_sub(1), + source: None, + } + } +} + +impl fmt::Display for RealDependencyLocation { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let source = &self.source.clone().expect("missing sourcemap"); + let (start, end) = source.look_up_range_pos(self.start, self.end); + + if start.line == end.line { + if start.column == end.column { + return write!(f, "{}:{}", start.line, start.column); + } + + return write!(f, "{}:{}-{}", start.line, start.column, end.column); + } + + write!( + f, + "{}:{}-{}:{}", + start.line, start.column, end.line, end.column + ) + } +} + +#[derive(Debug, Clone)] +pub struct SyntheticDependencyName { + pub name: String, +} + +impl SyntheticDependencyName { + pub fn new(name: &str) -> Self { + SyntheticDependencyName { + name: name.to_string(), + } + } +} + +impl fmt::Display for SyntheticDependencyName { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.name) + } +} + +// #[derive(Debug, Clone)] +// pub enum DependencyLocation { +// Real(RealDependencyLocation), +// Synthetic(SyntheticDependencyName), +// } + +#[derive(Debug, Clone, Copy)] +pub struct SourcePosition { + pub line: usize, + pub column: usize, +} + +pub trait SourceLocation: Send + Sync { + fn look_up_range_pos(&self, start: u32, end: u32) -> (SourcePosition, SourcePosition); +} + +impl SourceLocation for swc_core::common::SourceMap { + fn look_up_range_pos(&self, start: u32, end: u32) -> (SourcePosition, SourcePosition) { + let lo = self.lookup_char_pos(swc_core::common::BytePos(start + 1)); + let hi = self.lookup_char_pos(swc_core::common::BytePos(end + 1)); + + ( + SourcePosition { + line: lo.line, + column: lo.col_display, + }, + SourcePosition { + line: hi.line, + column: hi.col_display, + }, + ) + } +} diff --git a/crates/rspack_core/src/dependency/dependency_range.rs b/crates/rspack_core/src/dependency/dependency_range.rs deleted file mode 100644 index 9896a4c3041..00000000000 --- a/crates/rspack_core/src/dependency/dependency_range.rs +++ /dev/null @@ -1,97 +0,0 @@ -use std::sync::Arc; - -use derivative::Derivative; - -#[derive(Derivative)] -#[derivative(Debug, Clone)] -pub struct DependencyRange { - pub end: u32, - pub start: u32, - #[derivative(Debug = "ignore")] - source: Option>, -} - -impl DependencyRange { - pub fn new(start: u32, end: u32) -> Self { - DependencyRange { - end, - start, - source: None, - } - } - - pub fn with_source(mut self, source: Arc) -> Self { - self.source = Some(source); - self - } -} - -impl From for DependencyRange { - fn from(span: swc_core::common::Span) -> Self { - Self { - start: span.lo.0.saturating_sub(1), - end: span.hi.0.saturating_sub(1), - source: None, - } - } -} - -#[derive(Debug, Clone, Copy)] -pub struct SourcePosition { - pub line: usize, - pub column: usize, -} - -#[derive(Debug, Clone, Copy)] -pub struct DependencyLocation { - pub end: SourcePosition, - pub start: SourcePosition, -} - -pub trait SourceLocation: Send + Sync { - fn look_up_range_pos(&self, start: u32, end: u32) -> DependencyLocation; -} - -impl SourceLocation for swc_core::common::SourceMap { - fn look_up_range_pos(&self, start: u32, end: u32) -> DependencyLocation { - let lo = self.lookup_char_pos(swc_core::common::BytePos(start + 1)); - let hi = self.lookup_char_pos(swc_core::common::BytePos(end + 1)); - - DependencyLocation { - start: SourcePosition { - line: lo.line, - column: lo.col_display, - }, - end: SourcePosition { - line: hi.line, - column: hi.col_display, - }, - } - } -} - -impl DependencyRange { - pub fn to_loc(&self) -> Option { - if let Some(source) = &self.source { - let loc = source.look_up_range_pos(self.start, self.end); - - if loc.start.line == loc.end.line { - if loc.start.column == loc.end.column { - return Some(format!("{}:{}", loc.start.line, loc.start.column)); - } - - return Some(format!( - "{}:{}-{}", - loc.start.line, loc.start.column, loc.end.column - )); - } - - return Some(format!( - "{}:{}-{}:{}", - loc.start.line, loc.start.column, loc.end.line, loc.end.column - )); - } - - None - } -} diff --git a/crates/rspack_core/src/dependency/mod.rs b/crates/rspack_core/src/dependency/mod.rs index de706fceaca..19a28ae74a4 100644 --- a/crates/rspack_core/src/dependency/mod.rs +++ b/crates/rspack_core/src/dependency/mod.rs @@ -4,8 +4,8 @@ mod context_dependency; mod context_element_dependency; mod dependency_category; mod dependency_id; +mod dependency_location; mod dependency_macro; -mod dependency_range; mod dependency_template; mod dependency_trait; mod dependency_type; @@ -25,7 +25,7 @@ pub use context_dependency::{AsContextDependency, ContextDependency}; pub use context_element_dependency::ContextElementDependency; pub use dependency_category::DependencyCategory; pub use dependency_id::*; -pub use dependency_range::*; +pub use dependency_location::*; pub use dependency_template::*; pub use dependency_trait::*; pub use dependency_type::DependencyType; diff --git a/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_full_require_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_full_require_dependency.rs index 4ed6907c87f..d4a02654caa 100644 --- a/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_full_require_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_full_require_dependency.rs @@ -1,6 +1,7 @@ use rspack_core::{ - module_id, property_access, to_normal_comment, Compilation, DependencyRange, ExportsType, - ExtendedReferencedExport, ModuleGraph, RuntimeGlobals, RuntimeSpec, UsedName, + module_id, property_access, to_normal_comment, Compilation, ExportsType, + ExtendedReferencedExport, ModuleGraph, RealDependencyLocation, RuntimeGlobals, RuntimeSpec, + UsedName, }; use rspack_core::{AsContextDependency, Dependency, DependencyCategory}; use rspack_core::{DependencyId, DependencyTemplate}; @@ -13,7 +14,7 @@ pub struct CommonJsFullRequireDependency { id: DependencyId, request: String, names: Vec, - range: DependencyRange, + range: RealDependencyLocation, is_call: bool, optional: bool, asi_safe: bool, @@ -23,7 +24,7 @@ impl CommonJsFullRequireDependency { pub fn new( request: String, names: Vec, - range: DependencyRange, + range: RealDependencyLocation, is_call: bool, optional: bool, asi_safe: bool, @@ -54,7 +55,7 @@ impl Dependency for CommonJsFullRequireDependency { } fn loc(&self) -> Option { - self.range.to_loc() + Some(self.range.to_string()) } fn span(&self) -> Option { diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs index 71ce9a712e3..6a19944c37d 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs @@ -3,8 +3,8 @@ use rspack_collections::{Identifier, IdentifierSet}; use rspack_core::rspack_sources::ReplacementEnforce; use rspack_core::{ property_access, AsContextDependency, AsModuleDependency, Compilation, Dependency, - DependencyRange, DependencyType, ExportNameOrSpec, ExportsOfExportsSpec, ExportsSpec, - HarmonyExportInitFragment, ModuleGraph, RuntimeGlobals, RuntimeSpec, UsedName, DEFAULT_EXPORT, + DependencyType, ExportNameOrSpec, ExportsOfExportsSpec, ExportsSpec, HarmonyExportInitFragment, + ModuleGraph, RealDependencyLocation, RuntimeGlobals, RuntimeSpec, UsedName, DEFAULT_EXPORT, }; use rspack_core::{DependencyId, DependencyTemplate}; use rspack_core::{TemplateContext, TemplateReplaceSource}; @@ -20,13 +20,13 @@ pub enum DeclarationId { #[derive(Debug, Clone)] pub struct DeclarationInfo { - range: DependencyRange, + range: RealDependencyLocation, prefix: String, suffix: String, } impl DeclarationInfo { - pub fn new(range: DependencyRange, prefix: String, suffix: String) -> Self { + pub fn new(range: RealDependencyLocation, prefix: String, suffix: String) -> Self { Self { range, prefix, @@ -38,15 +38,15 @@ impl DeclarationInfo { #[derive(Debug, Clone)] pub struct HarmonyExportExpressionDependency { id: DependencyId, - range: DependencyRange, - range_stmt: DependencyRange, + range: RealDependencyLocation, + range_stmt: RealDependencyLocation, declaration: Option, } impl HarmonyExportExpressionDependency { pub fn new( - range: DependencyRange, - range_stmt: DependencyRange, + range: RealDependencyLocation, + range_stmt: RealDependencyLocation, declaration: Option, ) -> Self { Self { @@ -68,7 +68,7 @@ impl Dependency for HarmonyExportExpressionDependency { } fn loc(&self) -> Option { - self.range.to_loc() + Some(self.range.to_string()) } fn get_exports(&self, _mg: &ModuleGraph) -> Option { diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_header_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_header_dependency.rs index 66c6331549b..1f768538f14 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_header_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_header_dependency.rs @@ -1,6 +1,7 @@ use rspack_core::{ - AsContextDependency, AsModuleDependency, Compilation, Dependency, DependencyId, DependencyRange, - DependencyTemplate, DependencyType, RuntimeSpec, TemplateContext, TemplateReplaceSource, + AsContextDependency, AsModuleDependency, Compilation, Dependency, DependencyId, + DependencyTemplate, DependencyType, RealDependencyLocation, RuntimeSpec, TemplateContext, + TemplateReplaceSource, }; // Remove `export` label. @@ -9,12 +10,12 @@ use rspack_core::{ #[derive(Debug, Clone)] pub struct HarmonyExportHeaderDependency { id: DependencyId, - range: DependencyRange, - range_decl: Option, + range: RealDependencyLocation, + range_decl: Option, } impl HarmonyExportHeaderDependency { - pub fn new(range: DependencyRange, range_decl: Option) -> Self { + pub fn new(range: RealDependencyLocation, range_decl: Option) -> Self { Self { range, range_decl, @@ -29,7 +30,7 @@ impl Dependency for HarmonyExportHeaderDependency { } fn loc(&self) -> Option { - self.range.to_loc() + Some(self.range.to_string()) } fn dependency_type(&self) -> &DependencyType { diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs index f3128159d6c..bb63a3d5a88 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs @@ -7,13 +7,13 @@ use rspack_core::{ create_exports_object_referenced, create_no_exports_referenced, filter_runtime, get_exports_type, process_export_info, property_access, property_name, string_of_used_name, AsContextDependency, Compilation, ConditionalInitFragment, ConnectionState, Dependency, DependencyCategory, - DependencyCondition, DependencyId, DependencyRange, DependencyTemplate, DependencyType, - ErrorSpan, ExportInfo, ExportInfoProvided, ExportNameOrSpec, ExportPresenceMode, ExportSpec, - ExportsInfo, ExportsOfExportsSpec, ExportsSpec, ExportsType, ExtendedReferencedExport, + DependencyCondition, DependencyId, DependencyTemplate, DependencyType, ErrorSpan, ExportInfo, + ExportInfoProvided, ExportNameOrSpec, ExportPresenceMode, ExportSpec, ExportsInfo, + ExportsOfExportsSpec, ExportsSpec, ExportsType, ExtendedReferencedExport, HarmonyExportInitFragment, ImportAttributes, InitFragmentExt, InitFragmentKey, InitFragmentStage, JavascriptParserOptions, ModuleDependency, ModuleGraph, ModuleIdentifier, NormalInitFragment, - RuntimeCondition, RuntimeGlobals, RuntimeSpec, Template, TemplateContext, TemplateReplaceSource, - UsageState, UsedName, + RealDependencyLocation, RuntimeCondition, RuntimeGlobals, RuntimeSpec, Template, TemplateContext, + TemplateReplaceSource, UsageState, UsedName, }; use rspack_error::{ miette::{MietteDiagnostic, Severity}, @@ -41,7 +41,7 @@ pub struct HarmonyExportImportedSpecifierDependency { pub export_all: bool, pub source_order: i32, pub other_star_exports: Option>, - range: DependencyRange, + range: RealDependencyLocation, attributes: Option, resource_identifier: String, export_presence_mode: ExportPresenceMode, @@ -56,7 +56,7 @@ impl HarmonyExportImportedSpecifierDependency { name: Option, export_all: bool, other_star_exports: Option>, - range: DependencyRange, + range: RealDependencyLocation, export_presence_mode: ExportPresenceMode, attributes: Option, ) -> Self { @@ -1051,7 +1051,7 @@ impl Dependency for HarmonyExportImportedSpecifierDependency { } fn loc(&self) -> Option { - self.range.to_loc() + Some(self.range.to_string()) } fn span(&self) -> Option { diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs index d6dfa483360..a5cf9760e8d 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs @@ -1,8 +1,8 @@ use rspack_collections::IdentifierSet; use rspack_core::{ AsContextDependency, AsModuleDependency, Compilation, Dependency, DependencyCategory, - DependencyId, DependencyRange, DependencyTemplate, DependencyType, ExportNameOrSpec, - ExportsOfExportsSpec, ExportsSpec, HarmonyExportInitFragment, ModuleGraph, RuntimeSpec, + DependencyId, DependencyTemplate, DependencyType, ExportNameOrSpec, ExportsOfExportsSpec, + ExportsSpec, HarmonyExportInitFragment, ModuleGraph, RealDependencyLocation, RuntimeSpec, TemplateContext, TemplateReplaceSource, UsedName, }; use swc_core::ecma::atoms::Atom; @@ -11,13 +11,13 @@ use swc_core::ecma::atoms::Atom; #[derive(Debug, Clone)] pub struct HarmonyExportSpecifierDependency { id: DependencyId, - range: DependencyRange, + range: RealDependencyLocation, pub name: Atom, pub value: Atom, // id } impl HarmonyExportSpecifierDependency { - pub fn new(name: Atom, value: Atom, range: DependencyRange) -> Self { + pub fn new(name: Atom, value: Atom, range: RealDependencyLocation) -> Self { Self { name, value, @@ -33,7 +33,7 @@ impl Dependency for HarmonyExportSpecifierDependency { } fn loc(&self) -> Option { - self.range.to_loc() + Some(self.range.to_string()) } fn category(&self) -> &DependencyCategory { diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs index 5e03fe6d947..3f5717bccbb 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs @@ -3,7 +3,7 @@ use std::sync::LazyLock; use rspack_collections::{IdentifierDashMap, IdentifierMap, IdentifierSet}; use rspack_core::Compilation; -use rspack_core::DependencyRange; +use rspack_core::RealDependencyLocation; use rspack_core::{ filter_runtime, import_statement, merge_runtime, AsContextDependency, AwaitDependenciesInitFragment, BuildMetaDefaultObject, ConditionalInitFragment, ConnectionState, @@ -46,8 +46,8 @@ pub struct HarmonyImportSideEffectDependency { pub request: Atom, pub source_order: i32, pub id: DependencyId, - pub range: DependencyRange, - pub range_src: DependencyRange, + pub range: RealDependencyLocation, + pub range_src: RealDependencyLocation, pub dependency_type: DependencyType, pub export_all: bool, attributes: Option, @@ -59,8 +59,8 @@ impl HarmonyImportSideEffectDependency { pub fn new( request: Atom, source_order: i32, - range: DependencyRange, - range_src: DependencyRange, + range: RealDependencyLocation, + range_src: RealDependencyLocation, dependency_type: DependencyType, export_all: bool, attributes: Option, @@ -376,7 +376,7 @@ impl Dependency for HarmonyImportSideEffectDependency { } fn loc(&self) -> Option { - self.range.to_loc() + Some(self.range.to_string()) } fn span(&self) -> Option { diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs index bdedab7882b..424c4e18d8b 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs @@ -2,10 +2,10 @@ use rspack_collections::IdentifierSet; use rspack_core::{ create_exports_object_referenced, export_from_import, get_dependency_used_by_exports_condition, get_exports_type, AsContextDependency, Compilation, ConnectionState, Dependency, - DependencyCategory, DependencyCondition, DependencyId, DependencyRange, DependencyTemplate, - DependencyType, ExportPresenceMode, ExportsType, ExtendedReferencedExport, ImportAttributes, - JavascriptParserOptions, ModuleDependency, ModuleGraph, ReferencedExport, RuntimeSpec, - TemplateContext, TemplateReplaceSource, UsedByExports, + DependencyCategory, DependencyCondition, DependencyId, DependencyTemplate, DependencyType, + ExportPresenceMode, ExportsType, ExtendedReferencedExport, ImportAttributes, + JavascriptParserOptions, ModuleDependency, ModuleGraph, RealDependencyLocation, ReferencedExport, + RuntimeSpec, TemplateContext, TemplateReplaceSource, UsedByExports, }; use rspack_core::{property_access, ModuleReferenceOptions}; use rspack_error::Diagnostic; @@ -23,7 +23,7 @@ pub struct HarmonyImportSpecifierDependency { source_order: i32, shorthand: bool, asi_safe: bool, - range: DependencyRange, + range: RealDependencyLocation, ids: Vec, call: bool, direct_import: bool, @@ -43,7 +43,7 @@ impl HarmonyImportSpecifierDependency { source_order: i32, shorthand: bool, asi_safe: bool, - range: DependencyRange, + range: RealDependencyLocation, ids: Vec, call: bool, direct_import: bool, @@ -225,7 +225,7 @@ impl Dependency for HarmonyImportSpecifierDependency { } fn loc(&self) -> Option { - self.range.to_loc() + Some(self.range.to_string()) } fn span(&self) -> Option { diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/common_js_imports_parse_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/common_js_imports_parse_plugin.rs index 406073fbd81..9f520d365fb 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/common_js_imports_parse_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/common_js_imports_parse_plugin.rs @@ -1,5 +1,5 @@ use rspack_core::{ - ConstDependency, ContextMode, DependencyCategory, DependencyRange, ErrorSpan, SpanExt, + ConstDependency, ContextMode, DependencyCategory, ErrorSpan, RealDependencyLocation, SpanExt, }; use rspack_core::{ContextNameSpaceObject, ContextOptions}; use rspack_error::Severity; @@ -92,7 +92,7 @@ impl CommonJsImportsParserPlugin { let (members, first_arg) = extract_require_call_info(parser, mem_expr)?; - let range: DependencyRange = mem_expr.span.into(); + let range: RealDependencyLocation = mem_expr.span.into(); let param = parser.evaluate_expression(&first_arg.expr); param.is_string().then(|| { CommonJsFullRequireDependency::new( diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/harmony_export_dependency_parser_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/harmony_export_dependency_parser_plugin.rs index 682bedd7d63..2a80f53ff41 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/harmony_export_dependency_parser_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/harmony_export_dependency_parser_plugin.rs @@ -1,4 +1,6 @@ -use rspack_core::{BoxDependency, ConstDependency, DependencyRange, DependencyType, SpanExt}; +use rspack_core::{ + BoxDependency, ConstDependency, DependencyType, RealDependencyLocation, SpanExt, +}; use swc_core::atoms::Atom; use swc_core::common::Spanned; @@ -22,7 +24,7 @@ pub struct HarmonyExportDependencyParserPlugin; impl JavascriptParserPlugin for HarmonyExportDependencyParserPlugin { fn export(&self, parser: &mut JavascriptParser, statement: ExportLocal) -> Option { - let range: DependencyRange = statement.span().into(); + let range: RealDependencyLocation = statement.span().into(); let dep = HarmonyExportHeaderDependency::new( range.with_source(parser.source_map.clone()), statement.declaration_span().map(|span| span.into()), @@ -39,7 +41,7 @@ impl JavascriptParserPlugin for HarmonyExportDependencyParserPlugin { ) -> Option { parser.last_harmony_import_order += 1; let span = statement.span(); - let range: DependencyRange = span.into(); + let range: RealDependencyLocation = span.into(); let clean_dep = ConstDependency::new(span.real_lo(), span.real_hi(), "".into(), None); parser.presentational_dependencies.push(Box::new(clean_dep)); let side_effect_dep = HarmonyImportSideEffectDependency::new( @@ -73,7 +75,7 @@ impl JavascriptParserPlugin for HarmonyExportDependencyParserPlugin { .insert(export_name.clone()); let dep = if let Some(settings) = parser.get_tag_data(local_id, HARMONY_SPECIFIER_TAG) { let settings = HarmonySpecifierData::downcast(settings); - let range: DependencyRange = statement.span().into(); + let range: RealDependencyLocation = statement.span().into(); Box::new(HarmonyExportImportedSpecifierDependency::new( settings.source, settings.source_order, @@ -88,7 +90,7 @@ impl JavascriptParserPlugin for HarmonyExportDependencyParserPlugin { settings.attributes, )) as BoxDependency } else { - let range: DependencyRange = statement.span().into(); + let range: RealDependencyLocation = statement.span().into(); Box::new(HarmonyExportSpecifierDependency::new( export_name.clone(), local_id.clone(), @@ -116,7 +118,7 @@ impl JavascriptParserPlugin for HarmonyExportDependencyParserPlugin { } else { Some(parser.build_info.all_star_exports.clone()) }; - let range: DependencyRange = statement.span().into(); + let range: RealDependencyLocation = statement.span().into(); let dep = HarmonyExportImportedSpecifierDependency::new( source.clone(), parser.last_harmony_import_order, @@ -146,9 +148,9 @@ impl JavascriptParserPlugin for HarmonyExportDependencyParserPlugin { let expr_span = expr.span(); let statement_span = statement.span(); let dep: HarmonyExportExpressionDependency = HarmonyExportExpressionDependency::new( - DependencyRange::new(expr_span.real_lo(), expr_span.real_hi()) + RealDependencyLocation::new(expr_span.real_lo(), expr_span.real_hi()) .with_source(parser.source_map.clone()), - DependencyRange::new(statement_span.real_lo(), statement_span.real_hi()), + RealDependencyLocation::new(statement_span.real_lo(), statement_span.real_hi()), match expr { ExportDefaultExpression::FnDecl(f) => { let start = f.span().real_lo(); @@ -158,7 +160,7 @@ impl JavascriptParserPlugin for HarmonyExportDependencyParserPlugin { f.function.body.span().real_lo() }; Some(DeclarationId::Func(DeclarationInfo::new( - DependencyRange::new(start, end), + RealDependencyLocation::new(start, end), format!( "{}function{} ", if f.function.is_async { "async " } else { "" }, diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/harmony_import_dependency_parser_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/harmony_import_dependency_parser_plugin.rs index b52bc4cdfcd..d9a3278a21f 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/harmony_import_dependency_parser_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/harmony_import_dependency_parser_plugin.rs @@ -1,5 +1,5 @@ use rspack_core::{ - ConstDependency, Dependency, DependencyRange, DependencyType, ImportAttributes, SpanExt, + ConstDependency, Dependency, DependencyType, ImportAttributes, RealDependencyLocation, SpanExt, }; use swc_core::atoms::Atom; use swc_core::common::{Span, Spanned}; @@ -70,7 +70,7 @@ impl JavascriptParserPlugin for HarmonyImportDependencyParserPlugin { source: &str, ) -> Option { parser.last_harmony_import_order += 1; - let range: DependencyRange = import_decl.span.into(); + let range: RealDependencyLocation = import_decl.span.into(); let attributes = import_decl.with.as_ref().map(|obj| get_attributes(obj)); let dependency = HarmonyImportSideEffectDependency::new( source.into(), @@ -134,7 +134,7 @@ impl JavascriptParserPlugin for HarmonyImportDependencyParserPlugin { .definitions_db .expect_get_tag_info(parser.current_tag_info?); let settings = HarmonySpecifierData::downcast(tag_info.data.clone()?); - let range: DependencyRange = ident.span.into(); + let range: RealDependencyLocation = ident.span.into(); let dep = HarmonyImportSpecifierDependency::new( settings.source, settings.name, @@ -201,7 +201,7 @@ impl JavascriptParserPlugin for HarmonyImportDependencyParserPlugin { let mut ids = settings.ids; ids.extend(non_optional_members.iter().cloned()); let direct_import = members.is_empty(); - let range: DependencyRange = span.into(); + let range: RealDependencyLocation = span.into(); let dep = HarmonyImportSpecifierDependency::new( settings.source, settings.name, @@ -265,7 +265,7 @@ impl JavascriptParserPlugin for HarmonyImportDependencyParserPlugin { }; let mut ids = settings.ids; ids.extend(non_optional_members.iter().cloned()); - let range: DependencyRange = span.into(); + let range: RealDependencyLocation = span.into(); let dep = HarmonyImportSpecifierDependency::new( settings.source, settings.name,