-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_transform
should probably use parse_program
instead of parse_module
#8713
Comments
Also just came to thought, I believe |
test_transform
should possibly use parse_program
instead of parse_module
test_transform
should probably use parse_program
instead of parse_module
#9623) **Description:** This PR addresses the issue described in #8713 **BREAKING CHANGE:** Will break unit tests that use `fold_module`/`visit_module`/`visit_mut_module` if the visitor is intended to work for both modules and scripts instead of using `fold_program`/`visit_program`/`visit_mut_program`. When creating visitors, you should use `fold_program`/`visit_program`/`visit_mut_program` if you simply want to visit the top-level node. When creating tests, the input source code will be parsed using `parse_program` by default. If you need to parse it as a `Module`, you can use `module: Some(true)` in `FixtureTestConfig` (or with `test!(module, ..)`), which will parse it as a `Program::Module`, or `Some(false)` for `Program::Script`. `None` will use `parse_program` (`parse_program` will auto-detect the underlying type).
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
):swc/crates/swc_ecma_transforms_testing/src/lib.rs
Line 175 in b0c00b9
To 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
The text was updated successfully, but these errors were encountered: