Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/browser",
"version": "4.22.2",
"version": "4.22.3-0",
"description": "Next-generation ES module bundler browser build",
"main": "dist/rollup.browser.js",
"module": "dist/es/rollup.browser.js",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup",
"version": "4.22.2",
"version": "4.22.3-0",
"description": "Next-generation ES module bundler",
"main": "dist/rollup.js",
"module": "dist/es/rollup.js",
Expand Down
2 changes: 1 addition & 1 deletion src/Bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {
NormalizedOutputOptions,
OutputBundle
} from './rollup/types';
import type { PluginDriver } from './utils/PluginDriver';
import { getChunkAssignments } from './utils/chunkAssignment';
import commondir from './utils/commondir';
import { sortByExecutionOrder } from './utils/executionOrder';
Expand All @@ -28,6 +27,7 @@ import type { OutputBundleWithPlaceholders } from './utils/outputBundle';
import { getOutputBundle, removeUnreferencedAssets } from './utils/outputBundle';
import { parseAst } from './utils/parseAst';
import { isAbsolute } from './utils/path';
import type { PluginDriver } from './utils/PluginDriver';
import { renderChunks } from './utils/renderChunks';
import { timeEnd, timeStart } from './utils/timers';
import {
Expand Down
8 changes: 4 additions & 4 deletions src/Chunk.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import MagicString, { Bundle as MagicStringBundle, type SourceMap } from 'magic-string';
import { relative } from '../browser/src/path';
import ExternalChunk from './ExternalChunk';
import ExternalModule from './ExternalModule';
import Module from './Module';
import ExportDefaultDeclaration from './ast/nodes/ExportDefaultDeclaration';
import FunctionDeclaration from './ast/nodes/FunctionDeclaration';
import type ImportExpression from './ast/nodes/ImportExpression';
Expand All @@ -13,7 +10,10 @@ import LocalVariable from './ast/variables/LocalVariable';
import NamespaceVariable from './ast/variables/NamespaceVariable';
import SyntheticNamedExportVariable from './ast/variables/SyntheticNamedExportVariable';
import type Variable from './ast/variables/Variable';
import ExternalChunk from './ExternalChunk';
import ExternalModule from './ExternalModule';
import finalisers from './finalisers/index';
import Module from './Module';
import type {
GetInterop,
GlobalsOption,
Expand All @@ -26,7 +26,6 @@ import type {
RenderedChunk,
RenderedModule
} from './rollup/types';
import type { PluginDriver } from './utils/PluginDriver';
import { createAddons } from './utils/addons';
import { deconflictChunk, type DependenciesToBeDeconflicted } from './utils/deconflictChunk';
import { escapeId } from './utils/escapeId';
Expand Down Expand Up @@ -58,6 +57,7 @@ import {
import type { OutputBundleWithPlaceholders } from './utils/outputBundle';
import { FILE_PLACEHOLDER } from './utils/outputBundle';
import { basename, extname, isAbsolute, normalize, resolve } from './utils/path';
import type { PluginDriver } from './utils/PluginDriver';
import { getAliasName, getImportPath } from './utils/relativeId';
import type { RenderOptions } from './utils/renderHelpers';
import { makeUnique, renderNamePattern } from './utils/renderNamePattern';
Expand Down
1 change: 1 addition & 0 deletions src/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export default class Graph {
this.needsTreeshakingPass = false;
for (const module of this.modules) {
if (module.isExecuted) {
module.hasTreeShakingPassStarted = true;
if (module.info.moduleSideEffects === 'no-treeshake') {
module.includeAllInBundle();
} else {
Expand Down
1 change: 1 addition & 0 deletions src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export default class Module {
readonly dynamicImports: DynamicImport[] = [];
excludeFromSourcemap: boolean;
execIndex = Infinity;
hasTreeShakingPassStarted = false;
readonly implicitlyLoadedAfter = new Set<Module>();
readonly implicitlyLoadedBefore = new Set<Module>();
readonly importDescriptions = new Map<string, ImportDescription>();
Expand Down
18 changes: 12 additions & 6 deletions src/ast/nodes/Identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BLANK } from '../../utils/blank';
import { logIllegalImportReassignment } from '../../utils/logs';
import { PureFunctionKey } from '../../utils/pureFunctions';
import type { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import { markModuleAndImpureDependenciesAsExecuted } from '../../utils/traverseStaticDependencies';
import type { DeoptimizableEntity } from '../DeoptimizableEntity';
import type { HasEffectsContext, InclusionContext } from '../ExecutionContext';
import type { NodeInteraction, NodeInteractionCalled } from '../NodeInteractions';
Expand Down Expand Up @@ -220,9 +221,10 @@ export default class Identifier extends NodeBase implements PatternNode {
this.variable instanceof LocalVariable &&
this.variable.kind &&
tdzVariableKinds.has(this.variable.kind) &&
// we ignore possible TDZs due to circular module dependencies as
// otherwise we get many false positives
this.variable.module === this.scope.context.module
// We ignore modules that did not receive a treeshaking pass yet as that
// causes many false positives due to circular dependencies or disabled
// moduleSideEffects.
this.variable.module.hasTreeShakingPassStarted
)
) {
return (this.isTDZAccess = false);
Expand All @@ -241,9 +243,7 @@ export default class Identifier extends NodeBase implements PatternNode {
return (this.isTDZAccess = true);
}

// We ignore the case where the module is not yet executed because
// moduleSideEffects are false.
if (!this.variable.initReached && this.scope.context.module.isExecuted) {
if (!this.variable.initReached) {
// Either a const/let TDZ violation or
// var use before declaration was encountered.
return (this.isTDZAccess = true);
Expand Down Expand Up @@ -294,6 +294,12 @@ export default class Identifier extends NodeBase implements PatternNode {
protected applyDeoptimizations(): void {
this.deoptimized = true;
if (this.variable instanceof LocalVariable) {
// When accessing a variable from a module without side effects, this
// means we use an export of that module and therefore need to potentially
// include it in the bundle.
if (!this.variable.module.isExecuted) {
markModuleAndImpureDependenciesAsExecuted(this.variable.module);
}
this.variable.consolidateInitializers();
this.scope.context.requestTreeshakingPass();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = defineTest({
description: 'includes impure dependencies of modules without side effects',
options: {
treeshake: {
moduleSideEffects: id => id.endsWith('effect.js')
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './effect.js';
export const value = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { updateSharedValue } from './shared';
updateSharedValue();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { value } from './dep.js';
import { sharedValue } from './shared';

assert.ok(value);
assert.strictEqual(sharedValue, 'updated');
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export let sharedValue = 'original';
export function updateSharedValue() {
sharedValue = 'updated';
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = defineTest({
skip: true,
description: 'detects variable updates in modules without side effects (#5408)',
options: {
treeshake: {
Expand Down