Closed levi-nz closed 1 month ago
Also just came to thought, I believe visit_program
(and others) will also not work in unit tests because a Module
is not a Program
, as far as I know. So to my understanding right now, only visit_module
/visit_mut_module
/fold_module
can be called from test_transform
, while visit_program
and visit_script
can never be called, due to the parsed code always being a Module
.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Describe the feature
The problem right now with
test_transform
is that, because it usesparse_module
to parse code internally, visitors that usevisit_script
/visit_mut_script
/fold_script
will not work because these functions are never called due to the parsed code being a module (thanks toapply_transform
): https://github.com/swc-project/swc/blob/b0c00b96f18c391bea89059130d08484e3ac3506/crates/swc_ecma_transforms_testing/src/lib.rs#L175To fix this, we could make
test_transform
useparse_program
instead, but this might introduce breaking changes. AProgram
can be either aModule
orScript
, but if we maketest_transform
useparse_program
it might break existing unit tests (1st or 3rd party) that usevisit_module
instead ofvisit_program
(or the other two functions). Some of the code related to this would also need to be changed, but that doesn't seem too big of an issue.Overall, making
test_transform
would make people's lives a bit easier when making visitors that use specific functions likevisit_script
if they know they will never need to use the program or module functions, but I'm curious what the maintainers think about this as I'm not sure if I'm right.Babel plugin or link to the feature description
No response
Additional context
No response