Open shulaoda opened 4 months ago
Thanks for filing this issue! The dependency struts are indeed chaotic and a messed-up.
First, for the status-quo, we do over-used the word Span
. To me, Span
is more likely to be a specific word using to describe the internal data of a compiler(SWC in this case) and if this was to used in other cases, it will definitely mess up the definition.
Second, I like the idea of using DependencyRange
to describe the 0-based
range and the idea of DependencyLocation
. On top of this, I would love them to be derived from Span
(exposing fn to_loc
and fn to_range
out). This would not likely to cause any mistakes and avoid adding to much methods to module traits.
If the current impl cannot meet your needs, you may create your own RspackSpan
to iron out these problems.
This issue is related to work #7336 , and I can try to address it.
In addition, it is worth mentioning that some dependencies related to CSS
do not come from Span
, but from simple Range
. Perhaps we can also try using Trait From
.
This issue is related to work #7336 , and I can try to address it.
In addition, it is worth mentioning that some dependencies related to
CSS
do not come fromSpan
, but from simpleRange
. Perhaps we can also try using TraitFrom
.
Then I guess a custom RspackSpan
would be enough to describe them all. We can implement trait From
to all of the raw Span
s provided by compilers.
The work on DependencyLocation
is a great job, but we can improve some types to make the semantics more strict, for example: BasicEvaluatedExpression::with_range
The type of BasicEvaluatedExpression::with_range
is https://github.com/web-infra-dev/rspack/blob/0969538afd86f58c6cc64eeb855c8985bdaf2429/crates/rspack_plugin_javascript/src/utils/eval/mod.rs#L126
it accepts two u32
to create an RealDependencyLocation
(0-based), but the usage of it is accepting start and end from Span
(1-based), start is changed to 0-based by real_lo
, but end didn't, this is actually different with the semantics of RealDependencyLocation
(start and end are both 0-based)
so for this case we can improve the type to something like this, to strictly enforce the semantics of RealDependencyLocation
: start and end are both 0-based
pub fn with_range(location: impl IntoDependencyLocation) -> Self
impl IntoDependencyLocation for Span {
// change to 0-based
}
The basic idea is avoid using (u32, u32)
directly as much as possible, all RealDependencyLocation is transformed from another type (swc::Span
, css_module_lexer::Range
, etc)
This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
What problem does this feature solve?
Among many dependencies, they mark the scope of the dependency as
span
,range
, orstart&end
. This behavior is very chaotic in Dependency.https://github.com/web-infra-dev/rspack/blob/f37741c316c30e6234cfc504efbabea53a26df75/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_header_dependency.rs#L11-L16
https://github.com/web-infra-dev/rspack/blob/f37741c316c30e6234cfc504efbabea53a26df75/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs#L43-L54
https://github.com/web-infra-dev/rspack/blob/f37741c316c30e6234cfc504efbabea53a26df75/crates/rspack_core/src/dependency/cached_const_dependency.rs#L7-L12
This
0-based
range is based on the1-based
SWC'sSpan
conversion, and I think we should name itrange
which used inwebpack
to avoid ambiguity.In addition, I think it may be better to name the types of
loc
andrange
asDependencyLocation
andDependencyRange
.What's your opinion? @h-a-n-a
What does the proposed API of configuration look like?