You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
currrently Rspack will do double parse for all file processed by builtin:swc-loader, the reason Rspack do double parse is caused by swc transform will make the origin span invalid which cause it's bad for following dependency generation
before transformed by builtin:swc-loader
import{b}from'./b';consta=b;// now AstNode('b') span is 37-38
after transformed by builtin:swc-loader
import{b}from'./b';vara=b;// the span in ast is still 37-38 but after codegen the valid span is actually 34-35
span can be fixed by srcmapbuf generated by codegen
so the span in ASTNode is not valid after transformation, but we can fix the span use src_map generated by emitter, the src_map contains the right mapping from span in ast to span after codegen
Except fix the span, we need pass ast from swc_loader to JavaScriptParserAndGenerator.
We can use additional_data: anymap::Map<dyn CloneAny + Send + Sync> to pass ast.
Actually, we can't get mapping that from source span to transformed span using src_map_buf.
The src_map_buf is used for generate source_map, It only maps a portion of the span's start or end positions to the corresponding source line and column numbers.
We need other way.
span is not valid after transformation
currrently Rspack will do double parse for all file processed by builtin:swc-loader, the reason Rspack do double parse is caused by swc transform will make the origin span invalid which cause it's bad for following dependency generation
builtin:swc-loader
builtin:swc-loader
span can be fixed by srcmapbuf generated by codegen
so the span in ASTNode is not valid after transformation, but we can fix the span use src_map generated by emitter, the src_map contains the right mapping from span in ast to span after codegen
rspack/crates/rspack_plugin_javascript/src/ast/stringify.rs
Lines 79 to 84 in 9112e35
we fix ast span using
visit_mut_span
in SpanFixerVisitorast invalidation
we should mark the ast dirty | invalid, if the code is modified by following loader
reuse span in module.build
if the AST contains the valid span, then parse can reuse ast passing from builtin:swc-loader, no need to do double parse in module.build
rspack/crates/rspack_core/src/normal_module.rs
Line 542 in 9112e35
The text was updated successfully, but these errors were encountered: