From 9f265b97614e5c4763dc3d2d7343fc2472a6cc1a Mon Sep 17 00:00:00 2001 From: kpdecker Date: Mon, 3 Aug 2015 12:13:24 -0500 Subject: Handle this references properly in track id mode --- lib/handlebars/compiler/compiler.js | 5 +++-- 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; } -- cgit v1.1