Skip to content

Commit

Permalink
wip: {{else}} is a keyword and not a helper call
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Jan 6, 2020
1 parent fea9fc4 commit 6af9613
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/languages/handlebars.js
Expand Up @@ -10,7 +10,7 @@ function (hljs) {

var BUILT_INS = {
'builtin-name': 'action bindattr collection component concat debugger '
+ 'each each-in else get hash if in input link-to loc log lookup '
+ 'each each-in get hash if in input link-to loc log lookup '
+ 'mut outlet partial query-params render template textarea unbound '
+ 'unless view with yield'
};
Expand Down Expand Up @@ -138,6 +138,10 @@ function (hljs) {
begin: /\{\{#/, end: /\}\}/,
contains: [OPENING_BLOCK_MUSTACHE_CONTENTS],
},
{
className: 'keyword',
begin: /\{\{else\}\}/
},
{
// closing block statement
className: 'template-tag',
Expand Down
14 changes: 14 additions & 0 deletions test/markup/handlebars/else-variants.expect.txt
@@ -0,0 +1,14 @@
<span class="xml">Multiple possibilities of using "else":

</span><span class="hljs-template-tag">{{#<span class="hljs-name">helper</span>}}</span><span class="hljs-keyword">{{else}}</span><span class="xml">else-block</span><span class="hljs-template-tag">{{/<span class="hljs-name">helper</span>}}</span><span class="xml">
...
</span><span class="hljs-template-tag">{{#<span class="hljs-name">helper</span>}}</span><span class="xml">block</span><span class="hljs-keyword">{{else}}</span><span class="xml">else-block</span><span class="hljs-template-tag">{{/<span class="hljs-name">helper</span>}}</span><span class="xml">
...
</span><span class="hljs-template-variable">{{<span class="hljs-name">[<span class="hljs-built_in">else</span>]</span>}}</span><span class="xml"> in brackets is a helper, not a keyword
...
</span><span class="hljs-template-tag">{{#<span class="hljs-name"><span class="hljs-built_in">else</span></span>}}</span><span class="xml"> as block helper name is not a keyword </span><span class="hljs-template-tag">{{/<span class="hljs-name"><span class="hljs-built_in">else</span></span>}}</span><span class="xml">
...
\{{else}} is not a keyword if escaped
...
Done
</span>
13 changes: 13 additions & 0 deletions test/markup/handlebars/else-variants.txt
@@ -0,0 +1,13 @@
Multiple possibilities of using "else":

{{#helper}}{{else}}else-block{{/helper}}
...
{{#helper}}block{{else}}else-block{{/helper}}
...
{{[else]}} in brackets is a helper, not a keyword
...
{{#else}} as block helper name is not a keyword {{/else}}
...
\{{else}} is not a keyword if escaped
...
Done

0 comments on commit 6af9613

Please sign in to comment.