mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(linter/tree-shaking): detect the correct export symbol resolution (#5467)
fixes: #5455
This commit is contained in:
parent
cba93f52d0
commit
5187f384cb
3 changed files with 26 additions and 7 deletions
|
|
@ -8,10 +8,10 @@ use oxc_ast::{
|
|||
FormalParameter, Function, IdentifierReference, JSXAttribute, JSXAttributeItem,
|
||||
JSXAttributeValue, JSXChild, JSXElement, JSXElementName, JSXExpression,
|
||||
JSXExpressionContainer, JSXFragment, JSXMemberExpression, JSXMemberExpressionObject,
|
||||
JSXOpeningElement, LogicalExpression, MemberExpression, NewExpression, ObjectExpression,
|
||||
ObjectPropertyKind, ParenthesizedExpression, PrivateFieldExpression, Program, PropertyKey,
|
||||
SequenceExpression, SimpleAssignmentTarget, Statement, StaticMemberExpression, SwitchCase,
|
||||
ThisExpression, UnaryExpression, VariableDeclarator,
|
||||
JSXOpeningElement, LogicalExpression, MemberExpression, ModuleExportName, NewExpression,
|
||||
ObjectExpression, ObjectPropertyKind, ParenthesizedExpression, PrivateFieldExpression,
|
||||
Program, PropertyKey, SequenceExpression, SimpleAssignmentTarget, Statement,
|
||||
StaticMemberExpression, SwitchCase, ThisExpression, UnaryExpression, VariableDeclarator,
|
||||
},
|
||||
AstKind,
|
||||
};
|
||||
|
|
@ -195,9 +195,10 @@ impl<'a> ListenerMap for ExportSpecifier<'a> {
|
|||
let ctx = options.ctx;
|
||||
let symbol_table = ctx.symbols();
|
||||
if has_comment_about_side_effect_check(self.exported.span(), ctx) {
|
||||
let Some(name) = self.exported.identifier_name() else { return };
|
||||
let Some(symbol_id) = options.ctx.symbols().get_symbol_id_from_name(name.as_str())
|
||||
else {
|
||||
let ModuleExportName::IdentifierReference(ident) = &self.local else {
|
||||
return;
|
||||
};
|
||||
let Some(symbol_id) = get_symbol_id_of_variable(ident, ctx) else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -346,6 +346,11 @@ fn test() {
|
|||
r#"export {x as default} from "import""#,
|
||||
"export const /* tree-shaking no-side-effects-when-called */ x = function(){}",
|
||||
"export function /* tree-shaking no-side-effects-when-called */ x(){}",
|
||||
"
|
||||
{ let x = ext; }
|
||||
let x = () => {}
|
||||
export {/* tree-shaking no-side-effects-when-called */ x}
|
||||
",
|
||||
"const x = function(){}; export {/* tree-shaking no-side-effects-when-called */ x}",
|
||||
// ExpressionStatement
|
||||
"const x = 1",
|
||||
|
|
@ -632,6 +637,11 @@ fn test() {
|
|||
"export const /* tree-shaking no-side-effects-when-called */ x = ext",
|
||||
"export function /* tree-shaking no-side-effects-when-called */ x(){ext()}",
|
||||
"const x = ext; export {/* tree-shaking no-side-effects-when-called */ x}",
|
||||
"
|
||||
{ let x = () => {}; }
|
||||
let x = ext
|
||||
export {/* tree-shaking no-side-effects-when-called */ x}
|
||||
",
|
||||
// ExpressionStatement
|
||||
"ext()",
|
||||
// ForInStatement
|
||||
|
|
|
|||
|
|
@ -409,6 +409,14 @@ source: crates/oxc_linter/src/tester.rs
|
|||
· ───
|
||||
╰────
|
||||
|
||||
⚠ eslint-plugin-tree-shaking(no-side-effects-in-initialization): Cannot determine side-effects of calling global function `ext`
|
||||
╭─[no_side_effects_in_initialization.tsx:3:21]
|
||||
2 │ { let x = () => {}; }
|
||||
3 │ let x = ext
|
||||
· ───
|
||||
4 │ export {/* tree-shaking no-side-effects-when-called */ x}
|
||||
╰────
|
||||
|
||||
⚠ eslint-plugin-tree-shaking(no-side-effects-in-initialization): Cannot determine side-effects of calling global function `ext`
|
||||
╭─[no_side_effects_in_initialization.tsx:1:1]
|
||||
1 │ ext()
|
||||
|
|
|
|||
Loading…
Reference in a new issue