Skip to content

Commit bcf38f3

Browse files
maxnordlundfdintino
authored andcommittedMar 4, 2019
Emit line and column info for functions
This makes certain errors better by providing an accurate location.
1 parent fbddcd5 commit bcf38f3

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed
 

‎nunjucks/src/compiler.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ class Compiler extends Obj {
6767
lines.forEach((line) => this._emitLine(line));
6868
}
6969

70-
_emitFuncBegin(name) {
70+
_emitFuncBegin(node, name) {
7171
this.buffer = 'output';
7272
this._scopeClosers = '';
73-
this._emitLine('function ' + name + '(env, context, frame, runtime, cb) {');
74-
this._emitLine('var lineno = null;');
75-
this._emitLine('var colno = null;');
76-
this._emitLine('var ' + this.buffer + ' = "";');
73+
this._emitLine(`function ${name}(env, context, frame, runtime, cb) {`);
74+
this._emitLine(`var lineno = ${node.lineno};`);
75+
this._emitLine(`var colno = ${node.colno};`);
76+
this._emitLine(`var ${this.buffer} = "";`);
7777
this._emitLine('try {');
7878
}
7979

@@ -1123,7 +1123,7 @@ class Compiler extends Obj {
11231123

11241124
frame = new Frame();
11251125

1126-
this._emitFuncBegin('root');
1126+
this._emitFuncBegin(node, 'root');
11271127
this._emitLine('var parentTemplate = null;');
11281128
this._compileChildren(node, frame);
11291129
this._emitLine('if(parentTemplate) {');
@@ -1147,7 +1147,7 @@ class Compiler extends Obj {
11471147
}
11481148
blockNames.push(name);
11491149

1150-
this._emitFuncBegin(`b_${name}`);
1150+
this._emitFuncBegin(block, `b_${name}`);
11511151

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

0 commit comments

Comments
 (0)
Please sign in to comment.