/// <summary> /// Parsed the <paramref name="configPath"/> file using special <see cref="TypeScript.Net.DScript.ParsingOptions.CollectImportFile"/> /// option to collect all invocations of the 'importFile' function. Returns the parsed file (as an <see cref="ISourceFile"/>) /// and a list of <see cref="AbsolutePath"/>s representing files imported from the config. If any error happens, uses the /// <see cref="Logger"/> to report it. In the case of an error, the returned value is unspecified. /// </summary> private async Task <ParseResult> ParseFileAndDiscoverImportsAsync(AbsolutePath configPath) { var maybeParsedConfig = await TryParseAsync(configPath, configPath, ParsingOptions.WithCollectImportFile(true)); if (!maybeParsedConfig.Succeeded) { ReportConfigParsingFailed(maybeParsedConfig.Failure.Describe()); return(new ParseResult(configPath, null, null)); } var configSourceFile = maybeParsedConfig.Result; if (configSourceFile.ParseDiagnostics.Count != 0) { ReportErrorDiagnostics(configSourceFile.ParseDiagnostics); return(new ParseResult(configPath, configSourceFile, null)); } // Files should be bound for the following ast conversion. Binder.Bind(configSourceFile, CompilerOptions.Empty); if (configSourceFile.BindDiagnostics.Count != 0) { ReportErrorDiagnostics(configSourceFile.BindDiagnostics); return(new ParseResult(configPath, configSourceFile, null)); } var configDirectory = configPath.GetParent(Context.PathTable); var importedFiles = configSourceFile.LiteralLikeSpecifiers .Select(ConvertPathFromLiteralToAbsolutePath) .Where(path => path.IsValid) .ToList(); return(new ParseResult(configPath, configSourceFile, importedFiles)); AbsolutePath ConvertPathFromLiteralToAbsolutePath(ILiteralExpression literal) { if (RelativePath.TryCreate(Context.StringTable, literal.Text, out RelativePath importRelativePath)) { return(configDirectory.Combine(Context.PathTable, importRelativePath)); } else if (AbsolutePath.TryCreate(Context.PathTable, literal.Text, out AbsolutePath absolutePath)) { return(absolutePath); } else { var location = literal.GetLineInfo(configSourceFile).ToLocationData(configPath).ToLogLocation(Context.PathTable); ReportConfigParsingFailed("Invalid path: " + literal.Text, location); return(AbsolutePath.Invalid); } } }
/// <summary> /// Binds the given sourcefile /// </summary> public static void Bind(ISourceFile sourceFile) { var binder = new TypeScript.Net.Binding.Binder(); binder.BindSourceFile(sourceFile, s_publicCompilerOptions); }