Skip to content

Commit

Permalink
Partially revert #5658 and re-apply #5644 (#5667)
Browse files Browse the repository at this point in the history
It appears that this might cause some build failures
that need further investigation.
  • Loading branch information
lukastaegert authored Sep 20, 2024
1 parent 0a821d9 commit d5ff63d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ 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: 0 additions & 1 deletion src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ 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
15 changes: 6 additions & 9 deletions src/ast/nodes/Identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,9 @@ export default class Identifier extends NodeBase implements PatternNode {
this.variable instanceof LocalVariable &&
this.variable.kind &&
tdzVariableKinds.has(this.variable.kind) &&
// 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
// we ignore possible TDZs due to circular module dependencies as
// otherwise we get many false positives
this.variable.module === this.scope.context.module
)
) {
return (this.isTDZAccess = false);
Expand All @@ -242,7 +241,9 @@ export default class Identifier extends NodeBase implements PatternNode {
return (this.isTDZAccess = true);
}

if (!this.variable.initReached) {
// We ignore the case where the module is not yet executed because
// moduleSideEffects are false.
if (!this.variable.initReached && this.scope.context.module.isExecuted) {
// Either a const/let TDZ violation or
// var use before declaration was encountered.
return (this.isTDZAccess = true);
Expand Down Expand Up @@ -293,10 +294,6 @@ 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.
this.variable.module.isExecuted = true;
this.variable.consolidateInitializers();
this.scope.context.requestTreeshakingPass();
}
Expand Down
11 changes: 8 additions & 3 deletions src/utils/renderChunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ export async function renderChunks(
const getHash = hasherByType[outputOptions.hashCharacters];
const chunkGraph = getChunkGraph(chunks);
const {
hashDependenciesByPlaceholder,
initialHashesByPlaceholder,
nonHashedChunksWithPlaceholders,
renderedChunksByPlaceholder,
hashDependenciesByPlaceholder
placeholders,
renderedChunksByPlaceholder
} = await transformChunksAndGenerateContentHashes(
renderedChunks,
chunkGraph,
Expand All @@ -71,6 +72,7 @@ export async function renderChunks(
renderedChunksByPlaceholder,
hashDependenciesByPlaceholder,
initialHashesByPlaceholder,
placeholders,
bundle,
getHash
);
Expand Down Expand Up @@ -283,6 +285,7 @@ async function transformChunksAndGenerateContentHashes(
hashDependenciesByPlaceholder,
initialHashesByPlaceholder,
nonHashedChunksWithPlaceholders,
placeholders,
renderedChunksByPlaceholder
};
}
Expand All @@ -291,11 +294,13 @@ function generateFinalHashes(
renderedChunksByPlaceholder: Map<string, RenderedChunkWithPlaceholders>,
hashDependenciesByPlaceholder: Map<string, HashResult>,
initialHashesByPlaceholder: Map<string, string>,
placeholders: Set<string>,
bundle: OutputBundleWithPlaceholders,
getHash: GetHash
) {
const hashesByPlaceholder = new Map<string, string>(initialHashesByPlaceholder);
for (const [placeholder, { fileName }] of renderedChunksByPlaceholder) {
for (const placeholder of placeholders) {
const { fileName } = renderedChunksByPlaceholder.get(placeholder)!;
let contentToHash = '';
const hashDependencyPlaceholders = new Set<string>([placeholder]);
for (const dependencyPlaceholder of hashDependencyPlaceholders) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = defineTest({
skip: true,
description: 'detects variable updates in modules without side effects (#5408)',
options: {
treeshake: {
Expand Down
3 changes: 1 addition & 2 deletions test/misc/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ describe('misc', () => {
});
});

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

0 comments on commit d5ff63d

Please sign in to comment.