Skip to content

Commit f353d48

Browse files
committed
Merge branch 'master' of https://github.com/rollup/rollup into sync-9f5a7355
2 parents c84cd10 + 9f5a735 commit f353d48

File tree

12 files changed

+87
-36
lines changed

12 files changed

+87
-36
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.21.3
4+
5+
_2024-09-12_
6+
7+
### Bug Fixes
8+
9+
- Always respect side effects in left-hand side of optional chain (#5642)
10+
- Update stack trace for augmented errors to not hide relevant information (#5640)
11+
12+
### Pull Requests
13+
14+
- [#5636](https://github.com/rollup/rollup/pull/5636): chore(deps): lock file maintenance minor/patch updates (@renovate[bot])
15+
- [#5637](https://github.com/rollup/rollup/pull/5637): chore(deps): lock file maintenance (@renovate[bot])
16+
- [#5640](https://github.com/rollup/rollup/pull/5640): fix: keep the message of stack up-to-date (@TrickyPi)
17+
- [#5642](https://github.com/rollup/rollup/pull/5642): fix: include left-side effect of optional chaining in the end of hasEffectsAsChainElement (@TrickyPi)
18+
319
## 4.21.2
420

521
_2024-08-30_

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.21.2",
3+
"version": "4.21.3",
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.21.2",
3+
"version": "4.21.3",
44
"description": "Next-generation ES module bundler",
55
"main": "dist/rollup.js",
66
"module": "dist/es/rollup.js",

src/ast/nodes/CallExpression.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ export default class CallExpression
106106
}
107107
return (
108108
!this.annotationPure &&
109-
this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)
109+
(calleeHasEffects ||
110+
this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context))
110111
);
111112
}
112113

src/ast/nodes/MemberExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export default class MemberExpression
296296
}
297297
// We only apply deoptimizations lazily once we know we are not skipping
298298
if (!this.deoptimized) this.applyDeoptimizations();
299-
return this.property.hasEffects(context) || this.hasAccessEffect(context);
299+
return objectHasEffects || this.property.hasEffects(context) || this.hasAccessEffect(context);
300300
}
301301

302302
hasEffectsAsAssignmentTarget(context: HasEffectsContext, checkAccess: boolean): boolean {

src/utils/logs.ts

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ export function augmentLogMessage(log: AugmentedRollupLog): void {
9393
const position = log.loc ? ` (${log.loc.line}:${log.loc.column})` : '';
9494
prefix += `${relativeId(id)}${position}: `;
9595
}
96-
96+
const oldMessage = log.message;
9797
log.message = prefix + log.message;
98+
tweakStackMessage(log, oldMessage);
9899
}
99100

100101
// Error codes should be sorted alphabetically while errors should be sorted by
@@ -513,34 +514,51 @@ export function logCannotAssignModuleToChunk(
513514
};
514515
}
515516

517+
function tweakStackMessage(error: RollupLog, oldMessage: string): RollupLog {
518+
if (!error.stack) {
519+
return error;
520+
}
521+
error.stack = error.stack.replace(oldMessage, error.message);
522+
return error;
523+
}
524+
516525
export function logCannotBundleConfigAsEsm(originalError: Error): RollupLog {
517-
return {
518-
cause: originalError,
519-
code: INVALID_CONFIG_MODULE_FORMAT,
520-
message: `Rollup transpiled your configuration to an ES module even though it appears to contain CommonJS elements. To resolve this, you can pass the "--bundleConfigAsCjs" flag to Rollup or change your configuration to only contain valid ESM code.\n\nOriginal error: ${originalError.message}`,
521-
stack: originalError.stack,
522-
url: getRollupUrl(URL_BUNDLE_CONFIG_AS_CJS)
523-
};
526+
return tweakStackMessage(
527+
{
528+
cause: originalError,
529+
code: INVALID_CONFIG_MODULE_FORMAT,
530+
message: `Rollup transpiled your configuration to an ES module even though it appears to contain CommonJS elements. To resolve this, you can pass the "--bundleConfigAsCjs" flag to Rollup or change your configuration to only contain valid ESM code.\n\nOriginal error: ${originalError.message}`,
531+
stack: originalError.stack,
532+
url: getRollupUrl(URL_BUNDLE_CONFIG_AS_CJS)
533+
},
534+
originalError.message
535+
);
524536
}
525537

