From 4e92d60fa90cead39481e3703d26e5d812f43bd1 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 28 Sep 2023 06:51:13 +0200 Subject: [PATCH 1/2] Deoptimize all parameters when losing track of a function (#5158) --- src/ast/nodes/shared/FunctionBase.ts | 7 ++++++- test/function/samples/mutate-via-parameter/_config.js | 9 +++++++++ test/function/samples/mutate-via-parameter/main.js | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/function/samples/mutate-via-parameter/_config.js create mode 100644 test/function/samples/mutate-via-parameter/main.js diff --git a/src/ast/nodes/shared/FunctionBase.ts b/src/ast/nodes/shared/FunctionBase.ts index dcfec0f1e..ec028d073 100644 --- a/src/ast/nodes/shared/FunctionBase.ts +++ b/src/ast/nodes/shared/FunctionBase.ts @@ -74,8 +74,13 @@ export default abstract class FunctionBase extends NodeBase { this.getObjectEntity().deoptimizePath(path); if (path.length === 1 && path[0] === UnknownKey) { // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track - // which means the return expression needs to be reassigned + // which means the return expression and parameters need to be reassigned this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH); + for (const parameterList of this.scope.parameters) { + for (const parameter of parameterList) { + parameter.deoptimizePath(UNKNOWN_PATH); + } + } } } diff --git a/test/function/samples/mutate-via-parameter/_config.js b/test/function/samples/mutate-via-parameter/_config.js new file mode 100644 index 000000000..e54a34f1e --- /dev/null +++ b/test/function/samples/mutate-via-parameter/_config.js @@ -0,0 +1,9 @@ +const assert = require('node:assert'); + +module.exports = defineTest({ + description: + 'respects variable mutations via unknown parameter values if we lose track of a function', + exports({ test }) { + assert.ok(test(state => (state.modified = true))); + } +}); diff --git a/test/function/samples/mutate-via-parameter/main.js b/test/function/samples/mutate-via-parameter/main.js new file mode 100644 index 000000000..d1bf83b4b --- /dev/null +++ b/test/function/samples/mutate-via-parameter/main.js @@ -0,0 +1,8 @@ +export function test(callback) { + const state = { + modified: false + }; + callback(state); + if (state.modified) return true; + return false; +} From a6448b99f725d457e35821b73a865b5c4d4c6a61 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 28 Sep 2023 07:00:23 +0200 Subject: [PATCH 2/2] 3.29.4 --- CHANGELOG.md | 14 +++++++++++++- browser/package.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f73bb3696..66bb96254 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,16 @@ -# rollup changelog + # rollup changelog + +## 3.29.4 + +_2023-09-28_ + +### Bug Fixes + +- Fix static analysis when an exported function uses callbacks (#5158) + +### Pull Requests + +- [#5158](https://github.com/rollup/rollup/pull/5158): Deoptimize all parameters when losing track of a function (@lukastaegert) ## 3.29.3 diff --git a/browser/package.json b/browser/package.json index ec004c5aa..401c1c9cf 100644 --- a/browser/package.json +++ b/browser/package.json @@ -1,6 +1,6 @@ { "name": "@rollup/browser", - "version": "3.29.3", + "version": "3.29.4", "description": "Next-generation ES module bundler browser build", "main": "dist/rollup.browser.js", "module": "dist/es/rollup.browser.js", diff --git a/package-lock.json b/package-lock.json index 3ceaafdf1..6836cf824 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rollup", - "version": "3.29.3", + "version": "3.29.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rollup", - "version": "3.29.3", + "version": "3.29.4", "license": "MIT", "bin": { "rollup": "dist/bin/rollup" diff --git a/package.json b/package.json index f37e2c5d1..4e65f67fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "3.29.3", + "version": "3.29.4", "description": "Next-generation ES module bundler", "main": "dist/rollup.js", "module": "dist/es/rollup.js",