Skip to content

Commit e1e6d2c

Browse files
committed
Fixed a bug where lib crashes without error when passing a file outside a solution.
Plus needed for CLI.
1 parent 12bc94e commit e1e6d2c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

CSharpToJavaScript/CSTOJS.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Microsoft.CodeAnalysis;
99
using CSharpToJavaScript.Utils;
1010
using System.Linq;
11-
using System;
11+
using Microsoft.CodeAnalysis.Text;
1212

1313
namespace CSharpToJavaScript
1414
{
@@ -103,9 +103,13 @@ private async Task GenerateAsync(string path, Assembly assembly, string filename
103103
{
104104
_Walker = new(_Options);
105105

106-
string fileCS = await File.ReadAllTextAsync(path);
106+
SyntaxTree? tree = null;
107+
108+
using (var stream = File.OpenRead(path))
109+
{
110+
tree = CSharpSyntaxTree.ParseText(SourceText.From(stream), path: path);
111+
}
107112

108-
SyntaxTree tree = CSharpSyntaxTree.ParseText(fileCS);
109113
CompilationUnitSyntax root = tree.GetCompilationUnitRoot();
110114

111115
string assemblyPath = Path.GetDirectoryName(assembly.Location);

0 commit comments

Comments
 (0)