Skip to content

Commit 85ffcc1

Browse files
committed
Merge branch 'master' of https://github.com/rollup/rollup into sync-ecb6b0a4
2 parents cd17fee + ecb6b0a commit 85ffcc1

File tree

9 files changed

+79
-11
lines changed

9 files changed

+79
-11
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# rollup changelog
22

3+
## 4.9.6
4+
5+
_2024-01-21_
6+
7+
### Bug Fixes
8+
9+
- Detect side effects when an element that was pushed into an array is modified via the array (#5352)
10+
11+
### Pull Requests
12+
13+
- [#5337](https://github.com/rollup/rollup/pull/5337): Generate AST transformers from config (@lukastaegert)
14+
- [#5340](https://github.com/rollup/rollup/pull/5340): Also type-check d.ts files (@lukastaegert)
15+
- [#5348](https://github.com/rollup/rollup/pull/5348): chore(deps): lock file maintenance minor/patch updates (@renovate[bot])
16+
- [#5351](https://github.com/rollup/rollup/pull/5351): chore(deps): update dependency vite to v5.0.12 [security] (@renovate[bot])
17+
- [#5352](https://github.com/rollup/rollup/pull/5352): Track mutations of elements pushed into arrays (@lukastaegert)
18+
319
## 4.9.5
420

521
_2024-01-12_

browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rollup/browser",
3-
"version": "4.9.5",
3+
"version": "4.9.6",
44
"description": "Next-generation ES module bundler browser build",
55
"main": "dist/rollup.browser.js",
66
"module": "dist/es/rollup.browser.js",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rollup",
3-
"version": "4.9.5",
3+
"version": "4.9.6",
44
"description": "Next-generation ES module bundler",
55
"main": "dist/rollup.js",
66
"module": "dist/es/rollup.js",

rollup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default async function (
8989
addCliEntry(),
9090
esmDynamicImport(),
9191
!command.configTest && collectLicenses(),
92-
!command.configTest && copyNodeTypes()
92+
copyNodeTypes()
9393
],
9494
strictDeprecations: true,
9595
treeshake

src/ast/nodes/shared/ArrayPrototype.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const NEW_ARRAY_PROPERTIES: ObjectProperty[] = [
1919
const METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_BOOLEAN: [ExpressionEntity] = [
2020
new Method({
2121
callsArgs: [0],
22+
mutatesArgs: false,
2223
mutatesSelfAsArray: 'deopt-only',
2324
returns: null,
2425
returnsPrimitive: UNKNOWN_LITERAL_BOOLEAN
@@ -28,6 +29,7 @@ const METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_BOOLEAN: [ExpressionEntity] = [
2829
const METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NUMBER: [ExpressionEntity] = [
2930
new Method({
3031
callsArgs: [0],
32+
mutatesArgs: false,
3133
mutatesSelfAsArray: 'deopt-only',
3234
returns: null,
3335
returnsPrimitive: UNKNOWN_LITERAL_NUMBER
@@ -37,6 +39,7 @@ const METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NUMBER: [ExpressionEntity] = [
3739
const METHOD_MUTATES_SELF_RETURNS_NEW_ARRAY: [ExpressionEntity] = [
3840
new Method({
3941
callsArgs: null,
42+
mutatesArgs: false,
4043
mutatesSelfAsArray: true,
4144
returns: () => new ObjectEntity(NEW_ARRAY_PROPERTIES, ARRAY_PROTOTYPE),
4245
returnsPrimitive: null
@@ -46,6 +49,7 @@ const METHOD_MUTATES_SELF_RETURNS_NEW_ARRAY: [ExpressionEntity] = [
4649
const METHOD_DEOPTS_SELF_RETURNS_NEW_ARRAY: [ExpressionEntity] = [
4750
new Method({
4851
callsArgs: null,
52+
mutatesArgs: false,
4953
mutatesSelfAsArray: 'deopt-only',
5054
returns: () => new ObjectEntity(NEW_ARRAY_PROPERTIES, ARRAY_PROTOTYPE),
5155
returnsPrimitive: null
@@ -55,15 +59,17 @@ const METHOD_DEOPTS_SELF_RETURNS_NEW_ARRAY: [ExpressionEntity] = [
5559
const METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NEW_ARRAY: [ExpressionEntity] = [
5660
new Method({
5761
callsArgs: [0],
62+
mutatesArgs: false,
5863
mutatesSelfAsArray: 'deopt-only',
5964
returns: () => new ObjectEntity(NEW_ARRAY_PROPERTIES, ARRAY_PROTOTYPE),
6065
returnsPrimitive: null
6166
})
6267
];
6368

64-
const METHOD_MUTATES_SELF_RETURNS_NUMBER: [ExpressionEntity] = [
69+
const METHOD_MUTATES_SELF_AND_ARGS_RETURNS_NUMBER: [ExpressionEntity] = [
6570
new Method({
6671
callsArgs: null,
72+
mutatesArgs: true,
6773
mutatesSelfAsArray: true,
6874
returns: null,
6975
returnsPrimitive: UNKNOWN_LITERAL_NUMBER
@@ -73,6 +79,7 @@ const METHOD_MUTATES_SELF_RETURNS_NUMBER: [ExpressionEntity] = [
7379
const METHOD_MUTATES_SELF_RETURNS_UNKNOWN: [ExpressionEntity] = [
7480
new Method({
7581
callsArgs: null,
82+
mutatesArgs: false,
7683
mutatesSelfAsArray: true,
7784
returns: null,
7885
returnsPrimitive: UNKNOWN_EXPRESSION
@@ -82,6 +89,7 @@ const METHOD_MUTATES_SELF_RETURNS_UNKNOWN: [ExpressionEntity] = [
8289
const METHOD_DEOPTS_SELF_RETURNS_UNKNOWN: [ExpressionEntity] = [
8390
new Method({
8491
callsArgs: null,
92+
mutatesArgs: false,
8593
mutatesSelfAsArray: 'deopt-only',
8694
returns: null,
8795
returnsPrimitive: UNKNOWN_EXPRESSION
@@ -91,6 +99,7 @@ const METHOD_DEOPTS_SELF_RETURNS_UNKNOWN: [ExpressionEntity] = [
9199
const METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN: [ExpressionEntity] = [
92100
new Method({
93101
callsArgs: [0],
102+
mutatesArgs: false,
94103
mutatesSelfAsArray: 'deopt-only',
95104
returns: null,
96105
returnsPrimitive: UNKNOWN_EXPRESSION
@@ -100,6 +109,7 @@ const METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN: [ExpressionEntity] = [
100109
const METHOD_MUTATES_SELF_RETURNS_SELF: [ExpressionEntity] = [
101110
new Method({
102111
callsArgs: null,
112+
mutatesArgs: false,
103113
mutatesSelfAsArray: true,
104114
returns: 'self',
105115
returnsPrimitive: null
@@ -109,6 +119,7 @@ const METHOD_MUTATES_SELF_RETURNS_SELF: [ExpressionEntity] = [
109119
const METHOD_CALLS_ARG_MUTATES_SELF_RETURNS_SELF: [ExpressionEntity] = [
110120
new Method({
111121
callsArgs: [0],
122+
mutatesArgs: false,
112123
mutatesSelfAsArray: true,
113124
returns: 'self',
114125
returnsPrimitive: null
@@ -140,7 +151,7 @@ export const ARRAY_PROTOTYPE = new ObjectEntity(
140151
lastIndexOf: METHOD_RETURNS_NUMBER,
141152
map: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NEW_ARRAY,
142153
pop: METHOD_MUTATES_SELF_RETURNS_UNKNOWN,
143-
push: METHOD_MUTATES_SELF_RETURNS_NUMBER,
154+
push: METHOD_MUTATES_SELF_AND_ARGS_RETURNS_NUMBER,
144155
reduce: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
145156
reduceRight: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
146157
reverse: METHOD_MUTATES_SELF_RETURNS_SELF,
@@ -151,7 +162,7 @@ export const ARRAY_PROTOTYPE = new ObjectEntity(
151162
splice: METHOD_MUTATES_SELF_RETURNS_NEW_ARRAY,
152163
toLocaleString: METHOD_RETURNS_STRING,
153164
toString: METHOD_RETURNS_STRING,
154-
unshift: METHOD_MUTATES_SELF_RETURNS_NUMBER,
165+
unshift: METHOD_MUTATES_SELF_AND_ARGS_RETURNS_NUMBER,
155166
values: METHOD_DEOPTS_SELF_RETURNS_UNKNOWN
156167
} as unknown as PropertyMap,
157168
OBJECT_PROTOTYPE,

src/ast/nodes/shared/MethodTypes.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import {
66
NODE_INTERACTION_UNKNOWN_ASSIGNMENT,
77
NODE_INTERACTION_UNKNOWN_CALL
88
} from '../../NodeInteractions';
9-
import { EMPTY_PATH, type ObjectPath, UNKNOWN_INTEGER_PATH } from '../../utils/PathTracker';
9+
import {
10+
EMPTY_PATH,
11+
type ObjectPath,
12+
UNKNOWN_INTEGER_PATH,
13+
UNKNOWN_PATH
14+
} from '../../utils/PathTracker';
1015
import {
1116
UNKNOWN_LITERAL_BOOLEAN,
1217
UNKNOWN_LITERAL_NUMBER,
@@ -17,6 +22,7 @@ import { ExpressionEntity, UNKNOWN_EXPRESSION, UNKNOWN_RETURN_EXPRESSION } from
1722
type MethodDescription = {
1823
callsArgs: number[] | null;
1924
mutatesSelfAsArray: boolean | 'deopt-only';
25+
mutatesArgs: boolean;
2026
} & (
2127
| {
2228
returns: 'self' | (() => ExpressionEntity);
@@ -34,8 +40,15 @@ export class Method extends ExpressionEntity {
3440
}
3541

3642
deoptimizeArgumentsOnInteractionAtPath({ args, type }: NodeInteraction, path: ObjectPath): void {
37-
if (type === INTERACTION_CALLED && path.length === 0 && this.description.mutatesSelfAsArray) {
38-
args[0]?.deoptimizePath(UNKNOWN_INTEGER_PATH);
43+
if (type === INTERACTION_CALLED && path.length === 0) {
44+
if (this.description.mutatesSelfAsArray) {
45+
args[0]?.deoptimizePath(UNKNOWN_INTEGER_PATH);
46+
}
47+
if (this.description.mutatesArgs) {
48+
for (let index = 1; index < args.length; index++) {
49+
args[index]!.deoptimizePath(UNKNOWN_PATH);
50+
}
51+
}
3952
}
4053
}
4154

@@ -97,6 +110,7 @@ export class Method extends ExpressionEntity {
97110
export const METHOD_RETURNS_BOOLEAN = [
98111
new Method({
99112
callsArgs: null,
113+
mutatesArgs: false,
100114
mutatesSelfAsArray: false,
101115
returns: null,
102116
returnsPrimitive: UNKNOWN_LITERAL_BOOLEAN
@@ -106,6 +120,7 @@ export const METHOD_RETURNS_BOOLEAN = [
106120
export const METHOD_RETURNS_STRING = [
107121
new Method({
108122
callsArgs: null,
123+
mutatesArgs: false,
109124
mutatesSelfAsArray: false,
110125
returns: null,
111126
returnsPrimitive: UNKNOWN_LITERAL_STRING
@@ -115,6 +130,7 @@ export const METHOD_RETURNS_STRING = [
115130
export const METHOD_RETURNS_NUMBER = [
116131
new Method({
117132
callsArgs: null,
133+
mutatesArgs: false,
118134
mutatesSelfAsArray: false,
119135
returns: null,
120136
returnsPrimitive: UNKNOWN_LITERAL_NUMBER
@@ -124,6 +140,7 @@ export const METHOD_RETURNS_NUMBER = [
124140
export const METHOD_RETURNS_UNKNOWN = [
125141
new Method({
126142
callsArgs: null,
143+
mutatesArgs: false,
127144
mutatesSelfAsArray: false,
128145
returns: null,
129146
returnsPrimitive: UNKNOWN_EXPRESSION
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = defineTest({
2+
description: 'deoptimizes elements pushed into an array'
3+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
let mutated1 = false;
2+
const state1 = {
3+
foo: undefined
4+
};
5+
6+
let mutated2 = false;
7+
const state2 = {
8+
foo: undefined
9+
};
10+
11+
const stack = [];
12+
stack.push(state1, state2);
13+
stack[0].foo = () => (mutated1 = true);
14+
stack.at(-1).foo = () => (mutated2 = true);
15+
16+
state1.foo?.();
17+
assert.ok(mutated1, '1');
18+
19+
state2.foo?.();
20+
assert.ok(mutated2, '2');
21+

0 commit comments

Comments
 (0)