Skip to content

Commit

Permalink
Do not handle declarations in modules without side effects as TDZ (#5322
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lukastaegert authored Dec 30, 2023
1 parent e004d92 commit ba1c2db
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ast/nodes/Identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ export default class Identifier extends NodeBase implements PatternNode {
return (this.isTDZAccess = true);
}

if (!this.variable.initReached) {
// We ignore the case where the module is not yet executed because
// moduleSideEffects are false.
if (!this.variable.initReached && this.scope.context.module.isExecuted) {
// Either a const/let TDZ violation or
// var use before declaration was encountered.
return (this.isTDZAccess = true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = defineTest({
description: 'properly tree-shakes nested function calls when moduleSideEffects are disabled',
options: {
treeshake: {
moduleSideEffects: false
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const main = () => {
};

export { main };
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const doNothing = () => {};

const alpha = () => {
doNothing();
};

export { alpha };
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { alpha } from "./alpha";

const main = () => {
alpha();
};

export { main };

0 comments on commit ba1c2db

Please sign in to comment.