summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2014-11-26 20:35:33 -0600
committerkpdecker <kpdecker@gmail.com>2014-11-26 20:36:36 -0600
commit5c921cafebee438fa27d417ae701b24323373a30 (patch)
treeb83b875444816351d3e45f13e8ddf3769294cad1 /lib/handlebars/compiler/compiler.js
parent697bbe59cad06bc74a945f7e26fc0af333a01d47 (diff)
downloadhandlebars.js-5c921cafebee438fa27d417ae701b24323373a30.zip
handlebars.js-5c921cafebee438fa27d417ae701b24323373a30.tar.gz
handlebars.js-5c921cafebee438fa27d417ae701b24323373a30.tar.bz2
Replace DataNode and IdNode with PathNode
This is a breaking change for string mode users as there is no longer a distinct type for data parameters. Instead data consumers should look for the @ prefix value.
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js39
1 files changed, 24 insertions, 15 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index a5acb64..ea65583 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -212,7 +212,7 @@ Compiler.prototype = {
this.opcode('pushProgram', sexpr, program);
this.opcode('pushProgram', sexpr, inverse);
- this.ID(id);
+ this.accept(id);
this.opcode('invokeAmbiguous', sexpr, name, isBlock);
},
@@ -220,10 +220,8 @@ Compiler.prototype = {
simpleSexpr: function(sexpr) {
var id = sexpr.id;
- if (id.type === 'DATA') {
- this.DATA(id);
- } else if (id.parts.length) {
- this.ID(id);
+ if (id.parts.length) {
+ this.accept(id);
} else {
// Simplified ID for `this`
this.addDepth(id.depth);
@@ -246,7 +244,7 @@ Compiler.prototype = {
} else {
id.falsy = true;
- this.ID(id);
+ this.accept(id);
this.opcode('invokeHelper', sexpr, params.length, id.original, id.isSimple);
}
},
@@ -265,7 +263,7 @@ Compiler.prototype = {
this.opcode('popHash', hash);
},
- ID: function(id) {
+ PathExpression: function(id) {
this.addDepth(id.depth);
this.opcode('getContext', id, id.depth);
@@ -273,16 +271,14 @@ Compiler.prototype = {
if (!name) {
// Context reference, i.e. `{{foo .}}` or `{{foo ..}}`
this.opcode('pushContext', id);
+ } else if (id.data) {
+ this.options.data = true;
+ this.opcode('lookupData', id, id.depth, id.parts);
} else {
this.opcode('lookupOnContext', id, id.parts, id.falsy, id.isScoped);
}
},
- DATA: function(data) {
- this.options.data = true;
- this.opcode('lookupData', data, data.id.depth, data.id.parts);
- },
-
StringLiteral: function(string) {
this.opcode('pushString', string, string.value);
},
@@ -338,14 +334,20 @@ Compiler.prototype = {
},
pushParam: function(val) {
- var stringModeValue = val.stringModeValue || (val.value != null ? val.value : '');
+ var value = val.value != null ? val.value : val.original || '';
if (this.stringParams) {
+ if (value.replace) {
+ value = value
+ .replace(/^(\.?\.\/)*/g, '')
+ .replace(/\//g, '.');
+ }
+
if(val.depth) {
this.addDepth(val.depth);
}
this.opcode('getContext', val, val.depth || 0);
- this.opcode('pushStringParam', val, stringModeValue, val.type);
+ this.opcode('pushStringParam', val, value, val.type);
if (val.type === 'sexpr') {
// Subexpressions get evaluated and passed in
@@ -354,7 +356,14 @@ Compiler.prototype = {
}
} else {
if (this.trackIds) {
- this.opcode('pushId', val, val.type, val.idName || stringModeValue);
+ value = val.original || value;
+ if (value.replace) {
+ value = value
+ .replace(/^\.\//g, '')
+ .replace(/^\.$/g, '');
+ }
+
+ this.opcode('pushId', val, val.type, value);
}
this.accept(val);
}