Don't count extra trees toward stack versions' error costs
This commit is contained in:
parent
877fe1f682
commit
9538b5b879
2 changed files with 39 additions and 8 deletions
29
spec/fixtures/error_corpus/javascript_errors.txt
vendored
29
spec/fixtures/error_corpus/javascript_errors.txt
vendored
|
|
@ -123,8 +123,7 @@ var
|
|||
(var_assignment (identifier) (number))
|
||||
(ERROR) (identifier)
|
||||
(var_assignment (identifier) (number))
|
||||
(ERROR (identifier))
|
||||
(identifier)))
|
||||
(var_assignment (identifier) (ERROR) (identifier))))
|
||||
|
||||
============================================
|
||||
Misplaced expressions in var declarations
|
||||
|
|
@ -150,3 +149,29 @@ var x;
|
|||
(var_assignment (identifier) (number))
|
||||
(var_assignment (identifier) (number)))
|
||||
(var_declaration (identifier)))
|
||||
|
||||
================================================
|
||||
Mismatched delimiters in var declarations
|
||||
================================================
|
||||
|
||||
var
|
||||
// keep this
|
||||
a,
|
||||
|
||||
// skip this
|
||||
[
|
||||
|
||||
// keep this
|
||||
b = 1;
|
||||
|
||||
var c;
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(var_declaration
|
||||
(comment)
|
||||
(identifier)
|
||||
(ERROR (comment) (comment))
|
||||
(var_assignment (identifier) (number)))
|
||||
(var_declaration (identifier)))
|
||||
|
|
|
|||
|
|
@ -91,8 +91,6 @@ static StackNode *stack_node_new(StackNode *next, TSTree *tree, bool is_pending,
|
|||
else if (!(node = ts_malloc(sizeof(StackNode))))
|
||||
return NULL;
|
||||
|
||||
bool is_error = (state == ts_parse_state_error);
|
||||
|
||||
*node = (StackNode){
|
||||
.ref_count = 1,
|
||||
.link_count = 0,
|
||||
|
|
@ -100,21 +98,29 @@ static StackNode *stack_node_new(StackNode *next, TSTree *tree, bool is_pending,
|
|||
.state = state,
|
||||
.position = position,
|
||||
.error_depth = 0,
|
||||
.error_cost = is_error ? 1 : 0,
|
||||
.error_cost = 0,
|
||||
};
|
||||
|
||||
if (next) {
|
||||
stack_node_retain(next);
|
||||
node->links[0] = (StackLink){ next, tree, is_pending };
|
||||
|
||||
node->link_count = 1;
|
||||
node->error_cost += next->error_cost;
|
||||
node->links[0] = (StackLink){ next, tree, is_pending };
|
||||
|
||||
node->error_cost = next->error_cost;
|
||||
node->error_depth = next->error_depth;
|
||||
|
||||
if (tree) {
|
||||
ts_tree_retain(tree);
|
||||
node->error_cost += tree->error_size;
|
||||
if (state == ts_parse_state_error) {
|
||||
if (!tree->extra) {
|
||||
node->error_cost++;
|
||||
}
|
||||
} else {
|
||||
node->error_cost += tree->error_size;
|
||||
}
|
||||
} else {
|
||||
node->error_cost++;
|
||||
node->error_depth++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue