summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/helpers.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-04-14 01:12:39 -0500
committerkpdecker <kpdecker@gmail.com>2015-04-14 01:12:39 -0500
commit54e743a09a0e7524edd9e76c029eff53a90f9cba (patch)
tree816918e199201c19e81c15a72f64e8562e1163aa /lib/handlebars/compiler/helpers.js
parenta7160a8d2745de95cb9da7d20ff02795b0d3f784 (diff)
downloadhandlebars.js-54e743a09a0e7524edd9e76c029eff53a90f9cba.zip
handlebars.js-54e743a09a0e7524edd9e76c029eff53a90f9cba.tar.gz
handlebars.js-54e743a09a0e7524edd9e76c029eff53a90f9cba.tar.bz2
Allow this references in literal statements
Fixes #967
Diffstat (limited to 'lib/handlebars/compiler/helpers.js')
-rw-r--r--lib/handlebars/compiler/helpers.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/handlebars/compiler/helpers.js b/lib/handlebars/compiler/helpers.js
index beaf988..4a502d8 100644
--- a/lib/handlebars/compiler/helpers.js
+++ b/lib/handlebars/compiler/helpers.js
@@ -12,6 +12,14 @@ export function SourceLocation(source, locInfo) {
};
}
+export function id(token) {
+ if (/^\[.*\]$/.test(token)) {
+ return token.substr(1, token.length - 2);
+ } else {
+ return token;
+ }
+}
+
export function stripFlags(open, close) {
return {
open: open.charAt(2) === '~',
@@ -34,10 +42,13 @@ export function preparePath(data, parts, locInfo) {
depthString = '';
for(var i=0,l=parts.length; i<l; i++) {
- var part = parts[i].part;
+ var part = parts[i].part,
+ // If we have [] syntax then we do not treat path references as operators,
+ // i.e. foo.[this] resolves to approximately context.foo['this']
+ isLiteral = parts[i].original !== part;
original += (parts[i].separator || '') + part;
- if (part === '..' || part === '.' || part === 'this') {
+ if (!isLiteral && (part === '..' || part === '.' || part === 'this')) {
if (dig.length > 0) {
throw new Exception('Invalid path: ' + original, {loc: locInfo});
} else if (part === '..') {