diff options
author | kpdecker <kpdecker@gmail.com> | 2014-08-14 12:27:39 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-08-14 12:27:39 -0500 |
commit | 9e3f824bf57ed7f049314853782f61d258f3c7df (patch) | |
tree | f28e63dd9585b89fefee92ba577ab0eee2b498ff /lib/handlebars/compiler/compiler.js | |
parent | b94656a31fe783b5b4c29eab09e7e334e5113036 (diff) | |
download | handlebars.js-9e3f824bf57ed7f049314853782f61d258f3c7df.zip handlebars.js-9e3f824bf57ed7f049314853782f61d258f3c7df.tar.gz handlebars.js-9e3f824bf57ed7f049314853782f61d258f3c7df.tar.bz2 |
Fix compiler program de-duping
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 8cabbdd..a4bd09a 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -1,4 +1,5 @@ import Exception from "../exception"; +import {isArray} from "../utils"; export function Compiler() {} @@ -19,20 +20,14 @@ Compiler.prototype = { for (var i = 0; i < len; i++) { var opcode = this.opcodes[i], otherOpcode = other.opcodes[i]; - if (opcode.opcode !== otherOpcode.opcode || opcode.args.length !== otherOpcode.args.length) { + if (opcode.opcode !== otherOpcode.opcode || !argEquals(opcode.args, otherOpcode.args)) { return false; } - for (var j = 0; j < opcode.args.length; j++) { - if (opcode.args[j] !== otherOpcode.args[j]) { - return false; - } - } } + // We know that length is the same between the two arrays because they are directly tied + // to the opcode behavior above. len = this.children.length; - if (other.children.length !== len) { - return false; - } for (i = 0; i < len; i++) { if (!this.children[i].equals(other.children[i])) { return false; @@ -449,3 +444,18 @@ export function compile(input, options, env) { }; return ret; } + +function argEquals(a, b) { + if (a === b) { + return true; + } + + if (isArray(a) && isArray(b) && a.length === b.length) { + for (var i = 0; i < a.length; i++) { + if (!argEquals(a[i], b[i])) { + return false; + } + } + return true; + } +} |