From 6a4032304db3e24d73446015782390752412aade Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Thu, 2 Jan 2020 23:33:08 +0100 Subject: [PATCH] wip: adjustments for integrating handlebars rules - hash-parameters - subexpressions wip: adjustments for integrating handlebars rules - hash-parameters - subexpressions wip: update tests some minor adaptions wip: fix test cases wip: try to honor path expressions correctly wip: fix tests and refactor language definition wip: update keywords, remove debug output wip: {{else}} is a keyword and not a helper call wip: fix test for else-variants - else is not a built-in (except for the keyword {{else}}) wip: fix hashes and number literals, add string literals - the hash-value must start after the equals-sign - number and string modes must be in front of identifiers, because they are a subset wip: make "as" in block-parameters a "keyword" --- src/languages/handlebars.js | 144 +++++++++++++++--- src/languages/htmlbars.js | 80 ---------- test/detect/htmlbars/default.txt | 9 -- ...ession-variants-as-path-segment.expect.txt | 17 ++- ...ck-expression-variants-as-path-segment.txt | 17 ++- ...ression-variants-in-helper-name.expect.txt | 26 ++-- ...ock-expression-variants-in-helper-name.txt | 28 ++-- ...ck-expression-variants-in-param.expect.txt | 10 +- .../block-expression-variants-in-param.txt | 10 +- .../handlebars/block-parameters-as.expect.txt | 10 ++ .../markup/handlebars/block-parameters-as.txt | 9 ++ .../handlebars/block-with-param.expect.txt | 6 +- test/markup/handlebars/block-with-param.txt | 4 + test/markup/handlebars/block.expect.txt | 6 +- test/markup/handlebars/block.txt | 4 + test/markup/handlebars/built-ins.expect.txt | 18 ++- test/markup/handlebars/built-ins.txt | 14 +- test/markup/handlebars/comments.expect.txt | 6 +- test/markup/handlebars/comments.txt | 6 +- .../complex-combinations.expect.txt | 8 + .../handlebars/complex-combinations.txt | 7 + .../handlebars/else-variants.expect.txt | 14 ++ test/markup/handlebars/else-variants.txt | 13 ++ .../handlebars/escaped-mustaches.expect.txt | 30 ++-- test/markup/handlebars/escaped-mustaches.txt | 24 +-- .../handlebars/expression-variants.expect.txt | 52 +++---- .../markup/handlebars/expression-variants.txt | 52 +++---- .../handlebars/helper-parameters.expect.txt | 8 + test/markup/handlebars/helper-parameters.txt | 7 + .../helper-subexpressions.expect.txt | 10 ++ .../handlebars/helper-subexpressions.txt | 9 ++ test/markup/handlebars/literals.expect.txt | 52 +++++++ test/markup/handlebars/literals.txt | 51 +++++++ .../markup/handlebars/partial-call.expect.txt | 12 +- test/markup/handlebars/partial-call.txt | 12 +- test/markup/handlebars/path-expressions.txt | 15 ++ test/markup/handlebars/raw-block.expect.txt | 12 +- test/markup/handlebars/raw-block.txt | 10 ++ .../handlebars/simple-expression.expect.txt | 6 +- test/markup/handlebars/simple-expression.txt | 4 + .../handlebars/sub-expressions.expect.txt | 2 - test/markup/handlebars/sub-expressions.txt | 1 - .../handlebars/triple-mustache.expect.txt | 12 +- test/markup/handlebars/triple-mustache.txt | 10 ++ 44 files changed, 595 insertions(+), 262 deletions(-) delete mode 100644 src/languages/htmlbars.js delete mode 100644 test/detect/htmlbars/default.txt create mode 100644 test/markup/handlebars/block-parameters-as.expect.txt create mode 100644 test/markup/handlebars/block-parameters-as.txt create mode 100644 test/markup/handlebars/complex-combinations.expect.txt create mode 100644 test/markup/handlebars/complex-combinations.txt create mode 100644 test/markup/handlebars/else-variants.expect.txt create mode 100644 test/markup/handlebars/else-variants.txt create mode 100644 test/markup/handlebars/helper-parameters.expect.txt create mode 100644 test/markup/handlebars/helper-parameters.txt create mode 100644 test/markup/handlebars/helper-subexpressions.expect.txt create mode 100644 test/markup/handlebars/helper-subexpressions.txt create mode 100644 test/markup/handlebars/literals.expect.txt create mode 100644 test/markup/handlebars/literals.txt create mode 100644 test/markup/handlebars/path-expressions.txt delete mode 100644 test/markup/handlebars/sub-expressions.expect.txt delete mode 100644 test/markup/handlebars/sub-expressions.txt diff --git a/src/languages/handlebars.js b/src/languages/handlebars.js index 7fea1c3cca..e502113b8f 100644 --- a/src/languages/handlebars.js +++ b/src/languages/handlebars.js @@ -6,31 +6,125 @@ Description: Matcher for Handlebars as well as EmberJS additions. Website: https://handlebarsjs.com Category: template */ +export default function (hljs) { -export default function(hljs) { - var BUILT_INS = {'builtin-name': 'each in with if else unless bindattr action collection debugger log outlet template unbound view yield lookup'}; + var BUILT_INS = { + 'builtin-name': 'action bindattr collection component concat debugger ' + + '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' + }; - var IDENTIFIER_PLAIN_OR_QUOTED = { - begin: /".*?"|'.*?'|\[.*?\]|\w+/ + var LITERALS = { + 'literal': 'true false undefined null' }; - var EXPRESSION_OR_HELPER_CALL = hljs.inherit(IDENTIFIER_PLAIN_OR_QUOTED, { - keywords: BUILT_INS, + // as defined in https://handlebarsjs.com/guide/expressions.html#literal-segments + // this regex matches literal segments like ' abc ' or [ abc ] as well as helpers and paths + // like a/b, ./abc/cde, and abc.bcd + var IDENFIFIER_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+|\.|\/)+/; + + // identifier followed by a equal-sign (without the equal sign) + var HASH_PARAM_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+)(?==)/; + + var HELPER_NAME_OR_PATH_EXPRESSION = { + begin: IDENFIFIER_REGEX, + lexemes: /[\w.\/]+/ + }; + + var HELPER_PARAMETER = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + keywords: LITERALS + }); + + var SUB_EXPRESSION = { + illegal: /\}\}/, + begin: /\(/, end: /\)/ + // the "contains" is added below when all necessary sub-modes are defined + }; + + var HASH = { + // fka "attribute-assignment", parameters of the form 'key=value' + className: 'attr', + illegal: /\}\}/, + begin: HASH_PARAM_REGEX, + relevance: 0, starts: { - // helper params - endsWithParent: true, - relevance: 0, - contains: [hljs.inherit(IDENTIFIER_PLAIN_OR_QUOTED, {relevance: 0})] + begin: /=/, + end: /=/, + starts: { + contains: [ + hljs.NUMBER_MODE, + hljs.QUOTE_STRING_MODE, + hljs.APOS_STRING_MODE, + HELPER_PARAMETER, + SUB_EXPRESSION + ] + } } + }; + + var BLOCK_PARAMS = { + // parameters of the form '{{#with x as | y |}}...{{/with}}' + begin: /as\s+\|/, + keywords: { keyword: 'as' }, + end: /\|/, + contains: [ + { + // define sub-mode in order to prevent highlighting of block-parameter named "as" + begin: /\w+/, + keywords: '' + } + ] + } + + var HELPER_PARAMETERS = { + contains: [ + hljs.NUMBER_MODE, + hljs.QUOTE_STRING_MODE, + hljs.APOS_STRING_MODE, + BLOCK_PARAMS, + HASH, + HELPER_PARAMETER, + SUB_EXPRESSION + ], + returnEnd: true + // the property "end" is defined through inheritance when the mode is used. If depends + // on the surrounding mode, but "endsWithParent" does not work here (i.e. it includes the + // end-token of the surrounding mode) + }; + + var SUB_EXPRESSION_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + className: 'name', + keywords: BUILT_INS, + starts: hljs.inherit(HELPER_PARAMETERS, { + end: /\)/, + }) + }); + + SUB_EXPRESSION.contains = [ + SUB_EXPRESSION_CONTENTS + ]; + + var OPENING_BLOCK_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + keywords: BUILT_INS, + className: 'name', + starts: hljs.inherit(HELPER_PARAMETERS, { + end: /}}/, + }) }); - var BLOCK_MUSTACHE_CONTENTS = hljs.inherit(EXPRESSION_OR_HELPER_CALL, { + var CLOSING_BLOCK_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + keywords: BUILT_INS, className: 'name' }); - var BASIC_MUSTACHE_CONTENTS = hljs.inherit(EXPRESSION_OR_HELPER_CALL, { - // relevance 0 for backward compatibility concerning auto-detection - relevance: 0 + + var BASIC_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + className: 'name', + keywords: BUILT_INS, + starts: hljs.inherit(HELPER_PARAMETERS, { + end: /}}/, + }) }); var ESCAPE_MUSTACHE_WITH_PRECEEDING_BACKSLASH = {begin: /\\\{\{/, skip: true}; @@ -38,7 +132,7 @@ export default function(hljs) { return { name: 'Handlebars', - aliases: ['hbs', 'html.hbs', 'html.handlebars'], + aliases: ['hbs', 'html.hbs', 'html.handlebars', 'htmlbars'], case_insensitive: true, subLanguage: 'xml', contains: [ @@ -50,33 +144,41 @@ export default function(hljs) { // open raw block "{{{{raw}}}} content not evaluated {{{{/raw}}}}" className: 'template-tag', begin: /\{\{\{\{(?!\/)/, end: /\}\}\}\}/, - contains: [BLOCK_MUSTACHE_CONTENTS], + contains: [OPENING_BLOCK_MUSTACHE_CONTENTS], starts: {end: /\{\{\{\{\//, returnEnd: true, subLanguage: 'xml'} }, { // close raw block className: 'template-tag', begin: /\{\{\{\{\//, end: /\}\}\}\}/, - contains: [BLOCK_MUSTACHE_CONTENTS] + contains: [CLOSING_BLOCK_MUSTACHE_CONTENTS] }, { // open block statement className: 'template-tag', - begin: /\{\{[#\/]/, end: /\}\}/, - contains: [BLOCK_MUSTACHE_CONTENTS], + begin: /\{\{#/, end: /\}\}/, + contains: [OPENING_BLOCK_MUSTACHE_CONTENTS], + }, + { + className: 'keyword', + begin: /\{\{else\}\}/ + }, + { + // closing block statement + className: 'template-tag', + begin: /\{\{\//, end: /\}\}/, + contains: [CLOSING_BLOCK_MUSTACHE_CONTENTS], }, { // template variable or helper-call that is NOT html-escaped className: 'template-variable', begin: /\{\{\{/, end: /\}\}\}/, - keywords: BUILT_INS, contains: [BASIC_MUSTACHE_CONTENTS] }, { // template variable or helper-call that is html-escaped className: 'template-variable', begin: /\{\{/, end: /\}\}/, - keywords: BUILT_INS, contains: [BASIC_MUSTACHE_CONTENTS] } ] diff --git a/src/languages/htmlbars.js b/src/languages/htmlbars.js deleted file mode 100644 index 49adc1561a..0000000000 --- a/src/languages/htmlbars.js +++ /dev/null @@ -1,80 +0,0 @@ -/* -Language: HTMLBars -Requires: xml.js -Author: Michael Johnston -Description: Matcher for HTMLBars -Website: https://github.com/tildeio/htmlbars -Category: template -*/ - -export default function(hljs) { - var BUILT_INS = 'action collection component concat debugger each each-in else get hash if input link-to loc log mut outlet partial query-params render textarea unbound unless with yield view'; - - var ATTR_ASSIGNMENT = { - illegal: /\}\}/, - begin: /[a-zA-Z0-9_]+=/, - returnBegin: true, - relevance: 0, - contains: [ - { - className: 'attr', begin: /[a-zA-Z0-9_]+/ - } - ] - }; - - var SUB_EXPR = { - illegal: /\}\}/, - begin: /\)/, end: /\)/, - contains: [ - { - begin: /[a-zA-Z\.\-]+/, - keywords: {built_in: BUILT_INS}, - starts: { - endsWithParent: true, relevance: 0, - contains: [ - hljs.QUOTE_STRING_MODE, - ] - } - } - ] - }; - - var TAG_INNARDS = { - endsWithParent: true, relevance: 0, - keywords: {keyword: 'as', built_in: BUILT_INS}, - contains: [ - hljs.QUOTE_STRING_MODE, - ATTR_ASSIGNMENT, - hljs.NUMBER_MODE - ] - }; - - return { - name: 'HTMLBars', - case_insensitive: true, - subLanguage: 'xml', - contains: [ - hljs.COMMENT('{{!(--)?', '(--)?}}'), - { - className: 'template-tag', - begin: /\{\{[#\/]/, end: /\}\}/, - contains: [ - { - className: 'name', - begin: /[a-zA-Z\.\-]+/, - keywords: {'builtin-name': BUILT_INS}, - starts: TAG_INNARDS - } - ] - }, - { - className: 'template-variable', - begin: /\{\{[a-zA-Z][a-zA-Z\-]+/, end: /\}\}/, - keywords: {keyword: 'as', built_in: BUILT_INS}, - contains: [ - hljs.QUOTE_STRING_MODE - ] - } - ] - }; -} diff --git a/test/detect/htmlbars/default.txt b/test/detect/htmlbars/default.txt deleted file mode 100644 index c3003aef0a..0000000000 --- a/test/detect/htmlbars/default.txt +++ /dev/null @@ -1,9 +0,0 @@ -
- {{!-- only output this author names if an author exists --}} - {{#if author}} - {{#playwright-wrapper playwright=author action=(mut author) as |playwright|}} -

{{playwright.firstName}} {{playwright.lastName}}

- {{/playwright-wrapper}} - {{/if}} - {{yield}} -
diff --git a/test/markup/handlebars/block-expression-variants-as-path-segment.expect.txt b/test/markup/handlebars/block-expression-variants-as-path-segment.expect.txt index c1a252d87c..4cfc329edd 100644 --- a/test/markup/handlebars/block-expression-variants-as-path-segment.expect.txt +++ b/test/markup/handlebars/block-expression-variants-as-path-segment.expect.txt @@ -1,9 +1,10 @@ -text {{#abc abcd.[lite"'ral}}segment] }}a{{/abc}} - -text {{#abc abcd."lite]'ral}}segment" }}a{{/abc}} - -text {{#abc abcd.'lite]"ral}}segment' }}a{{/abc}} - -text - +Block expression variants with literal segments in paths: +... +{{#abc abcd.[lite"'ral}}segment] }}a{{/abc}} +... +{{#abc abcd."lite]'ral}}segment" }}a{{/abc}} +... +{{#abc abcd.'lite]"ral}}segment' }}a{{/abc}} +... +Done diff --git a/test/markup/handlebars/block-expression-variants-as-path-segment.txt b/test/markup/handlebars/block-expression-variants-as-path-segment.txt index 98a378847e..f1e7e56989 100644 --- a/test/markup/handlebars/block-expression-variants-as-path-segment.txt +++ b/test/markup/handlebars/block-expression-variants-as-path-segment.txt @@ -1,8 +1,9 @@ -text {{#abc abcd.[lite"'ral}}segment] }}a{{/abc}} - -text {{#abc abcd."lite]'ral}}segment" }}a{{/abc}} - -text {{#abc abcd.'lite]"ral}}segment' }}a{{/abc}} - -text - +Block expression variants with literal segments in paths: +... +{{#abc abcd.[lite"'ral}}segment] }}a{{/abc}} +... +{{#abc abcd."lite]'ral}}segment" }}a{{/abc}} +... +{{#abc abcd.'lite]"ral}}segment' }}a{{/abc}} +... +Done diff --git a/test/markup/handlebars/block-expression-variants-in-helper-name.expect.txt b/test/markup/handlebars/block-expression-variants-in-helper-name.expect.txt index 09c34f21f3..0914769d32 100644 --- a/test/markup/handlebars/block-expression-variants-in-helper-name.expect.txt +++ b/test/markup/handlebars/block-expression-variants-in-helper-name.expect.txt @@ -1,14 +1,16 @@ -text {{#[ab}}c] param }}a{{/[ab}}c]}} +Block expression variants with literal segments in helper name: -text {{#'ab}}c' param}}a{{/'ab}}c'}} - -text {{#"ab}}c" param}}a{{/"ab}}c"}} - -text {{#"" param}}a{{/""}} - -text {{#'' param}}a{{/''}} - -text {{#[] param}}a{{/[]}} - -text +{{#[ab}}c] param }}a{{/[ab}}c]}} +... +{{#'ab}}c' param}}a{{/'ab}}c'}} +... +{{#"ab}}c" param}}a{{/"ab}}c"}} +... +{{#"" param}}a{{/""}} +... +{{#'' param}}a{{/''}} +... +{{#[] param}}a{{/[]}} +... +Done diff --git a/test/markup/handlebars/block-expression-variants-in-helper-name.txt b/test/markup/handlebars/block-expression-variants-in-helper-name.txt index 36468ffe53..1909c9f654 100644 --- a/test/markup/handlebars/block-expression-variants-in-helper-name.txt +++ b/test/markup/handlebars/block-expression-variants-in-helper-name.txt @@ -1,13 +1,15 @@ -text {{#[ab}}c] param }}a{{/[ab}}c]}} - -text {{#'ab}}c' param}}a{{/'ab}}c'}} - -text {{#"ab}}c" param}}a{{/"ab}}c"}} - -text {{#"" param}}a{{/""}} - -text {{#'' param}}a{{/''}} - -text {{#[] param}}a{{/[]}} - -text +Block expression variants with literal segments in helper name: + +{{#[ab}}c] param }}a{{/[ab}}c]}} +... +{{#'ab}}c' param}}a{{/'ab}}c'}} +... +{{#"ab}}c" param}}a{{/"ab}}c"}} +... +{{#"" param}}a{{/""}} +... +{{#'' param}}a{{/''}} +... +{{#[] param}}a{{/[]}} +... +Done diff --git a/test/markup/handlebars/block-expression-variants-in-param.expect.txt b/test/markup/handlebars/block-expression-variants-in-param.expect.txt index ae081bc79b..cbc71ebcd4 100644 --- a/test/markup/handlebars/block-expression-variants-in-param.expect.txt +++ b/test/markup/handlebars/block-expression-variants-in-param.expect.txt @@ -1,8 +1,6 @@ -text {{#abc "lite]'ral}}segment" }}a{{/abc}} +Block expression variants with literal segments in helper param: -text {{#abc 'lite]"ral}}segment' }}a{{/abc}} - -text {{#abc [lite"'ral}}segment] }}a{{/abc}} - -text +{{#abc [lite"'ral}}segment] }}a{{/abc}} +... +Done diff --git a/test/markup/handlebars/block-expression-variants-in-param.txt b/test/markup/handlebars/block-expression-variants-in-param.txt index 9f9d51b6d0..60aa82b669 100644 --- a/test/markup/handlebars/block-expression-variants-in-param.txt +++ b/test/markup/handlebars/block-expression-variants-in-param.txt @@ -1,7 +1,5 @@ -text {{#abc "lite]'ral}}segment" }}a{{/abc}} +Block expression variants with literal segments in helper param: -text {{#abc 'lite]"ral}}segment' }}a{{/abc}} - -text {{#abc [lite"'ral}}segment] }}a{{/abc}} - -text +{{#abc [lite"'ral}}segment] }}a{{/abc}} +... +Done diff --git a/test/markup/handlebars/block-parameters-as.expect.txt b/test/markup/handlebars/block-parameters-as.expect.txt new file mode 100644 index 0000000000..aec0ed84fd --- /dev/null +++ b/test/markup/handlebars/block-parameters-as.expect.txt @@ -0,0 +1,10 @@ +Block parameters (using "x as | y |"): + +{{#each filter as | value index|}} {{/each}} +... +{{#with as as | as |}} {{/with}} +... +{{#with (lookup 'abc') as | as |}} {{/with}} +... +Done + diff --git a/test/markup/handlebars/block-parameters-as.txt b/test/markup/handlebars/block-parameters-as.txt new file mode 100644 index 0000000000..2a2ea6f4ba --- /dev/null +++ b/test/markup/handlebars/block-parameters-as.txt @@ -0,0 +1,9 @@ +Block parameters (using "x as | y |"): + +{{#each filter as | value index|}} {{/each}} +... +{{#with as as | as |}} {{/with}} +... +{{#with (lookup 'abc') as | as |}} {{/with}} +... +Done diff --git a/test/markup/handlebars/block-with-param.expect.txt b/test/markup/handlebars/block-with-param.expect.txt index accf7824eb..ad970208d4 100644 --- a/test/markup/handlebars/block-with-param.expect.txt +++ b/test/markup/handlebars/block-with-param.expect.txt @@ -1,2 +1,6 @@ -{{#blockHelper param1 param2}}block content{{/blockHelper}} +Simple block with parameters: + +{{#blockHelper param1 param2}}block content{{/blockHelper}} +... +Done diff --git a/test/markup/handlebars/block-with-param.txt b/test/markup/handlebars/block-with-param.txt index 2fc7b05534..935964cadc 100644 --- a/test/markup/handlebars/block-with-param.txt +++ b/test/markup/handlebars/block-with-param.txt @@ -1 +1,5 @@ +Simple block with parameters: + {{#blockHelper param1 param2}}block content{{/blockHelper}} +... +Done diff --git a/test/markup/handlebars/block.expect.txt b/test/markup/handlebars/block.expect.txt index 52de3bf769..a34f679f52 100644 --- a/test/markup/handlebars/block.expect.txt +++ b/test/markup/handlebars/block.expect.txt @@ -1,2 +1,6 @@ -{{#block}}block content{{/block}} +Simple Block: + +{{#block}}block content{{/block}} +... +Done diff --git a/test/markup/handlebars/block.txt b/test/markup/handlebars/block.txt index 9f3da0a62b..5ec2723593 100644 --- a/test/markup/handlebars/block.txt +++ b/test/markup/handlebars/block.txt @@ -1 +1,5 @@ +Simple Block: + {{#block}}block content{{/block}} +... +Done diff --git a/test/markup/handlebars/built-ins.expect.txt b/test/markup/handlebars/built-ins.expect.txt index cedd3aa3e6..5a989e76a7 100644 --- a/test/markup/handlebars/built-ins.expect.txt +++ b/test/markup/handlebars/built-ins.expect.txt @@ -1,12 +1,16 @@ -{{#if test}}yes{{/if}} +Built-in helpers: +{{#if test}}yes{{/if}} +... {{#unless test}}no{{/unless}} - +... {{#with test}}abc{{/with}} - +... {{#each test}}abc{{/each}} - -{{lookup abc}} - -{{log test}} +... +{{lookup abc}} +... +{{log test}} +... +Done diff --git a/test/markup/handlebars/built-ins.txt b/test/markup/handlebars/built-ins.txt index c76597ab22..e0764d88d3 100644 --- a/test/markup/handlebars/built-ins.txt +++ b/test/markup/handlebars/built-ins.txt @@ -1,11 +1,15 @@ -{{#if test}}yes{{/if}} +Built-in helpers: +{{#if test}}yes{{/if}} +... {{#unless test}}no{{/unless}} - +... {{#with test}}abc{{/with}} - +... {{#each test}}abc{{/each}} - +... {{lookup abc}} - +... {{log test}} +... +Done diff --git a/test/markup/handlebars/comments.expect.txt b/test/markup/handlebars/comments.expect.txt index d1dbff8968..b27deaf1b3 100644 --- a/test/markup/handlebars/comments.expect.txt +++ b/test/markup/handlebars/comments.expect.txt @@ -1,4 +1,8 @@ -{{!-- a comment {{expression}} --}} {{expression}} +Comments: +{{!-- a comment {{commented.expression}} --}} {{expression}} +... {{! a simple comment }} +... +Done diff --git a/test/markup/handlebars/comments.txt b/test/markup/handlebars/comments.txt index 0c7260e0c4..10ab23a657 100644 --- a/test/markup/handlebars/comments.txt +++ b/test/markup/handlebars/comments.txt @@ -1,3 +1,7 @@ -{{!-- a comment {{expression}} --}} {{expression}} +Comments: +{{!-- a comment {{commented.expression}} --}} {{expression}} +... {{! a simple comment }} +... +Done diff --git a/test/markup/handlebars/complex-combinations.expect.txt b/test/markup/handlebars/complex-combinations.expect.txt new file mode 100644 index 0000000000..d64e8410ed --- /dev/null +++ b/test/markup/handlebars/complex-combinations.expect.txt @@ -0,0 +1,8 @@ +Complex combinations: + +{{#with.in.path (helper abc abc=abc cde=(helper xzx=xzx))}} {{/with.in.path}} +... +{{#with.in.path (helper abc abc='ab}}' (log x)))}} {{/with.in.path}} +... +Done + diff --git a/test/markup/handlebars/complex-combinations.txt b/test/markup/handlebars/complex-combinations.txt new file mode 100644 index 0000000000..26f6e0b09b --- /dev/null +++ b/test/markup/handlebars/complex-combinations.txt @@ -0,0 +1,7 @@ +Complex combinations: + +{{#with.in.path (helper abc abc=abc cde=(helper xzx=xzx))}} {{/with.in.path}} +... +{{#with.in.path (helper abc abc='ab}}' (log x)))}} {{/with.in.path}} +... +Done diff --git a/test/markup/handlebars/else-variants.expect.txt b/test/markup/handlebars/else-variants.expect.txt new file mode 100644 index 0000000000..ced6f1db06 --- /dev/null +++ b/test/markup/handlebars/else-variants.expect.txt @@ -0,0 +1,14 @@ +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 + diff --git a/test/markup/handlebars/else-variants.txt b/test/markup/handlebars/else-variants.txt new file mode 100644 index 0000000000..d7654bba0e --- /dev/null +++ b/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 diff --git a/test/markup/handlebars/escaped-mustaches.expect.txt b/test/markup/handlebars/escaped-mustaches.expect.txt index da37eb1812..a2a6add64f 100644 --- a/test/markup/handlebars/escaped-mustaches.expect.txt +++ b/test/markup/handlebars/escaped-mustaches.expect.txt @@ -1,22 +1,26 @@ -\{{no-expression}} +Escaping mustache expressions: +\{{no-expression}} +... \{{{no-expression}}} - +... \{{#no}} block \{{/no}} - +... \{{\{{no}}}} block \{{\{{/no}}}} - +... \{{!-- no comment --}} - +... \{{! no comment }} - +... <!-- escaped escapings --> - -\\{{expression}} - -\\\{{expression}} - -\\\\{{expression}} - +... +\\{{expression}} +... +\\\{{expression}} +... +\\\\{{expression}} +... \\\{{! comment }} +... +Done diff --git a/test/markup/handlebars/escaped-mustaches.txt b/test/markup/handlebars/escaped-mustaches.txt index 94c7ac3540..1baa5f474f 100644 --- a/test/markup/handlebars/escaped-mustaches.txt +++ b/test/markup/handlebars/escaped-mustaches.txt @@ -1,21 +1,25 @@ -\{{no-expression}} +Escaping mustache expressions: +\{{no-expression}} +... \{{{no-expression}}} - +... \{{#no}} block \{{/no}} - +... \{{\{{no}}}} block \{{\{{/no}}}} - +... \{{!-- no comment --}} - +... \{{! no comment }} - +... - +... \\{{expression}} - +... \\\{{expression}} - +... \\\\{{expression}} - +... \\\{{! comment }} +... +Done diff --git a/test/markup/handlebars/expression-variants.expect.txt b/test/markup/handlebars/expression-variants.expect.txt index 48da6b13c7..e1e832a0f2 100644 --- a/test/markup/handlebars/expression-variants.expect.txt +++ b/test/markup/handlebars/expression-variants.expect.txt @@ -1,27 +1,27 @@ -text - -{{ "lite]'ral}}segment" }} text - -{{ 'lite]"ral}}segment' }} text - -{{ [lite"'ral}}segment] }} text - -{{ abc "lite]'ral}}segment" }} text - -{{ abc 'lite]"ral}}segment' }} text - -{{ abc [lite"'ral}}segment] }} text - - -{{ abcd.[lite"'ral}}segment] }} text - -{{ abcd."lite]'ral}}segment" }} text - -{{ abcd.'lite]"ral}}segment' }} text - -{{ abcd.''}} text - -{{ abcd."" }} text - -{{ abcd.[] }} text +Literal segment variants in simple expressions: + +{{ "lite]'ral}}segment" }} +... +{{ 'lite]"ral}}segment' }} +... +{{ [lite"'ral}}segment] }} +... + +{{ abc [lite"'ral}}segment] }} +... + +{{ abcd.[lite"'ral}}segment] }} +... +{{ abcd."lite]'ral}}segment" }} +... +{{ abcd.'lite]"ral}}segment' }} +... + +{{ abcd.''}} +... +{{ abcd."" }} +... +{{ abcd.[] }} +... +Done diff --git a/test/markup/handlebars/expression-variants.txt b/test/markup/handlebars/expression-variants.txt index 6b3facc8de..e3bdc4c137 100644 --- a/test/markup/handlebars/expression-variants.txt +++ b/test/markup/handlebars/expression-variants.txt @@ -1,26 +1,26 @@ -text - -{{ "lite]'ral}}segment" }} text - -{{ 'lite]"ral}}segment' }} text - -{{ [lite"'ral}}segment] }} text - -{{ abc "lite]'ral}}segment" }} text - -{{ abc 'lite]"ral}}segment' }} text - -{{ abc [lite"'ral}}segment] }} text - - -{{ abcd.[lite"'ral}}segment] }} text - -{{ abcd."lite]'ral}}segment" }} text - -{{ abcd.'lite]"ral}}segment' }} text - -{{ abcd.''}} text - -{{ abcd."" }} text - -{{ abcd.[] }} text +Literal segment variants in simple expressions: + +{{ "lite]'ral}}segment" }} +... +{{ 'lite]"ral}}segment' }} +... +{{ [lite"'ral}}segment] }} +... + +{{ abc [lite"'ral}}segment] }} +... + +{{ abcd.[lite"'ral}}segment] }} +... +{{ abcd."lite]'ral}}segment" }} +... +{{ abcd.'lite]"ral}}segment' }} +... + +{{ abcd.''}} +... +{{ abcd."" }} +... +{{ abcd.[] }} +... +Done diff --git a/test/markup/handlebars/helper-parameters.expect.txt b/test/markup/handlebars/helper-parameters.expect.txt new file mode 100644 index 0000000000..fd1b7d3828 --- /dev/null +++ b/test/markup/handlebars/helper-parameters.expect.txt @@ -0,0 +1,8 @@ +Simple helper parameters: + +{{helper param1 param2}} +... +{{helper param1 key=value}} +... +Done + diff --git a/test/markup/handlebars/helper-parameters.txt b/test/markup/handlebars/helper-parameters.txt new file mode 100644 index 0000000000..f8c1086a05 --- /dev/null +++ b/test/markup/handlebars/helper-parameters.txt @@ -0,0 +1,7 @@ +Simple helper parameters: + +{{helper param1 param2}} +... +{{helper param1 key=value}} +... +Done diff --git a/test/markup/handlebars/helper-subexpressions.expect.txt b/test/markup/handlebars/helper-subexpressions.expect.txt new file mode 100644 index 0000000000..2d01058860 --- /dev/null +++ b/test/markup/handlebars/helper-subexpressions.expect.txt @@ -0,0 +1,10 @@ +Helper calls with sub-expressions and hashes: + +{{helper (helper param)}} +... +{{helper (helper param) param}} +... +{{helper (helper param key=value) (helper key=value)}} +... +Done + diff --git a/test/markup/handlebars/helper-subexpressions.txt b/test/markup/handlebars/helper-subexpressions.txt new file mode 100644 index 0000000000..42fb47e8d8 --- /dev/null +++ b/test/markup/handlebars/helper-subexpressions.txt @@ -0,0 +1,9 @@ +Helper calls with sub-expressions and hashes: + +{{helper (helper param)}} +... +{{helper (helper param) param}} +... +{{helper (helper param key=value) (helper key=value)}} +... +Done diff --git a/test/markup/handlebars/literals.expect.txt b/test/markup/handlebars/literals.expect.txt new file mode 100644 index 0000000000..7563b859a1 --- /dev/null +++ b/test/markup/handlebars/literals.expect.txt @@ -0,0 +1,52 @@ +Raw blocks: + +{{helper true false a=true b=false}} +... +{{#helper true false a=true b=false}} {{/helper}} +... +{{helper (helper true false a=true b=false)}} +... + +{{helper 1234 a=1234}} +... +{{#helper 1234 a=1234}} {{/helper}} +... +{{helper (helper 1234 a=1234)}} +... + +{{helper null a=null}} +... +{{#helper null a=null}} {{/helper}} +... +{{helper (helper null a=null)}} +... + +{{helper undefined a=undefined}} +... +{{#helper undefined a=undefined}} {{/helper}} +... +{{helper (helper undefined a=undefined)}} +... + +{{helper 'string' a='string'}} +... +{{#helper 'string' a='string'}} {{/helper}} +... +{{helper (helper 'string' a='string')}} +... + +{{helper "string" a="string"}} +... +{{#helper "string" a="string"}} {{/helper}} +... +{{helper (helper "string" a="string")}} +... + +{{helper [not a string literal] a=[not a string literal]}} +... +{{#helper [not a string literal] a=[not a string literal]}} {{/helper}} +... +{{helper (helper [not a string literal] a=[not a string literal])}} +... +Done + diff --git a/test/markup/handlebars/literals.txt b/test/markup/handlebars/literals.txt new file mode 100644 index 0000000000..f372934e29 --- /dev/null +++ b/test/markup/handlebars/literals.txt @@ -0,0 +1,51 @@ +Raw blocks: + +{{helper true false a=true b=false}} +... +{{#helper true false a=true b=false}} {{/helper}} +... +{{helper (helper true false a=true b=false)}} +... + +{{helper 1234 a=1234}} +... +{{#helper 1234 a=1234}} {{/helper}} +... +{{helper (helper 1234 a=1234)}} +... + +{{helper null a=null}} +... +{{#helper null a=null}} {{/helper}} +... +{{helper (helper null a=null)}} +... + +{{helper undefined a=undefined}} +... +{{#helper undefined a=undefined}} {{/helper}} +... +{{helper (helper undefined a=undefined)}} +... + +{{helper 'string' a='string'}} +... +{{#helper 'string' a='string'}} {{/helper}} +... +{{helper (helper 'string' a='string')}} +... + +{{helper "string" a="string"}} +... +{{#helper "string" a="string"}} {{/helper}} +... +{{helper (helper "string" a="string")}} +... + +{{helper [not a string literal] a=[not a string literal]}} +... +{{#helper [not a string literal] a=[not a string literal]}} {{/helper}} +... +{{helper (helper [not a string literal] a=[not a string literal])}} +... +Done diff --git a/test/markup/handlebars/partial-call.expect.txt b/test/markup/handlebars/partial-call.expect.txt index 139b33a8f4..a215e99776 100644 --- a/test/markup/handlebars/partial-call.expect.txt +++ b/test/markup/handlebars/partial-call.expect.txt @@ -1,2 +1,12 @@ -{{> partial}} +Partial call: + +{{> partial1}} +... +{{> partial1 param}} +... +{{> partial1 key=value}} +... +{{> partial1 (helper param) key=value}} +... +Done diff --git a/test/markup/handlebars/partial-call.txt b/test/markup/handlebars/partial-call.txt index f38a1409f5..d71a447a9d 100644 --- a/test/markup/handlebars/partial-call.txt +++ b/test/markup/handlebars/partial-call.txt @@ -1 +1,11 @@ -{{> partial}} +Partial call: + +{{> partial1}} +... +{{> partial1 param}} +... +{{> partial1 key=value}} +... +{{> partial1 (helper param) key=value}} +... +Done diff --git a/test/markup/handlebars/path-expressions.txt b/test/markup/handlebars/path-expressions.txt new file mode 100644 index 0000000000..451b92f2a8 --- /dev/null +++ b/test/markup/handlebars/path-expressions.txt @@ -0,0 +1,15 @@ +Path expressions (no builtins and should highlight the whole path): + +{{with.in.path}} +... +{{#with.in.path}} {{/with.in.path}} +... +{{highlighted.path}} +... +{{highlighted.path param}} +... +{{#highlighted.path}} {{/highlighted.path}} +... +{{#highlighted.path param }} {{/highlighted.path}} +... +Done diff --git a/test/markup/handlebars/raw-block.expect.txt b/test/markup/handlebars/raw-block.expect.txt index 93b0a0558d..ba27b9063b 100644 --- a/test/markup/handlebars/raw-block.expect.txt +++ b/test/markup/handlebars/raw-block.expect.txt @@ -1,2 +1,12 @@ -{{{{#raw}}}} {{verbatim}} content {{{{/raw}}}} {{var}} +Raw blocks: + +{{{{#raw}}}} {{verbatim}} content {{{{/raw}}}} {{var}} +... +{{{{#raw param}}}} {{verbatim}} content {{{{/raw}}}} {{var}} +... +{{{{#raw key=value}}}} {{verbatim}} content {{{{/raw}}}} {{var}} +... +{{{{#raw (helper param) key=value}}}} {{verbatim}} content {{{{/raw}}}} {{var}} +... +Done diff --git a/test/markup/handlebars/raw-block.txt b/test/markup/handlebars/raw-block.txt index e336350d49..43501907ef 100644 --- a/test/markup/handlebars/raw-block.txt +++ b/test/markup/handlebars/raw-block.txt @@ -1 +1,11 @@ +Raw blocks: + {{{{#raw}}}} {{verbatim}} content {{{{/raw}}}} {{var}} +... +{{{{#raw param}}}} {{verbatim}} content {{{{/raw}}}} {{var}} +... +{{{{#raw key=value}}}} {{verbatim}} content {{{{/raw}}}} {{var}} +... +{{{{#raw (helper param) key=value}}}} {{verbatim}} content {{{{/raw}}}} {{var}} +... +Done diff --git a/test/markup/handlebars/simple-expression.expect.txt b/test/markup/handlebars/simple-expression.expect.txt index c243c13ba1..95e33eed29 100644 --- a/test/markup/handlebars/simple-expression.expect.txt +++ b/test/markup/handlebars/simple-expression.expect.txt @@ -1,2 +1,6 @@ -{{abc}} +Simple expression: + +{{abc}} +... +Done diff --git a/test/markup/handlebars/simple-expression.txt b/test/markup/handlebars/simple-expression.txt index 4807ddb625..4f57e98061 100644 --- a/test/markup/handlebars/simple-expression.txt +++ b/test/markup/handlebars/simple-expression.txt @@ -1 +1,5 @@ +Simple expression: + {{abc}} +... +Done diff --git a/test/markup/handlebars/sub-expressions.expect.txt b/test/markup/handlebars/sub-expressions.expect.txt deleted file mode 100644 index d8bf1c4c32..0000000000 --- a/test/markup/handlebars/sub-expressions.expect.txt +++ /dev/null @@ -1,2 +0,0 @@ -{{helper (subExpression 1 2)}} - diff --git a/test/markup/handlebars/sub-expressions.txt b/test/markup/handlebars/sub-expressions.txt deleted file mode 100644 index 55f2b34547..0000000000 --- a/test/markup/handlebars/sub-expressions.txt +++ /dev/null @@ -1 +0,0 @@ -{{helper (subExpression 1 2)}} diff --git a/test/markup/handlebars/triple-mustache.expect.txt b/test/markup/handlebars/triple-mustache.expect.txt index b2fb748b97..7f8342e4a7 100644 --- a/test/markup/handlebars/triple-mustache.expect.txt +++ b/test/markup/handlebars/triple-mustache.expect.txt @@ -1,2 +1,12 @@ -{{{raw}}} +Triple mustaches: + +{{{raw}}} +... +{{{raw param}}} +... +{{{raw key=value}}} +... +{{{raw (helper value)}}} +... +Done diff --git a/test/markup/handlebars/triple-mustache.txt b/test/markup/handlebars/triple-mustache.txt index 359041b361..abe9224171 100644 --- a/test/markup/handlebars/triple-mustache.txt +++ b/test/markup/handlebars/triple-mustache.txt @@ -1 +1,11 @@ +Triple mustaches: + {{{raw}}} +... +{{{raw param}}} +... +{{{raw key=value}}} +... +{{{raw (helper value)}}} +... +Done