Skip to content

Commit 9f265b9

Browse files
committed
Handle this references properly in track id mode
1 parent 0aa54f4 commit 9f265b9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/handlebars/compiler/compiler.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,9 @@ Compiler.prototype = {
390390
value = val.original || value;
391391
if (value.replace) {
392392
value = value
393-
.replace(/^\.\//g, '')
394-
.replace(/^\.$/g, '');
393+
.replace(/^this(?:\.|$)/, '')
394+
.replace(/^\.\//, '')
395+
.replace(/^\.$/, '');
395396
}
396397

397398
this.opcode('pushId', val.type, value);

spec/track-ids.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ describe('track ids', function() {
4747
equals(template(context, {helpers: helpers}), 'HELP ME MY BOSS is.a:foo slave.driver:bar');
4848
});
4949
it('should note ../ and ./ references', function() {
50-
var template = CompilerContext.compile('{{wycats ./is.a ../slave.driver}}', {trackIds: true});
50+
var template = CompilerContext.compile('{{wycats ./is.a ../slave.driver this.is.a this}}', {trackIds: true});
5151

5252
var helpers = {
53-
wycats: function(passiveVoice, noun, options) {
53+
wycats: function(passiveVoice, noun, thiz, thiz2, options) {
5454
equal(options.ids[0], 'is.a');
5555
equal(options.ids[1], '../slave.driver');
56+
equal(options.ids[2], 'is.a');
57+
equal(options.ids[3], '');
5658

5759
return 'HELP ME MY BOSS ' + options.ids[0] + ':' + passiveVoice + ' ' + options.ids[1] + ':' + noun;
5860
}

0 commit comments

Comments
 (0)