Skip to content

Commit

Permalink
Emit line and column info for functions
Browse files Browse the repository at this point in the history
This makes certain errors better by providing an accurate location.
  • Loading branch information
maxnordlund authored and fdintino committed Mar 4, 2019
1 parent fbddcd5 commit bcf38f3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions nunjucks/src/compiler.js
Expand Up @@ -67,13 +67,13 @@ class Compiler extends Obj {
lines.forEach((line) => this._emitLine(line));
}

_emitFuncBegin(name) {
_emitFuncBegin(node, name) {
this.buffer = 'output';
this._scopeClosers = '';
this._emitLine('function ' + name + '(env, context, frame, runtime, cb) {');
this._emitLine('var lineno = null;');
this._emitLine('var colno = null;');
this._emitLine('var ' + this.buffer + ' = "";');
this._emitLine(`function ${name}(env, context, frame, runtime, cb) {`);
this._emitLine(`var lineno = ${node.lineno};`);
this._emitLine(`var colno = ${node.colno};`);
this._emitLine(`var ${this.buffer} = "";`);
this._emitLine('try {');
}

Expand Down Expand Up @@ -1123,7 +1123,7 @@ class Compiler extends Obj {

frame = new Frame();

this._emitFuncBegin('root');
this._emitFuncBegin(node, 'root');
this._emitLine('var parentTemplate = null;');
this._compileChildren(node, frame);
this._emitLine('if(parentTemplate) {');
Expand All @@ -1147,7 +1147,7 @@ class Compiler extends Obj {
}
blockNames.push(name);

this._emitFuncBegin(`b_${name}`);
this._emitFuncBegin(block, `b_${name}`);

const tmpFrame = new Frame();
this._emitLine('var frame = frame.push(true);');
Expand Down

0 comments on commit bcf38f3

Please sign in to comment.