From f81f3d0c901949b93b701d6bb7a54f3696c77bf6 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Fri, 5 Jul 2024 12:38:23 +0300 Subject: [PATCH] Fix Tree.printDotGraph ignoring fd Fixes #202 --- src/parser.cc | 2 +- src/tree.cc | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/parser.cc b/src/parser.cc index f27fdd70..966e5cd5 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -274,7 +274,7 @@ Napi::Value Parser::SetLogger(const Napi::CallbackInfo &info) { Napi::Value Parser::PrintDotGraphs(const Napi::CallbackInfo &info) { bool should_print = true; - int32_t fd = fileno(stderr); + int fd = fileno(stderr); if (info.Length() > 0) { if (!info[0].IsBoolean()) { diff --git a/src/tree.cc b/src/tree.cc index f0433f91..78f98fdd 100644 --- a/src/tree.cc +++ b/src/tree.cc @@ -231,7 +231,16 @@ Napi::Value Tree::GetEditedRange(const Napi::CallbackInfo &info) { } Napi::Value Tree::PrintDotGraph(const Napi::CallbackInfo &info) { - ts_tree_print_dot_graph(tree_, fileno(stderr)); + int fd = fileno(stderr); + + if (info.Length() > 1) { + if (!info[1].IsNumber()) { + throw TypeError::New(info.Env(), "Second argument must be a number"); + } + fd = info[1].As().Int32Value(); + } + + ts_tree_print_dot_graph(tree_, fd); return info.This(); }