summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2014-11-06 09:44:38 -0600
committerkpdecker <kpdecker@gmail.com>2014-11-08 17:50:01 -0600
commit249f559104cb7f85736e7e83e38ccc67b9b84bf6 (patch)
tree5afde51b101a99ce2ddcba01cc973b1789c78fa2 /lib/handlebars/compiler/compiler.js
parentea6b0be910d3fb0178d8e2d1fcc54c17b8d3a94f (diff)
downloadhandlebars.js-249f559104cb7f85736e7e83e38ccc67b9b84bf6.zip
handlebars.js-249f559104cb7f85736e7e83e38ccc67b9b84bf6.tar.gz
handlebars.js-249f559104cb7f85736e7e83e38ccc67b9b84bf6.tar.bz2
Include location information in all opcodes
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js94
1 files changed, 49 insertions, 45 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 1303d8f..a75fc4a 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -130,36 +130,36 @@ Compiler.prototype = {
// now that the simple mustache is resolved, we need to
// evaluate it by executing `blockHelperMissing`
- this.opcode('pushProgram', program);
- this.opcode('pushProgram', inverse);
- this.opcode('emptyHash');
- this.opcode('blockValue', sexpr.id.original);
+ this.opcode('pushProgram', block, program);
+ this.opcode('pushProgram', block, inverse);
+ this.opcode('emptyHash', block);
+ this.opcode('blockValue', block, sexpr.id.original);
} else {
this.ambiguousSexpr(sexpr, program, inverse);
// now that the simple mustache is resolved, we need to
// evaluate it by executing `blockHelperMissing`
- this.opcode('pushProgram', program);
- this.opcode('pushProgram', inverse);
- this.opcode('emptyHash');
- this.opcode('ambiguousBlockValue');
+ this.opcode('pushProgram', block, program);
+ this.opcode('pushProgram', block, inverse);
+ this.opcode('emptyHash', block);
+ this.opcode('ambiguousBlockValue', block);
}
- this.opcode('append');
+ this.opcode('append', block);
},
hash: function(hash) {
var pairs = hash.pairs, i, l;
- this.opcode('pushHash');
+ this.opcode('pushHash', hash);
for(i=0, l=pairs.length; i<l; i++) {
this.pushParam(pairs[i][1]);
}
while(i--) {
- this.opcode('assignToHash', pairs[i][0]);
+ this.opcode('assignToHash', hash, pairs[i][0]);
}
- this.opcode('popHash');
+ this.opcode('popHash', hash);
},
partial: function(partial) {
@@ -169,28 +169,28 @@ Compiler.prototype = {
if (partial.hash) {
this.accept(partial.hash);
} else {
- this.opcode('push', 'undefined');
+ this.opcode('pushLiteral', partial, 'undefined');
}
if (partial.context) {
this.accept(partial.context);
} else {
- this.opcode('getContext', 0);
- this.opcode('pushContext');
+ this.opcode('getContext', partial, 0);
+ this.opcode('pushContext', partial);
}
var indent = partial.indent || '';
if (this.options.preventIndent && indent) {
- this.opcode('appendContent', indent);
+ this.opcode('appendContent', partial, indent);
indent = '';
}
- this.opcode('invokePartial', partialName.name, indent);
- this.opcode('append');
+ this.opcode('invokePartial', partial, partialName.name, indent);
+ this.opcode('append', partial);
},
content: function(content) {
if (content.string) {
- this.opcode('appendContent', content.string);
+ this.opcode('appendContent', content, content.string);
}
},
@@ -198,9 +198,9 @@ Compiler.prototype = {
this.sexpr(mustache.sexpr);
if(mustache.escaped && !this.options.noEscape) {
- this.opcode('appendEscaped');
+ this.opcode('appendEscaped', mustache);
} else {
- this.opcode('append');
+ this.opcode('append', mustache);
}
},
@@ -209,14 +209,14 @@ Compiler.prototype = {
name = id.parts[0],
isBlock = program != null || inverse != null;
- this.opcode('getContext', id.depth);
+ this.opcode('getContext', sexpr, id.depth);
- this.opcode('pushProgram', program);
- this.opcode('pushProgram', inverse);
+ this.opcode('pushProgram', sexpr, program);
+ this.opcode('pushProgram', sexpr, inverse);
this.ID(id);
- this.opcode('invokeAmbiguous', name, isBlock);
+ this.opcode('invokeAmbiguous', sexpr, name, isBlock);
},
simpleSexpr: function(sexpr) {
@@ -229,11 +229,11 @@ Compiler.prototype = {
} else {
// Simplified ID for `this`
this.addDepth(id.depth);
- this.opcode('getContext', id.depth);
- this.opcode('pushContext');
+ this.opcode('getContext', sexpr, id.depth);
+ this.opcode('pushContext', sexpr);
}
- this.opcode('resolvePossibleLambda');
+ this.opcode('resolvePossibleLambda', sexpr);
},
helperSexpr: function(sexpr, program, inverse) {
@@ -242,14 +242,14 @@ Compiler.prototype = {
name = id.parts[0];
if (this.options.knownHelpers[name]) {
- this.opcode('invokeKnownHelper', params.length, name);
+ this.opcode('invokeKnownHelper', sexpr, params.length, name);
} else if (this.options.knownHelpersOnly) {
throw new Exception("You specified knownHelpersOnly, but used the unknown helper " + name, sexpr);
} else {
id.falsy = true;
this.ID(id);
- this.opcode('invokeHelper', params.length, id.original, id.isSimple);
+ this.opcode('invokeHelper', sexpr, params.length, id.original, id.isSimple);
}
},
@@ -267,39 +267,43 @@ Compiler.prototype = {
ID: function(id) {
this.addDepth(id.depth);
- this.opcode('getContext', id.depth);
+ this.opcode('getContext', id, id.depth);
var name = id.parts[0];
if (!name) {
// Context reference, i.e. `{{foo .}}` or `{{foo ..}}`
- this.opcode('pushContext');
+ this.opcode('pushContext', id);
} else {
- this.opcode('lookupOnContext', id.parts, id.falsy, id.isScoped);
+ this.opcode('lookupOnContext', id, id.parts, id.falsy, id.isScoped);
}
},
DATA: function(data) {
this.options.data = true;
- this.opcode('lookupData', data.id.depth, data.id.parts);
+ this.opcode('lookupData', data, data.id.depth, data.id.parts);
},
STRING: function(string) {
- this.opcode('pushString', string.string);
+ this.opcode('pushString', string, string.string);
},
NUMBER: function(number) {
- this.opcode('pushLiteral', number.number);
+ this.opcode('pushLiteral', number, number.number);
},
BOOLEAN: function(bool) {
- this.opcode('pushLiteral', bool.bool);
+ this.opcode('pushLiteral', bool, bool.bool);
},
comment: function() {},
// HELPERS
- opcode: function(name) {
- this.opcodes.push({ opcode: name, args: slice.call(arguments, 1) });
+ opcode: function(name, node) {
+ var loc = {
+ firstLine: node.firstLine, firstColumn: node.firstColumn,
+ lastLine: node.lastLine, lastColumn: node.lastColumn
+ };
+ this.opcodes.push({ opcode: name, args: slice.call(arguments, 2), loc: loc });
},
addDepth: function(depth) {
@@ -344,8 +348,8 @@ Compiler.prototype = {
if(val.depth) {
this.addDepth(val.depth);
}
- this.opcode('getContext', val.depth || 0);
- this.opcode('pushStringParam', val.stringModeValue, val.type);
+ this.opcode('getContext', val, val.depth || 0);
+ this.opcode('pushStringParam', val, val.stringModeValue, val.type);
if (val.type === 'sexpr') {
// Subexpressions get evaluated and passed in
@@ -354,7 +358,7 @@ Compiler.prototype = {
}
} else {
if (this.trackIds) {
- this.opcode('pushId', val.type, val.idName || val.stringModeValue);
+ this.opcode('pushId', val, val.type, val.idName || val.stringModeValue);
}
this.accept(val);
}
@@ -364,13 +368,13 @@ Compiler.prototype = {
var params = sexpr.params;
this.pushParams(params);
- this.opcode('pushProgram', program);
- this.opcode('pushProgram', inverse);
+ this.opcode('pushProgram', sexpr, program);
+ this.opcode('pushProgram', sexpr, inverse);
if (sexpr.hash) {
this.hash(sexpr.hash);
} else {
- this.opcode('emptyHash');
+ this.opcode('emptyHash', sexpr);
}
return params;