Skip to content

Commit 871e121

Browse files
committed
Make class_literal take precedence over field_access
1 parent 81148c0 commit 871e121

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

grammar.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const PREC = {
2424
ARRAY: 16, // [Index]
2525
OBJ_ACCESS: 16, // .
2626
PARENS: 16, // (Expression)
27+
CLASS_LITERAL: 17, // .
2728
};
2829

2930
module.exports = grammar({
@@ -69,6 +70,7 @@ module.exports = grammar({
6970
// Only conflicts in switch expressions
7071
[$.lambda_expression, $.primary_expression],
7172
[$.inferred_parameters, $.primary_expression],
73+
[$.class_literal, $.field_access],
7274
],
7375

7476
word: $ => $.identifier,
@@ -309,7 +311,7 @@ module.exports = grammar({
309311

310312
parenthesized_expression: $ => seq('(', $.expression, ')'),
311313

312-
class_literal: $ => seq($._unannotated_type, '.', 'class'),
314+
class_literal: $ => prec.dynamic(PREC.CLASS_LITERAL, seq($._unannotated_type, '.', 'class')),
313315

314316
object_creation_expression: $ => choice(
315317
$._unqualified_object_creation_expression,
@@ -324,15 +326,15 @@ module.exports = grammar({
324326
optional($.class_body)
325327
)),
326328

327-
field_access: $ => seq(
329+
field_access: $ => prec.dynamic(PREC.OBJ_ACCESS, seq(
328330
field('object', choice($.primary_expression, $.super)),
329331
optional(seq(
330332
'.',
331333
$.super
332334
)),
333335
'.',
334336
field('field', choice($.identifier, $._reserved_identifier, $.this))
335-
),
337+
)),
336338

337339
array_access: $ => seq(
338340
field('array', $.primary_expression),

0 commit comments

Comments
 (0)