Skip to content

Commit 89b4e51

Browse files
authoredOct 8, 2021
Unmark defer for dependency that become used ('does not export') (#7035)
1 parent b575212 commit 89b4e51

File tree

12 files changed

+59
-1
lines changed

12 files changed

+59
-1
lines changed
 

‎packages/core/core/src/AssetGraph.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
304304

305305
let {sideEffects, canDefer = true} = childNode.value;
306306
let dependency = node.value;
307-
let previouslyDeferred = childNode.deferred;
307+
let previouslyDeferred = node.hasDeferred;
308308
let defer = this.shouldDeferDependency(dependency, sideEffects, canDefer);
309309
node.hasDeferred = defer;
310310
childNode.deferred = defer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {a} from "./package/";
2+
3+
sideEffectNoop(a);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { v } from "./b";
2+
import c from "./c";
3+
4+
export default class a {
5+
constructor() {
6+
c(v);
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const d1 = "def";
2+
export const v = "abc";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { d1 } from "./d";
2+
export const v = "abc";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { d1 } from "./b";
2+
export default function c() {
3+
return d1;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const d1 = "hello", d2 = 2 , d3 = 3;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export {d2} from './d';
2+
export {default as a} from "./a";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"sideEffects": false
3+
}

‎packages/core/integration-tests/test/integration/scope-hoisting/es6/unmarks-defer-for-new-deps/yarn.lock

Whitespace-only changes.

‎packages/core/integration-tests/test/scope-hoisting.js

+32
Original file line numberDiff line numberDiff line change
@@ -5932,4 +5932,36 @@ describe('scope hoisting', function() {
59325932
let res = await run(b, {output: null}, {require: false});
59335933
assert.equal(res.output, 'a');
59345934
});
5935+
5936+
it('should unmark dependency as deferred when dependency becomes used', async function() {
5937+
let testDir = path.join(
5938+
__dirname,
5939+
'integration/scope-hoisting/es6/unmarks-defer-for-new-deps',
5940+
);
5941+
5942+
let packageDir = path.join(testDir, '/package');
5943+
5944+
await overlayFS.mkdirp(packageDir);
5945+
await overlayFS.copyFile(
5946+
path.join(packageDir, 'b1.js'),
5947+
path.join(packageDir, 'b.js'),
5948+
);
5949+
5950+
await bundle(path.join(testDir, 'index.js'), {
5951+
inputFS: overlayFS,
5952+
outputFS: overlayFS,
5953+
shouldDisableCache: true,
5954+
});
5955+
5956+
await overlayFS.copyFile(
5957+
path.join(packageDir, 'b2.js'),
5958+
path.join(packageDir, 'b.js'),
5959+
);
5960+
5961+
await bundle(path.join(testDir, 'index.js'), {
5962+
inputFS: overlayFS,
5963+
outputFS: overlayFS,
5964+
shouldDisableCache: false,
5965+
});
5966+
});
59355967
});

0 commit comments

Comments
 (0)
Please sign in to comment.