Skip to content

Commit 3357dc4

Browse files
author
Matthew Flaschen
committed
Add missing reserved words so compiler knows to use array syntax:
* 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.
1 parent c5fe252 commit 3357dc4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/handlebars/compiler/javascript-compiler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,8 @@ var reservedWords = (
10251025
" class float package throws" +
10261026
" const goto private transient" +
10271027
" debugger implements protected volatile" +
1028-
" double import public let yield"
1028+
" double import public let yield await" +
1029+
" null true false"
10291030
).split(" ");
10301031

10311032
var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};

spec/javascript-compiler.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/*global Handlebars, beforeEach, handlebarsEnv, shouldCompileTo */
2+
3+
var assert = require('assert');
4+
25
describe('javascript-compiler api', function() {
36
if (!Handlebars.JavaScriptCompiler) {
47
return;
@@ -19,6 +22,16 @@ describe('javascript-compiler api', function() {
1922
};
2023
shouldCompileTo("{{foo}}", { bar_foo: "food" }, "food");
2124
});
25+
26+
it('should compile with dot if not reserved', function() {
27+
var actual = handlebarsEnv.JavaScriptCompiler.prototype.nameLookup('parent', 'normalProperty');
28+
assert.deepEqual(actual, ["parent", ".", "normalProperty"]);
29+
});
30+
31+
it('should handle reserved words', function() {
32+
var actual = handlebarsEnv.JavaScriptCompiler.prototype.nameLookup('parent', 'null');
33+
assert.deepEqual(actual, ["parent", "['", "null", "']"]);
34+
});
2235
});
2336
describe('#compilerInfo', function() {
2437
var $superCheck, $superInfo;

0 commit comments

Comments
 (0)