Skip to content

Commit e55c6ad

Browse files
committed
Merge branch 'master' of https://github.com/rollup/rollup into sync-79c0aba3
2 parents 0f47ee5 + 79c0aba commit e55c6ad

File tree

56 files changed

+178
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+178
-115
lines changed

CHANGELOG.md

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

3+
## 4.22.4
4+
5+
_2024-09-21_
6+
7+
### Bug Fixes
8+
9+
- Fix a vulnerability in generated code that affects IIFE, UMD and CJS bundles when run in a browser context (#5671)
10+
11+
### Pull Requests
12+
13+
- [#5670](https://github.com/rollup/rollup/pull/5670): refactor: Use object.prototype to check for reserved properties (@YuHyeonWook)
14+
- [#5671](https://github.com/rollup/rollup/pull/5671): Fix DOM Clobbering CVE (@lukastaegert)
15+
16+
## 4.22.3
17+
18+
_2024-09-21_
19+
20+
### Bug Fixes
21+
22+
- Ensure that mutations in modules without side effects are observed while properly handling transitive dependencies (#5669)
23+
24+
### Pull Requests
25+
26+
- [#5669](https://github.com/rollup/rollup/pull/5669): Ensure impure dependencies of pure modules are added (@lukastaegert)
27+
328
## 4.22.2
429

530
_2024-09-20_

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

src/Bundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type {
1010
NormalizedOutputOptions,
1111
OutputBundle
1212
} from './rollup/types';
13-
import type { PluginDriver } from './utils/PluginDriver';
1413
import { getChunkAssignments } from './utils/chunkAssignment';
1514
import commondir from './utils/commondir';
1615
import { sortByExecutionOrder } from './utils/executionOrder';
@@ -28,6 +27,7 @@ import type { OutputBundleWithPlaceholders } from './utils/outputBundle';
2827
import { getOutputBundle, removeUnreferencedAssets } from './utils/outputBundle';
2928
import { parseAst } from './utils/parseAst';
3029
import { isAbsolute } from './utils/path';
30+
import type { PluginDriver } from './utils/PluginDriver';
3131
import { renderChunks } from './utils/renderChunks';
3232
import { timeEnd, timeStart } from './utils/timers';
3333
import {

src/Chunk.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import MagicString, { Bundle as MagicStringBundle, type SourceMap } from 'magic-string';
22
import { relative } from '../browser/src/path';
3-
import ExternalChunk from './ExternalChunk';
4-
import ExternalModule from './ExternalModule';
5-
import Module from './Module';
63
import ExportDefaultDeclaration from './ast/nodes/ExportDefaultDeclaration';
74
import FunctionDeclaration from './ast/nodes/FunctionDeclaration';
85
import type ImportExpression from './ast/nodes/ImportExpression';
@@ -13,7 +10,10 @@ import LocalVariable from './ast/variables/LocalVariable';
1310
import NamespaceVariable from './ast/variables/NamespaceVariable';
1411
import SyntheticNamedExportVariable from './ast/variables/SyntheticNamedExportVariable';
1512
import type Variable from './ast/variables/Variable';
13+
import ExternalChunk from './ExternalChunk';
14+
import ExternalModule from './ExternalModule';
1615
import finalisers from './finalisers/index';
16+
import Module from './Module';
1717
import type {
1818
GetInterop,
1919
GlobalsOption,
@@ -26,7 +26,6 @@ import type {
2626
RenderedChunk,
2727
RenderedModule
2828
} from './rollup/types';
29-
import type { PluginDriver } from './utils/PluginDriver';
3029
import { createAddons } from './utils/addons';
3130
import { deconflictChunk, type DependenciesToBeDeconflicted } from './utils/deconflictChunk';
3231
import { escapeId } from './utils/escapeId';
@@ -58,6 +57,7 @@ import {
5857
import type { OutputBundleWithPlaceholders } from './utils/outputBundle';
5958
import { FILE_PLACEHOLDER } from './utils/outputBundle';
6059
import { basename, extname, isAbsolute, normalize, resolve } from './utils/path';
60+
import type { PluginDriver } from './utils/PluginDriver';
6161
import { getAliasName, getImportPath } from './utils/relativeId';
6262
import type { RenderOptions } from './utils/renderHelpers';
6363
import { makeUnique, renderNamePattern } from './utils/renderNamePattern';

src/Graph.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export default class Graph {
172172
this.needsTreeshakingPass = false;
173173
for (const module of this.modules) {
174174
if (module.isExecuted) {
175+
module.hasTreeShakingPassStarted = true;
175176
if (module.info.moduleSideEffects === 'no-treeshake') {
176177
module.includeAllInBundle();
177178
} else {

src/Module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export default class Module {
220220
readonly dynamicImports: DynamicImport[] = [];
221221
excludeFromSourcemap: boolean;
222222
execIndex = Infinity;
223+
hasTreeShakingPassStarted = false;
223224
readonly implicitlyLoadedAfter = new Set<Module>();
224225
readonly implicitlyLoadedBefore = new Set<Module>();
225226
readonly importDescriptions = new Map<string, ImportDescription>();

src/ast/nodes/Identifier.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BLANK } from '../../utils/blank';
55
import { logIllegalImportReassignment } from '../../utils/logs';
66
import { PureFunctionKey } from '../../utils/pureFunctions';
77
import type { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
8+
import { markModuleAndImpureDependenciesAsExecuted } from '../../utils/traverseStaticDependencies';
89
import type { DeoptimizableEntity } from '../DeoptimizableEntity';
910
import type { HasEffectsContext, InclusionContext } from '../ExecutionContext';
1011
import type { NodeInteraction, NodeInteractionCalled } from '../NodeInteractions';
@@ -220,9 +221,10 @@ export default class Identifier extends NodeBase implements PatternNode {
220221
this.variable instanceof LocalVariable &&
221222
this.variable.kind &&
222223
tdzVariableKinds.has(this.variable.kind) &&
223-
// we ignore possible TDZs due to circular module dependencies as
224-
// otherwise we get many false positives
225-
this.variable.module === this.scope.context.module
224+
// We ignore modules that did not receive a treeshaking pass yet as that
225+
// causes many false positives due to circular dependencies or disabled
226+
// moduleSideEffects.
227+
this.variable.module.hasTreeShakingPassStarted
226228
)
227229
) {
228230
return (this.isTDZAccess = false);
@@ -241,9 +243,7 @@ export default class Identifier extends NodeBase implements PatternNode {
241243
return (this.isTDZAccess = true);
242244
}
243245

244-
// We ignore the case where the module is not yet executed because
245-
// moduleSideEffects are false.
246-
if (!this.variable.initReached && this.scope.context.module.isExecuted) {
246+
if (!this.variable.initReached) {
247247
// Either a const/let TDZ violation or
248248
// var use before declaration was encountered.
249249
return (this.isTDZAccess = true);
@@ -294,6 +294,12 @@ export default class Identifier extends NodeBase implements PatternNode {
294294
protected applyDeoptimizations(): void {
295295
this.deoptimized = true;
296296
if (this.variable instanceof LocalVariable) {
297+
// When accessing a variable from a module without side effects, this
298+
// means we use an export of that module and therefore need to potentially
299+
// include it in the bundle.
300+
if (!this.variable.module.isExecuted) {
301+
markModuleAndImpureDependenciesAsExecuted(this.variable.module);
302+
}
297303
this.variable.consolidateInitializers();
298304
this.scope.context.requestTreeshakingPass();
299305
}

src/ast/nodes/MetaProperty.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type MagicString from 'magic-string';
22
import type { InternalModuleFormat } from '../../rollup/types';
3-
import type { PluginDriver } from '../../utils/PluginDriver';
43
import { escapeId } from '../../utils/escapeId';
54
import type { GenerateCodeSnippets } from '../../utils/generateCodeSnippets';
65
import { DOCUMENT_CURRENT_SCRIPT } from '../../utils/interopHelpers';
76
import { dirname, normalize, relative } from '../../utils/path';
7+
import type { PluginDriver } from '../../utils/PluginDriver';
88
import type { RenderOptions } from '../../utils/renderHelpers';
99
import type { NodeInteraction } from '../NodeInteractions';
1010
import { INTERACTION_ACCESSED } from '../NodeInteractions';
@@ -158,7 +158,7 @@ const getRelativeUrlFromDocument = (relativePath: string, umd = false) =>
158158
getResolveUrl(
159159
`'${escapeId(relativePath)}', ${
160160
umd ? `typeof document === 'undefined' ? location.href : ` : ''
161-
}document.currentScript && document.currentScript.src || document.baseURI`
161+
}document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.src || document.baseURI`
162162
);
163163

164164
const getGenericImportMetaMechanism =
@@ -180,7 +180,7 @@ const getFileUrlFromRelativePath = (path: string) =>
180180
const getUrlFromDocument = (chunkId: string, umd = false) =>
181181
`${
182182
umd ? `typeof document === 'undefined' ? location.href : ` : ''
183-
}(${DOCUMENT_CURRENT_SCRIPT} && ${DOCUMENT_CURRENT_SCRIPT}.src || new URL('${escapeId(
183+
}(${DOCUMENT_CURRENT_SCRIPT} && ${DOCUMENT_CURRENT_SCRIPT}.tagName.toUpperCase() === 'SCRIPT' && ${DOCUMENT_CURRENT_SCRIPT}.src || new URL('${escapeId(
184184
chunkId
185185
)}', document.baseURI).href)`;
186186

0 commit comments

Comments
 (0)