Skip to content

Commit

Permalink
Fix #375: Always resolve path when parentName is present
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed Feb 21, 2015
1 parent 0f4a85c commit 252b76a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/compiler.js
Expand Up @@ -27,7 +27,7 @@ function binOpEmitter(str) {

var Compiler = Object.extend({
init: function(templateName) {
this.templateName = templateName;
this.templateName = templateName || "";
this.codebuf = [];
this.lastId = 0;
this.buffer = null;
Expand Down Expand Up @@ -121,6 +121,10 @@ var Compiler = Object.extend({
return 't_' + this.lastId;
},

_templateName: function() {
return this.templateName == null? "undefined" : '"'+this.templateName.replace(/"/g, '\\"')+'"';
},

_bufferAppend: function(func) {
this.emit(this.buffer + ' += runtime.suppressValue(');
func.call(this);
Expand Down Expand Up @@ -885,7 +889,7 @@ var Compiler = Object.extend({

this.emit('env.getTemplate(');
this._compileExpression(node.template, frame);
this.emitLine(', false, "' + this.templateName + '", ' + this.makeCallback(id));
this.emitLine(', false, '+this._templateName()+', ' + this.makeCallback(id));
this.addScopeLevel();

this.emitLine(id + '.getExported(' +
Expand All @@ -908,7 +912,7 @@ var Compiler = Object.extend({

this.emit('env.getTemplate(');
this._compileExpression(node.template, frame);
this.emitLine(', false, "' + this.templateName + '", ' + this.makeCallback(importedId));
this.emitLine(', false, '+this._templateName()+', ' + this.makeCallback(importedId));
this.addScopeLevel();

this.emitLine(importedId + '.getExported(' +
Expand Down Expand Up @@ -983,7 +987,7 @@ var Compiler = Object.extend({

this.emit('env.getTemplate(');
this._compileExpression(node.template, frame);
this.emitLine(', true, "' + this.templateName + '", ' + this.makeCallback('parentTemplate'));
this.emitLine(', true, '+this._templateName()+', ' + this.makeCallback('parentTemplate'));

this.emitLine('for(var ' + k + ' in parentTemplate.blocks) {');
this.emitLine('context.addBlock(' + k +
Expand All @@ -1000,7 +1004,7 @@ var Compiler = Object.extend({

this.emit('env.getTemplate(');
this._compileExpression(node.template, frame);
this.emitLine(', false, "' + this.templateName + '", '+ this.makeCallback(id));
this.emitLine(', false, '+this._templateName()+', '+ this.makeCallback(id));
this.addScopeLevel();

this.emitLine(id + '.render(' +
Expand Down
7 changes: 2 additions & 5 deletions src/environment.js
Expand Up @@ -100,10 +100,7 @@ var Environment = Obj.extend({
},

getTemplate: function(name, eagerCompile, parentName, cb) {
var isRelative = (parentName && (name.indexOf("./") == 0 ||
name.indexOf("../") == 0));
var tmpl = null;

if(name && name.raw) {
// this fixes autoescape for templates referenced in symbols
name = name.raw;
Expand All @@ -125,7 +122,7 @@ var Environment = Obj.extend({
}

// Test cache
if (isRelative) {
if (parentName) {
for (var i = 0; i < this.loaders.length; i++) {
var _name = this.loaders[i].resolve(parentName, name);
tmpl = this.cache[_name];
Expand Down Expand Up @@ -160,7 +157,7 @@ var Environment = Obj.extend({
}

// Resolve name relative to parentName
if (isRelative) {
if (parentName) {
name = loader.resolve(parentName, name);
}

Expand Down

0 comments on commit 252b76a

Please sign in to comment.