Closed colinaaa closed 2 months ago
This is expected, but I think minifeir should panic instead
I managed to fix this by adding a report_usage
for JSXElementName
to the UsageAnalyzer
:
#[cfg_attr(feature = "debug", tracing::instrument(skip_all))]
fn visit_jsx_element_name(&mut self, n: &JSXElementName) {
let ctx = Ctx {
in_pat_of_var_decl: false,
in_pat_of_param: false,
in_catch_param: false,
var_decl_kind_of_pat: None,
in_pat_of_var_decl_with_init: false,
..self.ctx
};
n.visit_children_with(&mut *self.with_ctx(ctx));
if let JSXElementName::Ident(i) = n {
self.with_ctx(ctx).report_usage(i);
}
}
Would do you think about fixing it instead of panic?
JSX is not a standard, so I think it should panic instead of handling them.
I found that we should support this due to Evaluator
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 bug
We are using the SWC minifier with Rust API. But the output is incorrect with JSX is preserved.
If a variable is only being used as a
JSXElementName
, it will be mistakenly removed by SWC minifier.Input code
Config
Playground link (or link to the minimal reproduction)
https://play.swc.rs/?version=1.6.7&code=H4sIAAAAAAAAA0vOzysuUXDLz1ewVUguSk0sSQWyNTStuVIrCvKLShTSSvOSSzLz8xQcCwo0NBWquRSAoCi1pLQoT0EDzAEBm7LM1HI7OBcsBDJTHyFmo49QAzS%2BlgsAf4CxUHoAAAA%3D&config=H4sIAAAAAAAAA32UO3LjMAyG%2B5zCozrFjostcoDt9gwcWgRlZilCQ4CONRnffaFnPDboTsIHEMQPEN9vh0PzSW3zcfiWT%2FkZbCbI%2B79YaExsr2JpeByA2hwGbt43yjQhzgVmy20BDdvcAU9BQMdfx%2BMa0EREAjF7GwlWWx9S8ON9yhb7IQPRnU2scmTpITGtCd%2FvUcYvxX5CjGDTC2IsmZAYOsiKV4sx2oHAXKyOe9ErEGoZJlgYnBkyDipPLnDAJFI8UwfWmRbdg1gLCxlaDhfQ4iSZxCWS8irUwal03dzkBwwXG4tlJRCuc0Pkts%2FsjIHY%2BKKJsLCKAgvUpQ3eZOCSlXyfGNIW9SjNPwApP1qiZHtNn9nByyhV2RaoHh2Sl2nl8TlYJlurMUEngpoQvNbJSRjIHLSbZnClhUnXtk4rMlBwYMB7GRMllr4Ct2ct5%2FTC0StAmmvVChZg9gdY4dNjeIH%2FSJG8DFfFo7d8rlMa%2BxPGFwl64DO6Fw7SCcY6zrIgrkOdl%2BRAJgOc6lJoBs8LQMaf0cR5Uz7QQfYKy4mmi3j6WRGrw21fwL1NXdw7syzht9Wh6dGVGa7bfervspR%2FNz9O2%2F7dL94E%2BrtFzklv%2FwFbOOlnKQYAAA%3D%3D
SWC Info output
No response
Expected behavior
The
const Foo
is preserved in the output:Actual behavior
The
const Foo
is removed. Result inFoo is not defined
error at runtime.Version
1.6.7
Additional context
No response