From 8f028ebf6813512ec59b89a7f8c03eadd1bae9e5 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 5 Jul 2017 17:33:35 -0700 Subject: [PATCH] Avoid deep tree comparison when both trees have errors --- src/runtime/parser.c | 2 ++ test/fixtures/error_corpus/javascript_errors.txt | 2 +- test/runtime/parser_test.cc | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/runtime/parser.c b/src/runtime/parser.c index 5e2f75f3..13ef9a76 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -452,6 +452,8 @@ static bool parser__select_tree(Parser *self, Tree *left, Tree *right) { return false; } + if (left->error_cost > 0) return -1; + int comparison = ts_tree_compare(left, right); switch (comparison) { case -1: diff --git a/test/fixtures/error_corpus/javascript_errors.txt b/test/fixtures/error_corpus/javascript_errors.txt index 02edfb48..f4f99bc8 100644 --- a/test/fixtures/error_corpus/javascript_errors.txt +++ b/test/fixtures/error_corpus/javascript_errors.txt @@ -53,8 +53,8 @@ if ({a: 'b'} {c: 'd'}) { (program (if_statement + (ERROR (object (pair (identifier) (string)))) (object (pair (identifier) (string))) - (ERROR (statement_block (labeled_statement (identifier) (expression_statement (string))))) (statement_block (expression_statement (assignment (identifier) diff --git a/test/runtime/parser_test.cc b/test/runtime/parser_test.cc index 0c7e30a3..f680ecf5 100644 --- a/test/runtime/parser_test.cc +++ b/test/runtime/parser_test.cc @@ -398,7 +398,8 @@ describe("Parser", [&]() { assert_root_node( "(program " - "(expression_statement (number) (ERROR (number))) " + "(ERROR (number)) " + "(expression_statement (number)) " "(expression_statement (math_op (number) (number))))"); }); });