Skip to content

Commit 102953a

Browse files
committed
fix: Fix the pipe arguments precedence
1 parent 470fac2 commit 102953a

File tree

10 files changed

+21430
-12308
lines changed

10 files changed

+21430
-12308
lines changed

grammar.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const HTML = require('tree-sitter-html/grammar');
1212
const PREC = {
1313
CALL: 1,
1414
ALIAS: 2,
15+
PIPE: 3,
16+
NULLISH: 4,
17+
INTERPOLATION: 5,
1518
};
1619

1720
module.exports = grammar(HTML, {
@@ -276,10 +279,13 @@ module.exports = grammar(HTML, {
276279

277280
// ---------- Interpolation ---------
278281
interpolation: ($) =>
279-
seq(
280-
alias($._interpolation_start, '{{'),
281-
choice($._any_expression, $.concatenation_expression),
282-
alias($._interpolation_end, '}}'),
282+
prec.right(
283+
PREC.INTERPOLATION,
284+
seq(
285+
alias($._interpolation_start, '{{'),
286+
choice($._any_expression, $.concatenation_expression),
287+
alias($._interpolation_end, '}}'),
288+
),
283289
),
284290

285291
concatenation_expression: ($) =>
@@ -383,7 +389,7 @@ module.exports = grammar(HTML, {
383389

384390
// ---------- Expressions ---------
385391
// Expression
386-
expression: ($) => seq($._primitive, optional(field('pipes', $.pipe_sequence))),
392+
expression: ($) => prec.left(seq($._primitive, optional(field('pipes', $.pipe_sequence)))),
387393

388394
// Unary expression
389395
unary_expression: ($) =>
@@ -415,10 +421,13 @@ module.exports = grammar(HTML, {
415421

416422
// Nullish coalescing expression
417423
nullish_coalescing_expression: ($) =>
418-
seq(
419-
field('condition', $._any_expression),
420-
alias('??', $.coalescing_operator),
421-
field('default', $._primitive),
424+
prec.right(
425+
PREC.NULLISH,
426+
seq(
427+
field('condition', $._any_expression),
428+
alias('??', $.coalescing_operator),
429+
field('default', $._primitive),
430+
),
422431
),
423432

424433
// Conditional expression
@@ -441,13 +450,16 @@ module.exports = grammar(HTML, {
441450
),
442451

443452
// ---------- Pipes ---------
444-
pipe_sequence: ($) => repeat1(seq(alias('|', $.pipe_operator), $.pipe_call)),
453+
pipe_sequence: ($) => prec.left(PREC.PIPE, repeat1(seq(alias('|', $.pipe_operator), $.pipe_call))),
445454

446455
pipe_call: ($) =>
447-
seq(field('name', $.identifier), optional(field('arguments', $.pipe_arguments))),
456+
prec.left(
457+
PREC.PIPE,
458+
seq(field('name', $.identifier), optional(field('arguments', $.pipe_arguments))),
459+
),
448460

449-
pipe_arguments: ($) => repeat1($._pipe_argument),
450-
_pipe_argument: ($) => seq(':', $._primitive),
461+
pipe_arguments: ($) => prec.left(PREC.PIPE, repeat1($._pipe_argument)),
462+
_pipe_argument: ($) => prec.left(PREC.PIPE, seq(':', choice($._any_expression, $.group))),
451463

452464
// ---------- Primitives ----------
453465
_primitive: ($) =>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codemod.com/tree-sitter-angular",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "Tree-sitter grammar for the Angular framework",
55
"main": "bindings/node",
66
"types": "bindings/node",
@@ -61,5 +61,11 @@
6161
"tree_sitter": {
6262
"optional": true
6363
}
64-
}
64+
},
65+
"tree-sitter": [
66+
{
67+
"scope": "source.angular",
68+
"injection-regex": "^angular$"
69+
}
70+
]
6571
}

0 commit comments

Comments
 (0)