526538
export function logCannotLoadConfigAsCjs(originalError: Error): RollupLog {
527-
return {
528-
cause: originalError,
529-
code: INVALID_CONFIG_MODULE_FORMAT,
530-
message: `Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.\n\nOriginal error: ${originalError.message}`,
531-
stack: originalError.stack,
532-
url: getRollupUrl(URL_BUNDLE_CONFIG_AS_CJS)
533-
};
539+
return tweakStackMessage(
540+
{
541+
cause: originalError,
542+
code: INVALID_CONFIG_MODULE_FORMAT,
543+
message: `Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.\n\nOriginal error: ${originalError.message}`,
544+
stack: originalError.stack,
545+
url: getRollupUrl(URL_BUNDLE_CONFIG_AS_CJS)
546+
},
547+
originalError.message
548+
);
534549
}
535550

536551
export function logCannotLoadConfigAsEsm(originalError: Error): RollupLog {
537-
return {
538-
cause: originalError,
539-
code: INVALID_CONFIG_MODULE_FORMAT,
540-
message: `Node tried to load your configuration as an ES module even though it is likely CommonJS. To resolve this, change the extension of your configuration to ".cjs" or pass the "--bundleConfigAsCjs" flag.\n\nOriginal error: ${originalError.message}`,
541-
stack: originalError.stack,
542-
url: getRollupUrl(URL_BUNDLE_CONFIG_AS_CJS)
543-
};
552+
return tweakStackMessage(
553+
{
554+
cause: originalError,
555+
code: INVALID_CONFIG_MODULE_FORMAT,
556+
message: `Node tried to load your configuration as an ES module even though it is likely CommonJS. To resolve this, change the extension of your configuration to ".cjs" or pass the "--bundleConfigAsCjs" flag.\n\nOriginal error: ${originalError.message}`,
557+
stack: originalError.stack,
558+
url: getRollupUrl(URL_BUNDLE_CONFIG_AS_CJS)
559+
},
560+
originalError.message
561+
);
544562
}
545563

546564
export function logInvalidExportOptionValue(optionValue: string): RollupLog {
@@ -891,13 +909,16 @@ export function logModuleParseError(error: Error, moduleId: string): RollupLog {
891909
} else if (!moduleId.endsWith('.js')) {
892910
message += ' (Note that you need plugins to import files that are not JavaScript)';
893911
}
894-
return {
895-
cause: error,
896-
code: PARSE_ERROR,
897-
id: moduleId,
898-
message,
899-
stack: error.stack
900-
};
912+
return tweakStackMessage(
913+
{
914+
cause: error,
915+
code: PARSE_ERROR,
916+
id: moduleId,
917+
message,
918+
stack: error.stack
919+
},
920+
error.message
921+
);
901922
}
902923

903924
export function logPluginError(

test/cli/samples/config-type-module/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = defineTest({
88
stderr: stderr => {
99
assertIncludes(
1010
stderr,
11-
'ReferenceError: module is not defined in ES module scope\n' +
11+
'Original error: module is not defined in ES module scope\n' +
1212
"This file is being treated as an ES module because it has a '.js' file extension and"
1313
);
1414
assertIncludes(
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = defineTest({
2+
description: 'preserve optional chaining with smallest treeshake',
3+
options: {
4+
treeshake: 'smallest'
5+
}
6+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
while (global[++i]?.key) {} //retained
2+
while (global(++i)?.key) {} //retained

0 commit comments

Comments
 (0)