Skip to content

Commit 41abed5

Browse files
committed
Native support for else and else if in block statements
As there isn't a native concept of if statements in the grammar, it makes it especially hard to query `else if` statements, as they've previously just been exposed as a helper. It makes it cumbersome to query `else` blocks and not possible—I think at least—to query and capture `else if` as the same capture. `else` is supported for all block_statements in Ember, but `else if` isn't, but it wouldn't be valid syntax that we want to capture any other way, so I haven't tried to be cleaver about it.
1 parent da605af commit 41abed5

File tree

5 files changed

+3175
-2640
lines changed

5 files changed

+3175
-2640
lines changed

Diff for: grammar.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,23 @@ module.exports = grammar({
216216
choice("}}", "~}}"),
217217
),
218218

219+
block_statement_inverse: ($) =>
220+
choice(
221+
seq(
222+
choice("{{", "{{~"),
223+
"else",
224+
optional($.block_params),
225+
choice("}}", "~}}"),
226+
),
227+
// prettier-ignore
228+
seq(
229+
choice("{{", "{{~"),
230+
"else if",
231+
$._arguments,
232+
choice("}}", "~}}"),
233+
),
234+
),
235+
219236
block_statement_end: ($) =>
220237
seq(
221238
choice("{{/", "{{~/"),
@@ -226,7 +243,9 @@ module.exports = grammar({
226243
block_statement: ($) =>
227244
seq(
228245
$.block_statement_start,
229-
field("program", repeat($._declaration)),
246+
repeat(
247+
choice($.block_statement_inverse, field("program", $._declaration)),
248+
),
230249
$.block_statement_end,
231250
),
232251
},

Diff for: src/grammar.json

+107-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/node-types.json

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)