Skip to content

Commit

Permalink
Add missing reserved words so compiler knows to use array syntax:
Browse files Browse the repository at this point in the history
* await
* null
* true
* false

IE 8 was failing to compile Handlebars-generated source code
because it had helpers.null.

I came up with this list by diffing
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords
against the ones Handlebars already had.

I added two corresponding tests for nameLookup.
  • Loading branch information
Matthew Flaschen committed Jan 17, 2015
1 parent c5fe252 commit 3357dc4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,8 @@ var reservedWords = (
" class float package throws" +
" const goto private transient" +
" debugger implements protected volatile" +
" double import public let yield"
" double import public let yield await" +
" null true false"
).split(" ");

var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
Expand Down
13 changes: 13 additions & 0 deletions spec/javascript-compiler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/*global Handlebars, beforeEach, handlebarsEnv, shouldCompileTo */

var assert = require('assert');

describe('javascript-compiler api', function() {
if (!Handlebars.JavaScriptCompiler) {
return;
Expand All @@ -19,6 +22,16 @@ describe('javascript-compiler api', function() {
};
shouldCompileTo("{{foo}}", { bar_foo: "food" }, "food");
});

it('should compile with dot if not reserved', function() {
var actual = handlebarsEnv.JavaScriptCompiler.prototype.nameLookup('parent', 'normalProperty');
assert.deepEqual(actual, ["parent", ".", "normalProperty"]);
});

it('should handle reserved words', function() {
var actual = handlebarsEnv.JavaScriptCompiler.prototype.nameLookup('parent', 'null');
assert.deepEqual(actual, ["parent", "['", "null", "']"]);
});
});
describe('#compilerInfo', function() {
var $superCheck, $superInfo;
Expand Down

0 comments on commit 3357dc4

Please sign in to comment.