-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lazy assign connections to dependencies
in many cases we don't need the assignment
- Loading branch information
Showing
1 changed file
with
46 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,8 @@ class ModuleGraphModule { | |
this.profile = undefined; | ||
/** @type {boolean} */ | ||
this.async = false; | ||
/** @type {ModuleGraphConnection[]} */ | ||
this._unassignedConnections = undefined; | ||
} | ||
} | ||
|
||
|
@@ -169,14 +171,21 @@ class ModuleGraph { | |
dependency.weak, | ||
dependency.getCondition(this) | ||
); | ||
this._dependencyMap.set(dependency, connection); | ||
const connections = this._getModuleGraphModule(module).incomingConnections; | ||
connections.add(connection); | ||
const mgm = this._getModuleGraphModule(originModule); | ||
if (mgm.outgoingConnections === undefined) { | ||
mgm.outgoingConnections = new Set(); | ||
if (originModule) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sokra
Author
Member
|
||
const mgm = this._getModuleGraphModule(originModule); | ||
if (mgm._unassignedConnections === undefined) { | ||
mgm._unassignedConnections = []; | ||
} | ||
mgm._unassignedConnections.push(connection); | ||
if (mgm.outgoingConnections === undefined) { | ||
mgm.outgoingConnections = new Set(); | ||
} | ||
mgm.outgoingConnections.add(connection); | ||
} else { | ||
this._dependencyMap.set(dependency, connection); | ||
} | ||
mgm.outgoingConnections.add(connection); | ||
} | ||
|
||
/** | ||
|
@@ -185,7 +194,7 @@ class ModuleGraph { | |
* @returns {void} | ||
*/ | ||
updateModule(dependency, module) { | ||
const connection = this._dependencyMap.get(dependency); | ||
const connection = this.getConnection(dependency); | ||
if (connection.module === module) return; | ||
const newConnection = connection.clone(); | ||
newConnection.module = module; | ||
|
@@ -202,12 +211,12 @@ class ModuleGraph { | |
* @returns {void} | ||
*/ | ||
removeConnection(dependency) { | ||
const connection = this._dependencyMap.get(dependency); | ||
const connection = this.getConnection(dependency); | ||
const targetMgm = this._getModuleGraphModule(connection.module); | ||
targetMgm.incomingConnections.delete(connection); | ||
const originMgm = this._getModuleGraphModule(connection.originModule); | ||
originMgm.outgoingConnections.delete(connection); | ||
this._dependencyMap.delete(dependency); | ||
this._dependencyMap.set(dependency, null); | ||
} | ||
|
||
/** | ||
|
@@ -216,7 +225,7 @@ class ModuleGraph { | |
* @returns {void} | ||
*/ | ||
addExplanation(dependency, explanation) { | ||
const connection = this._dependencyMap.get(dependency); | ||
const connection = this.getConnection(dependency); | ||
connection.addExplanation(explanation); | ||
} | ||
|
||
|
@@ -342,7 +351,7 @@ class ModuleGraph { | |
* @returns {Module} the referenced module | ||
*/ | ||
getResolvedModule(dependency) { | ||
const connection = this._dependencyMap.get(dependency); | ||
const connection = this.getConnection(dependency); | ||
return connection !== undefined ? connection.resolvedModule : null; | ||
} | ||
|
||
|
@@ -352,15 +361,38 @@ class ModuleGraph { | |
*/ | ||
getConnection(dependency) { | ||
const connection = this._dependencyMap.get(dependency); | ||
return connection; | ||
if (connection === undefined) { | ||
const module = this.getParentModule(dependency); | ||
if (module !== undefined) { | ||
const mgm = this._getModuleGraphModule(module); | ||
if ( | ||
mgm._unassignedConnections && | ||
mgm._unassignedConnections.length !== 0 | ||
) { | ||
let foundConnection; | ||
for (const connection of mgm._unassignedConnections) { | ||
this._dependencyMap.set(connection.dependency, connection); | ||
if (connection.dependency === dependency) | ||
foundConnection = connection; | ||
} | ||
mgm._unassignedConnections.length = 0; | ||
if (foundConnection !== undefined) { | ||
return foundConnection; | ||
} | ||
} | ||
} | ||
this._dependencyMap.set(dependency, null); | ||
return undefined; | ||
} | ||
return connection === null ? undefined : connection; | ||
} | ||
|
||
/** | ||
* @param {Dependency} dependency the dependency to look for a referenced module | ||
* @returns {Module} the referenced module | ||
*/ | ||
getModule(dependency) { | ||
const connection = this._dependencyMap.get(dependency); | ||
const connection = this.getConnection(dependency); | ||
return connection !== undefined ? connection.module : null; | ||
} | ||
|
||
|
@@ -369,7 +401,7 @@ class ModuleGraph { | |
* @returns {Module} the referencing module | ||
*/ | ||
getOrigin(dependency) { | ||
const connection = this._dependencyMap.get(dependency); | ||
const connection = this.getConnection(dependency); | ||
return connection !== undefined ? connection.originModule : null; | ||
} | ||
|
||
|
@@ -378,7 +410,7 @@ class ModuleGraph { | |
* @returns {Module} the original referencing module | ||
*/ | ||
getResolvedOrigin(dependency) { | ||
const connection = this._dependencyMap.get(dependency); | ||
const connection = this.getConnection(dependency); | ||
return connection !== undefined ? connection.resolvedOriginModule : null; | ||
} | ||
|
||
|
Before this commit, the root node of module tree could be extracted by
moduleGraph._moduleMap.get(null)
, so I wonder how to get the module tree's root node after this commit?