diff options
author | Alan Johnson <alan@commondream.net> | 2011-09-02 09:04:41 -0400 |
---|---|---|
committer | Alan Johnson <alan@commondream.net> | 2011-09-02 09:04:41 -0400 |
commit | fc84308cc9124c94dcd372629d15bd10ce30875d (patch) | |
tree | 6d36b6dcfa946127cebf01dff27921ef8b3f7e1e /lib/handlebars/compiler/compiler.js | |
parent | 91bbc4fd2ca1e161fad3fba0c51a3732216503b3 (diff) | |
download | handlebars.js-fc84308cc9124c94dcd372629d15bd10ce30875d.zip handlebars.js-fc84308cc9124c94dcd372629d15bd10ce30875d.tar.gz handlebars.js-fc84308cc9124c94dcd372629d15bd10ce30875d.tar.bz2 |
Got simple literal expressions added into paths.
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index a3fd120..86b7361 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -314,12 +314,13 @@ Handlebars.JavaScriptCompiler = function() {}; // PUBLIC API: You can override these methods in a subclass to provide // alternative compiled forms for name lookup and buffering semantics nameLookup: function(parent, name, type) { - if(JavaScriptCompiler.RESERVED_WORDS[name] || name.indexOf('-') !== -1 || !isNaN(name)) { - return parent + "['" + name + "']"; - } else if (/^[0-9]+$/.test(name)) { + if (/^[0-9]+$/.test(name)) { return parent + "[" + name + "]"; - } else { - return parent + "." + name; + } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) { + return parent + "." + name; + } + else { + return parent + "['" + name + "']"; } }, @@ -734,6 +735,13 @@ Handlebars.JavaScriptCompiler = function() {}; compilerWords[reservedWords[i]] = true; } + JavaScriptCompiler.isValidJavaScriptVariableName = function(name) { + if(!JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]+$/.test(name)) { + return true; + } + return false; + } + })(Handlebars.Compiler, Handlebars.JavaScriptCompiler); Handlebars.precompile = function(string, options) { |