diff options
author | kpdecker <kpdecker@gmail.com> | 2015-08-22 10:57:24 -0700 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-08-22 10:58:44 -0700 |
commit | 2571dd8e8e43fd320672763564b16a5b3ae33966 (patch) | |
tree | b3cdd821bc239f9c57d2bf2b090c7191b09494fb | |
parent | 729d9fdffe92d7fbe9e5b2aa3fc46c2b1632683a (diff) | |
download | handlebars.js-2571dd8e8e43fd320672763564b16a5b3ae33966.zip handlebars.js-2571dd8e8e43fd320672763564b16a5b3ae33966.tar.gz handlebars.js-2571dd8e8e43fd320672763564b16a5b3ae33966.tar.bz2 |
Improve sanity checks in compiler and visitor
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 5 | ||||
-rw-r--r-- | lib/handlebars/compiler/visitor.js | 10 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index c8db7c9..ad6b861 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -90,6 +90,11 @@ Compiler.prototype = { }, accept: function(node) { + /* istanbul ignore next: Sanity code */ + if (!this[node.type]) { + throw new Exception('Unknown type: ' + node.type, node); + } + this.sourceNode.unshift(node); let ret = this[node.type](node); this.sourceNode.shift(); diff --git a/lib/handlebars/compiler/visitor.js b/lib/handlebars/compiler/visitor.js index 47f86e0..89dd632 100644 --- a/lib/handlebars/compiler/visitor.js +++ b/lib/handlebars/compiler/visitor.js @@ -12,8 +12,9 @@ Visitor.prototype = { acceptKey: function(node, name) { let value = this.accept(node[name]); if (this.mutating) { - // Hacky sanity check: - if (value && typeof value.type !== 'string') { + // Hacky sanity check: This may have a few false positives for type for the helper + // methods but will generally do the right thing without a lot of overhead. + if (value && !Visitor.prototype[value.type]) { throw new Exception('Unexpected node type "' + value.type + '" found when accepting ' + name + ' on ' + node.type); } node[name] = value; @@ -49,6 +50,11 @@ Visitor.prototype = { return; } + /* istanbul ignore next: Sanity code */ + if (!this[object.type]) { + throw new Exception('Unknown type: ' + object.type, object); + } + if (this.current) { this.parents.unshift(this.current); } |