Skip to content

Commit 8a770b1

Browse files
committed
Merge pull request #524 from mousetraps/i508
#508 Unhandled System.ArgumentException and
2 parents fd59a1d + d3c0297 commit 8a770b1

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ namespace Microsoft.NodejsTools.Analysis {
3232
/// Our dependency tracking scheme works by tracking analysis units - when we add a dependency it is the current
3333
/// AnalysisUnit which is dependent upon the variable. If the value of a variable changes then all of the dependent
3434
/// AnalysisUnit's will be re-enqueued. This proceeds until we reach a fixed point.
35+
///
36+
/// Note that AnalysisUnit contructors / methods are not threadsafe because we expect there to be many AnalysisUnits,
37+
/// and we want to keep things as performant as possible (which means minimizing locking behavior and whatnot.)
3538
/// </summary>
3639
[Serializable]
3740
internal class AnalysisUnit : ISet<AnalysisUnit> {

Nodejs/Product/Analysis/Analysis/JsAnalyzer.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,12 @@ public IAnalyzable AddPackageJson(string filePath, string entryPoint, List<strin
143143

144144
tree.DefaultPackage = entryPoint;
145145

146-
var requireAnalysisUnits = new List<RequireAnalysisUnit>();
146+
ProjectEntry projectEntry = null;
147147
if (dependencies != null) {
148-
var projectEntry = new ProjectEntry(this, filePath, null);
149-
requireAnalysisUnits.AddRange(dependencies.Select(
150-
dependency => { return new RequireAnalysisUnit(tree, Modules, projectEntry, dependency);
151-
}));
148+
projectEntry = new ProjectEntry(this, filePath, null);
152149
}
153150

154-
return new TreeUpdateAnalysis(tree, requireAnalysisUnits);
151+
return new TreeUpdateAnalysis(tree, dependencies, projectEntry, Modules);
155152
}
156153

157154
/// <summary>
@@ -162,22 +159,33 @@ public IAnalyzable AddPackageJson(string filePath, string entryPoint, List<strin
162159
[Serializable]
163160
internal class TreeUpdateAnalysis : IAnalyzable {
164161
private readonly ModuleTree _tree;
165-
private readonly IEnumerable<RequireAnalysisUnit> _requireAnalysisUnits;
162+
private readonly IEnumerable<string> _dependencies;
163+
private readonly ProjectEntry _projectEntry;
164+
private readonly ModuleTable _modules;
166165

167-
public TreeUpdateAnalysis(ModuleTree tree, IEnumerable<RequireAnalysisUnit> requireAnalysisUnits = null) {
166+
public TreeUpdateAnalysis(ModuleTree tree, IEnumerable<string> dependencies = null, ProjectEntry projectEntry = null, ModuleTable modules = null) {
168167
_tree = tree;
169-
_requireAnalysisUnits = requireAnalysisUnits;
168+
_dependencies = dependencies;
169+
_projectEntry = projectEntry;
170+
_modules = modules;
170171
}
171172

172173
public void Analyze(CancellationToken cancel) {
173174
if (_tree != null) {
174175
_tree.EnqueueDependents();
175176
}
176-
if (_requireAnalysisUnits != null) {
177-
foreach (var unit in _requireAnalysisUnits) {
177+
178+
if (_dependencies != null) {
179+
var requireAnalysisUnits = new List<RequireAnalysisUnit>();
180+
requireAnalysisUnits.AddRange(_dependencies.Select(
181+
dependency => {
182+
return new RequireAnalysisUnit(_tree, _modules, _projectEntry, dependency);
183+
}));
184+
185+
foreach (var unit in requireAnalysisUnits) {
178186
unit.AnalyzeWorker(null, cancel);
179187
}
180-
}
188+
}
181189
}
182190
}
183191

0 commit comments

Comments
 (0)