Include location information in all opcodes
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -84,6 +84,7 @@ JavaScriptCompiler.prototype = {
|
||||
for (i = 0, l = opcodes.length; i < l; i++) {
|
||||
opcode = opcodes[i];
|
||||
|
||||
this.currentLoc = opcode.loc;
|
||||
this[opcode.opcode].apply(this, opcode.args);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user