|
1 | 1 | use std::{borrow::Cow, sync::Arc};
|
2 | 2 |
|
3 |
| -use rspack_cacheable::cacheable; |
4 | 3 | use rspack_error::{Result, error};
|
5 | 4 | use rspack_hook::define_hook;
|
6 | 5 | use rspack_loader_runner::{Loader, Scheme, get_scheme};
|
7 | 6 | use rspack_paths::Utf8PathBuf;
|
8 | 7 | use rspack_util::MergeFrom;
|
9 | 8 | use sugar_path::SugarPath;
|
10 |
| -use swc_core::common::Span; |
11 | 9 | use winnow::prelude::*;
|
12 | 10 |
|
13 | 11 | use crate::{
|
14 | 12 | AssetInlineGeneratorOptions, AssetResourceGeneratorOptions, BoxLoader, BoxModule,
|
15 | 13 | CompilerOptions, Context, CssAutoGeneratorOptions, CssAutoParserOptions,
|
16 |
| - CssModuleGeneratorOptions, CssModuleParserOptions, Dependency, DependencyCategory, |
17 |
| - DependencyRange, FactoryMeta, FuncUseCtx, GeneratorOptions, ModuleExt, ModuleFactory, |
18 |
| - ModuleFactoryCreateData, ModuleFactoryResult, ModuleIdentifier, ModuleLayer, ModuleRuleEffect, |
19 |
| - ModuleRuleEnforce, ModuleRuleUse, ModuleRuleUseLoader, ModuleType, NormalModule, |
20 |
| - ParserAndGenerator, ParserOptions, RawModule, Resolve, ResolveArgs, |
21 |
| - ResolveOptionsWithDependencyType, ResolveResult, Resolver, ResolverFactory, ResourceData, |
22 |
| - ResourceParsedData, RunnerContext, SharedPluginDriver, diagnostics::EmptyDependency, |
23 |
| - module_rules_matcher, parse_resource, resolve, stringify_loaders_and_resource, |
| 14 | + CssModuleGeneratorOptions, CssModuleParserOptions, Dependency, DependencyCategory, FactoryMeta, |
| 15 | + FuncUseCtx, GeneratorOptions, ModuleExt, ModuleFactory, ModuleFactoryCreateData, |
| 16 | + ModuleFactoryResult, ModuleIdentifier, ModuleLayer, ModuleRuleEffect, ModuleRuleEnforce, |
| 17 | + ModuleRuleUse, ModuleRuleUseLoader, ModuleType, NormalModule, ParserAndGenerator, ParserOptions, |
| 18 | + RawModule, Resolve, ResolveArgs, ResolveOptionsWithDependencyType, ResolveResult, Resolver, |
| 19 | + ResolverFactory, ResourceData, ResourceParsedData, RunnerContext, SharedPluginDriver, |
| 20 | + diagnostics::EmptyDependency, module_rules_matcher, parse_resource, resolve, |
| 21 | + stringify_loaders_and_resource, |
24 | 22 | };
|
25 | 23 |
|
26 | 24 | define_hook!(NormalModuleFactoryBeforeResolve: SeriesBail(data: &mut ModuleFactoryCreateData) -> bool,tracing=false);
|
@@ -133,7 +131,7 @@ impl NormalModuleFactory {
|
133 | 131 | .expect("should be module dependency");
|
134 | 132 | let dependency_type = *dependency.dependency_type();
|
135 | 133 | let dependency_category = *dependency.category();
|
136 |
| - let dependency_source_span = dependency.source_span(); |
| 134 | + let dependency_range = dependency.range(); |
137 | 135 | let dependency_optional = dependency.get_optional();
|
138 | 136 |
|
139 | 137 | let importer = data.issuer_identifier;
|
@@ -218,8 +216,7 @@ impl NormalModuleFactory {
|
218 | 216 | let second_char = request.next();
|
219 | 217 |
|
220 | 218 | if first_char.is_none() {
|
221 |
| - let span = dependency.source_span().unwrap_or_default(); |
222 |
| - return Err(EmptyDependency::new(DependencyRange::new(span.start, span.end)).into()); |
| 219 | + return Err(EmptyDependency::new(dependency.range()).into()); |
223 | 220 | }
|
224 | 221 |
|
225 | 222 | // See: https://webpack.js.org/concepts/loaders/#inline
|
@@ -314,7 +311,7 @@ impl NormalModuleFactory {
|
314 | 311 | specifier: &resource,
|
315 | 312 | dependency_type: &dependency_type,
|
316 | 313 | dependency_category: &dependency_category,
|
317 |
| - span: dependency_source_span, |
| 314 | + span: dependency_range, |
318 | 315 | resolve_options: data.resolve_options.clone(),
|
319 | 316 | resolve_to_context: false,
|
320 | 317 | optional: dependency_optional,
|
@@ -884,32 +881,6 @@ async fn resolve_each(
|
884 | 881 | .ok_or_else(|| error!("Unable to resolve loader {}", l.loader))
|
885 | 882 | }
|
886 | 883 |
|
887 |
| -/// Using `u32` instead of `usize` to reduce memory usage, |
888 |
| -/// `u32` is 4 bytes on 64bit machine, comparing to `usize` which is 8 bytes. |
889 |
| -/// ## Warning |
890 |
| -/// [ErrorSpan] start from zero, and `Span` of `swc` start from one. see https://swc-css.netlify.app/?code=eJzLzC3ILypRSFRIK8rPVVAvSS0u0csqVgcAZaoIKg |
891 |
| -#[cacheable] |
892 |
| -#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, Default, PartialOrd, Ord)] |
893 |
| -pub struct ErrorSpan { |
894 |
| - pub start: u32, |
895 |
| - pub end: u32, |
896 |
| -} |
897 |
| - |
898 |
| -impl ErrorSpan { |
899 |
| - pub fn new(start: u32, end: u32) -> Self { |
900 |
| - Self { start, end } |
901 |
| - } |
902 |
| -} |
903 |
| - |
904 |
| -impl From<Span> for ErrorSpan { |
905 |
| - fn from(span: Span) -> Self { |
906 |
| - Self { |
907 |
| - start: span.lo.0.saturating_sub(1), |
908 |
| - end: span.hi.0.saturating_sub(1), |
909 |
| - } |
910 |
| - } |
911 |
| -} |
912 |
| - |
913 | 884 | #[derive(Debug)]
|
914 | 885 | pub struct NormalModuleCreateData {
|
915 | 886 | pub raw_request: String,
|
|
0 commit comments