diff --git a/packages/spacebars-compiler/codegen.js b/packages/spacebars-compiler/codegen.js index 8641e9d9e4..3c8e142c39 100644 --- a/packages/spacebars-compiler/codegen.js +++ b/packages/spacebars-compiler/codegen.js @@ -150,6 +150,8 @@ _.extend(CodeGen.prototype, { return BlazeTools.EmitCode(includeCode); } + } else if (tag.type === 'ESCAPE') { + return HTML.Raw(tag.value); } else { // Can't get here; TemplateTag validation should catch any // inappropriate tag types that might come out of the parser. diff --git a/packages/spacebars-compiler/spacebars_tests.js b/packages/spacebars-compiler/spacebars_tests.js index f86fe9fab6..f5ab56c3d4 100644 --- a/packages/spacebars-compiler/spacebars_tests.js +++ b/packages/spacebars-compiler/spacebars_tests.js @@ -164,6 +164,9 @@ Tinytest.add("spacebars-compiler - stache tags", function (test) { run('{{foo "="}}', {type: 'DOUBLE', path: ['foo'], args: [['STRING', '=']]}); + run('{{| asdf', { type: 'ESCAPE', value: '{{' }); + run('{{{| asdf', { type: 'ESCAPE', value: '{{{' }); + run('{{{{| asdf', { type: 'ESCAPE', value: '{{{{' }); }); diff --git a/packages/spacebars-compiler/templatetag.js b/packages/spacebars-compiler/templatetag.js index e3ff5a789e..34b74cef14 100644 --- a/packages/spacebars-compiler/templatetag.js +++ b/packages/spacebars-compiler/templatetag.js @@ -12,6 +12,7 @@ SpacebarsCompiler = {}; // - `"BLOCKOPEN"` - `{{#foo}}` // - `"BLOCKCLOSE"` - `{{/foo}}` // - `"ELSE"` - `{{else}}` +// - `"ESCAPE"` - `{{|`, `{{{|`, `{{{{|` and so on // // Besides `type`, the mandatory properties of a TemplateTag are: // @@ -53,6 +54,7 @@ var makeStacheTagStartRegex = function (r) { }; var starts = { + ESCAPE: makeStacheTagStartRegex(/^[\{]{2,}\|/), ELSE: makeStacheTagStartRegex(/^\{\{\s*else(?=[\s}])/i), DOUBLE: makeStacheTagStartRegex(/^\{\{\s*(?!\s)/), TRIPLE: makeStacheTagStartRegex(/^\{\{\{\s*(?!\s)/), @@ -88,6 +90,7 @@ TemplateTag.parse = function (scannerOrString) { return null; var ret = result[0]; scanner.pos += ret.length; + scanner.current = ret; return ret; }; @@ -230,9 +233,10 @@ TemplateTag.parse = function (scannerOrString) { error('Expected ' + what); }; - // must do ELSE first; order of others doesn't matter - - if (run(starts.ELSE)) type = 'ELSE'; + // must do ESCAPE first, immediately followed by ELSE + // order of others doesn't matter + if (run(starts.ESCAPE)) type = 'ESCAPE'; + else if (run(starts.ELSE)) type = 'ELSE'; else if (run(starts.DOUBLE)) type = 'DOUBLE'; else if (run(starts.TRIPLE)) type = 'TRIPLE'; else if (run(starts.BLOCKCOMMENT)) type = 'BLOCKCOMMENT'; @@ -263,6 +267,8 @@ TemplateTag.parse = function (scannerOrString) { } else if (type === 'ELSE') { if (! run(ends.DOUBLE)) expected('`}}`'); + } else if (type === 'ESCAPE') { + tag.value = scanner.current.slice(0, -1); } else { // DOUBLE, TRIPLE, BLOCKOPEN, INCLUSION tag.path = scanPath();