Skip to content

Commit 15d5e85

Browse files
committed
In 'new_expression', just parse the constructor as an expression
This avoids the premature parsing decision that happened in the last commit. However, we now get a conflict because of the '?.' token, for the following token sequence: new foo ?. One one hand, the '?.' token may be part of a member_expression or subscript_expression. In that case, we want to SHIFT the '?.' token before creating the 'new_expression' node, in order to group things like this: 'new' ( expression '?.' identifier) or | | ----- member_expression ---- On the other hand, the '?.' token may be part of a 'call_expression', in which case, the parser thinks we would want to create the 'new_expression' first, so as to group things like this: ( 'new' expression ) '?.' arguments | | -- new_expression -- This second conflicting interpretation arises because 'new_expression' currently has *higher* precedence than 'call_expression' - we set the precedences this way in PR #89.
1 parent 4909c4f commit 15d5e85

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ module.exports = grammar({
632632

633633
new_expression: $ => prec.right(PREC.NEW, seq(
634634
'new',
635-
field('constructor', $._constructable_expression),
635+
field('constructor', $._expression),
636636
field('arguments', optional($.arguments))
637637
)),
638638

src/grammar.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2739,7 +2739,7 @@
27392739
"name": "constructor",
27402740
"content": {
27412741
"type": "SYMBOL",
2742-
"name": "_constructable_expression"
2742+
"name": "_expression"
27432743
}
27442744
},
27452745
{

0 commit comments

Comments
 (0)