Description
It seems that the parse of a new
expression combined with a tagged template is incorrect. Consider the snippet below.
function f() {}
function i(template) { return f; }
new i`whatever`;
I expect this to be parsed as new_expression where the constructor is a member_expression consisting of identifier i
and template_string whatever
. However, this is being parsed as a call_expression with a new_expression and a template_string as children:
call_expression "new i`whatever`"
new_expression "new i"
new "new"
identifier "i"
template_string "`whatever`"
` "`"
string_fragment "whatever"
` "`"
When the new
expression contains arguments, the incorrectness becomes worse as two call_expression are nested around the new_expression and template_string, with arguments of the new
expression being parsed as the arguments of the outer call_expression:
function g(v) {}
function j(template) { return g; }
new j`whatever`(1);
call_expression "new j`whatever`(1)"
call_expression "new j`whatever`"
new_expression "new j"
new "new"
identifier "j"
template_string "`whatever`"
` "`"
string_fragment "whatever"
` "`"
arguments "(1)"
( "("
number "1"
) ")"
As a reference to what I consider the correct parse for these 2 snippets, I'm attaching a screenshot from AST explorer's parse of it.
Perhaps this can be fixed by replacing primary_expression
for member_expression
in the tree-sitter's grammar? (Link to the corresponding spec grammar.)