8000 Partially revert #5658 and re-apply #5644 (#5667) · rollup/rollup@d5ff63d · GitHub
[go: up one dir, main page]

Skip to content

Commit d5ff63d

Browse files
authored
Partially revert #5658 and re-apply #5644 (#5667)
It appears that this might cause some build failures that need further investigation.
1 parent 0a821d9 commit d5ff63d

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

src/Graph.ts

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

src/Module.ts

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

src/ast/nodes/Identifier.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,9 @@ export default class Identifier extends NodeBase implements PatternNode {
220220
this.variable instanceof LocalVariable &&
221221
this.variable.kind &&
222222
tdzVariableKinds.has(this.variable.kind) &&
223-
// We ignore modules that did not receive a treeshaking pass yet as that
224-
// causes many false positives due to circular dependencies or disabled
225-
// moduleSideEffects.
226-
this.variable.module.hasTreeShakingPassStarted
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
227226
)
228227
) {
229228
return (this.isTDZAccess = false);
@@ -242,7 +241,9 @@ export default class Identifier extends NodeBase implements PatternNode {
242241
return (this.isTDZAccess = true);
243242
}
244243

245-
if (!this.variable.initReached) {
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) {
246247
// Either a const/let TDZ violation or
247248
// var use before declaration was encountered.
248249
return (this.isTDZAccess = true);
@@ -293,10 +294,6 @@ export default class Identifier extends NodeBase implements PatternNode {
293294
protected applyDeoptimizations(): void {
294295
this.deoptimized = true;
295296
if (this.variable instanceof LocalVariable) {
296-
// When accessing a variable from a module without side effects, this
297-
// means we use an export of that module and therefore need to potentially
298-
// include it in the bundle.
299-
this.variable.module.isExecuted = true;
300297
this.variable.consolidateInitializers();
301298
this.scope.context.requestTreeshakingPass();
302299
}

src/utils/renderChunks.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ export async function renderChunks(
5555
const getHash = hasherByType[outputOptions.hashCharacters];
5656
const chunkGraph = getChunkGraph(chunks);
5757
const {
58+
hashDependenciesByPlaceholder,
5859
initialHashesByPlaceholder,
5960
nonHashedChunksWithPlaceholders,
60-
renderedChunksByPlaceholder,
61-
hashDependenciesByPlaceholder
61+
placeholders,
62+
renderedChunksByPlaceholder
6263
} = await transformChunksAndGenerateContentHashes(
6364
renderedChunks,
6465
chunkGraph,
@@ -71,6 +72,7 @@ export async function renderChunks(
7172
renderedChunksByPlaceholder,
7273
hashDependenciesByPlaceholder,
7374
initialHashesByPlaceholder,
75+
placeholders,
7476
bundle,
7577
getHash
7678
);
@@ -283,6 +285,7 @@ async function transformChunksAndGenerateContentHashes(
283285
hashDependenciesByPlaceholder,
284286
initialHashesByPlaceholder,
285287
nonHashedChunksWithPlaceholders,
288+
placeholders,
286289
renderedChunksByPlaceholder
287290
};
288291
}
@@ -291,11 +294,13 @@ function generateFinalHashes(
291294
renderedChunksByPlaceholder: Map<string, RenderedChunkWithPlaceholders>,
292295
hashDependenciesByPlaceholder: Map<string, HashResult>,
293296
initialHashesByPlaceholder: Map<string, string>,
297+
placeholders: Set<string>,
294298
bundle: OutputBundleWithPlaceholders,
295299
getHash: GetHash
296300
) {
297301
const hashesByPlaceholder = new Map<string, string>(initialHashesByPlaceholder);
298-
for (const [placeholder, { fileName }] of renderedChunksByPlaceholder) {
302+
for (const placeholder of placeholders) {
303+
const { fileName } = renderedChunksByPlaceholder.get(placeholder)!;
299304
let contentToHash = '';
300305
const hashDependencyPlaceholders = new Set<string>([placeholder]);
301306
for (const dependencyPlaceholder of hashDependencyPlaceholders) {

test/function/samples/tree-shake-module-side-effects-update/_config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = defineTest({
2+
skip: true,
23
description: 'detects variable updates in modules without side effects (#5408)',
34
options: {
45
treeshake: {

test/misc/misc.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ describe('misc', () => {
114114
});
115115
});
116116

117-
// Skipped until potential issues are fixed, see #5659
118-
it.skip('applies consistent hashes regardless of chunk transform order', async () => {
117+
it('applies consistent hashes regardless of chunk transform order', async () => {
119118
const FILES = {
120119
main: `
121120
import('folder1/dupe').then(({dupe}) => console.log(dupe));

0 commit comments

Comments
 (0)
0