summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/handlebars/vm.js2
-rw-r--r--spec/parser_spec.rb4
-rw-r--r--spec/qunit_spec.js4
-rw-r--r--src/handlebars.l2
4 files changed, 10 insertions, 2 deletions
diff --git a/lib/handlebars/vm.js b/lib/handlebars/vm.js
index 48e937c..ec27744 100644
--- a/lib/handlebars/vm.js
+++ b/lib/handlebars/vm.js
@@ -273,7 +273,7 @@ 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]) {
+ if(JavaScriptCompiler.RESERVED_WORDS[name] || name.indexOf('-') !== -1) {
return parent + "['" + name + "']";
} else {
return parent + "." + name;
diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb
index 882085e..78ffa1e 100644
--- a/spec/parser_spec.rb
+++ b/spec/parser_spec.rb
@@ -117,6 +117,10 @@ describe "Parser" do
ast_for("{{this/foo}}").should == program { mustache id("foo") }
end
+ it "parses mustaches with - in a path" do
+ ast_for("{{foo-bar}}").should == program { mustache id("foo-bar") }
+ end
+
it "parses mustaches with parameters" do
ast_for("{{foo bar}}").should == program { mustache id("foo"), [id("bar")] }
end
diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js
index 241292d..e984969 100644
--- a/spec/qunit_spec.js
+++ b/spec/qunit_spec.js
@@ -107,6 +107,10 @@ test("functions with context argument", function() {
"Frank", "functions are called with context arguments");
});
+test("paths with hyphens", function() {
+ shouldCompileTo("{{foo-bar}}", {"foo-bar": "baz"}, "baz", "Paths can contain hyphens (-)");
+});
+
test("nested paths", function() {
shouldCompileTo("Goodbye {{alan/expression}} world!", {alan: {expression: "beautiful"}},
"Goodbye beautiful world!", "Nested paths access nested objects");
diff --git a/src/handlebars.l b/src/handlebars.l
index 24c3712..62b8adf 100644
--- a/src/handlebars.l
+++ b/src/handlebars.l
@@ -24,7 +24,7 @@
<mu>"}}}" { this.begin("INITIAL"); return 'CLOSE'; }
<mu>"}}" { this.begin("INITIAL"); return 'CLOSE'; }
<mu>'"'("\\"["]|[^"])*'"' { yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; }
-<mu>[a-zA-Z0-9_]+/[=} /.] { return 'ID'; }
+<mu>[a-zA-Z0-9_-]+/[=} /.] { return 'ID'; }
<mu>. { return 'INVALID'; }
<INITIAL,mu><<EOF>> { return 'EOF'; }