Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down