diff options
author | kpdecker <kpdecker@gmail.com> | 2015-08-03 12:13:24 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-08-03 12:13:24 -0500 |
commit | 9f265b97614e5c4763dc3d2d7343fc2472a6cc1a (patch) | |
tree | b3303688c8fcf8e954771ceeae77dae862a2aec2 | |
parent | 0aa54f49de111d117e7d3b4a21e99b9fcaf483d1 (diff) | |
download | handlebars.js-9f265b97614e5c4763dc3d2d7343fc2472a6cc1a.zip handlebars.js-9f265b97614e5c4763dc3d2d7343fc2472a6cc1a.tar.gz handlebars.js-9f265b97614e5c4763dc3d2d7343fc2472a6cc1a.tar.bz2 |
Handle this references properly in track id mode
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 5 | ||||
-rw-r--r-- | spec/track-ids.js | 6 |
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 2448443..c1ef47e 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -390,8 +390,9 @@ Compiler.prototype = { value = val.original || value; if (value.replace) { value = value - .replace(/^\.\//g, '') - .replace(/^\.$/g, ''); + .replace(/^this(?:\.|$)/, '') + .replace(/^\.\//, '') + .replace(/^\.$/, ''); } this.opcode('pushId', val.type, value); diff --git a/spec/track-ids.js b/spec/track-ids.js index 7a8b59e..88db789 100644 --- a/spec/track-ids.js +++ b/spec/track-ids.js @@ -47,12 +47,14 @@ describe('track ids', function() { equals(template(context, {helpers: helpers}), 'HELP ME MY BOSS is.a:foo slave.driver:bar'); }); it('should note ../ and ./ references', function() { - var template = CompilerContext.compile('{{wycats ./is.a ../slave.driver}}', {trackIds: true}); + var template = CompilerContext.compile('{{wycats ./is.a ../slave.driver this.is.a this}}', {trackIds: true}); var helpers = { - wycats: function(passiveVoice, noun, options) { + wycats: function(passiveVoice, noun, thiz, thiz2, options) { equal(options.ids[0], 'is.a'); equal(options.ids[1], '../slave.driver'); + equal(options.ids[2], 'is.a'); + equal(options.ids[3], ''); return 'HELP ME MY BOSS ' + options.ids[0] + ':' + passiveVoice + ' ' + options.ids[1] + ':' + noun; } |