diff --git a/packages/spacebars-compiler/spacebars_tests.js b/packages/spacebars-compiler/spacebars_tests.js index 43d56b67e5..778cc1a7e6 100644 --- a/packages/spacebars-compiler/spacebars_tests.js +++ b/packages/spacebars-compiler/spacebars_tests.js @@ -121,6 +121,12 @@ Tinytest.add("spacebars - stache tags", function (test) { ['NUMBER', 2, 'y']]}); run('{{> foo x=1 y=2 z}}', "Can't have a non-keyword argument"); + + run('{{true.foo}}', "Can't use"); + run('{{foo.this}}', "Can only use"); + run('{{./this}}', "Can only use"); + run('{{../this}}', "Can only use"); + }); diff --git a/packages/spacebars-compiler/templatetag.js b/packages/spacebars-compiler/templatetag.js index 2b58dbd848..552944c4cc 100644 --- a/packages/spacebars-compiler/templatetag.js +++ b/packages/spacebars-compiler/templatetag.js @@ -141,9 +141,13 @@ TemplateTag.parse = function (scannerOrString) { segments.push(seg); } else { var id = scanIdentifier(! segments.length); - if (id === 'this' && ! segments.length) { - // initial `this` - segments.push('.'); + if (id === 'this') { + if (! segments.length) { + // initial `this` + segments.push('.'); + } else { + error("Can only use `this` at the beginning of a path.\nInstead of `foo.this` or `../this`, just write `foo` or `..`."); + } } else { segments.push(id); }