From daa8f3dd0566a7ad734d5bdca109b221fb951453 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 27 Dec 2014 10:05:05 -0600 Subject: [PATCH 1/6] Fix duplicate return statement on simple templates --- lib/handlebars/compiler/javascript-compiler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 9f407924..2e1108cf 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -248,7 +248,7 @@ JavaScriptCompiler.prototype = { if (bufferStart) { bufferStart.prepend('return '); bufferEnd.add(';'); - } else { + } else if (!sourceSeen) { this.source.push('return "";'); } } else { From f1470505133377223db6d3e6f4e30d5665e7f23e Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 27 Dec 2014 12:12:21 -0600 Subject: [PATCH 2/6] Update dependencies --- package.json | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 61bce712..c4711c99 100644 --- a/package.json +++ b/package.json @@ -21,37 +21,37 @@ "node": ">=0.4.7" }, "dependencies": { - "optimist": "~0.3", + "optimist": "^0.6.1", "source-map": "^0.1.40" }, "optionalDependencies": { "uglify-js": "~2.3" }, "devDependencies": { - "async": "~0.2.9", + "async": "^0.9.0", "aws-sdk": "~1.5.0", "benchmark": "~1.0", - "dustjs-linkedin": "~2.0.2", + "dustjs-linkedin": "^2.0.2", "eco": "~1.1.0-rc-3", "es6-module-packager": "^2.0.0", "grunt": "~0.4.1", "grunt-cli": "~0.1.10", - "grunt-contrib-clean": "~0.4.1", - "grunt-contrib-concat": "~0.3.0", - "grunt-contrib-connect": "~0.5.0", - "grunt-contrib-copy": "~0.4.1", + "grunt-contrib-clean": "0.x", + "grunt-contrib-concat": "0.x", + "grunt-contrib-connect": "0.x", + "grunt-contrib-copy": "0.x", "grunt-contrib-jshint": "0.x", - "grunt-contrib-requirejs": "~0.4.1", - "grunt-contrib-uglify": "~0.2.2", - "grunt-contrib-watch": "~0.5.3", + "grunt-contrib-requirejs": "0.x", + "grunt-contrib-uglify": "0.x", + "grunt-contrib-watch": "0.x", "grunt-saucelabs": "8.x", "istanbul": "^0.3.0", "jison": "~0.3.0", "keen.io": "0.0.3", "mocha": "~1.20.0", - "mustache": "~0.7.2", - "semver": "~2.1.0", - "underscore": "~1.5.1" + "mustache": "0.x", + "semver": "^4.0.0", + "underscore": "^1.5.1" }, "main": "lib/index.js", "bin": { From b474630c7dc96f7a4e56c3530a89920e13bf26d4 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 27 Dec 2014 12:58:28 -0600 Subject: [PATCH 3/6] Strip unnecessary whitespace in template output --- lib/handlebars/compiler/javascript-compiler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 2e1108cf..247f5e07 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -263,7 +263,7 @@ JavaScriptCompiler.prototype = { } if (varDeclarations) { - this.source.prepend('var ' + varDeclarations.substring(2) + (appendFirst ? '' : ';\n ')); + this.source.prepend('var ' + varDeclarations.substring(2) + (appendFirst ? '' : ';\n')); } return this.source.merge(); From 9c9a972a0c5d00db3a896cdadcdde6f2c453f66f Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 27 Dec 2014 13:01:13 -0600 Subject: [PATCH 4/6] Safely handle source map in browser tests --- spec/source-map.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/source-map.js b/spec/source-map.js index 4d3fa3e8..a9e8ba35 100644 --- a/spec/source-map.js +++ b/spec/source-map.js @@ -1,9 +1,13 @@ /*global CompilerContext, Handlebars */ -var SourceMap = require('source-map'), - SourceMapConsumer = SourceMap.SourceMapConsumer; +try { + var SourceMap = require('source-map'), + SourceMapConsumer = SourceMap.SourceMapConsumer; +} catch (err) { + /* NOP for in browser */ +} describe('source-map', function() { - if (!Handlebars.precompile) { + if (!Handlebars.precompile || !SourceMap) { return; } @@ -14,8 +18,8 @@ describe('source-map', function() { equal(!!template.map, !CompilerContext.browser); }); it('should map source properly', function() { - var source = ' b{{hello}} \n {{bar}}a {{#block arg hash=(subex 1 subval)}}{{/block}}', - template = Handlebars.precompile(source, {destName: 'dest.js', srcName: 'src.hbs'}); + var template = ' b{{hello}} \n {{bar}}a {{#block arg hash=(subex 1 subval)}}{{/block}}'; + template = Handlebars.precompile(template, {destName: 'dest.js', srcName: 'src.hbs'}); if (template.map) { var consumer = new SourceMapConsumer(template.map), From 0a9fc171b00a12fa990d2f7d27310182ed51a41c Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 27 Dec 2014 13:13:52 -0600 Subject: [PATCH 5/6] Fix block param evaluation under older IE --- lib/handlebars/compiler/compiler.js | 4 ++-- lib/handlebars/utils.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 13143cc8..95fe101b 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -1,5 +1,5 @@ import Exception from "../exception"; -import {isArray} from "../utils"; +import {isArray, indexOf} from "../utils"; import AST from "./ast"; var slice = [].slice; @@ -400,7 +400,7 @@ Compiler.prototype = { blockParamIndex: function(name) { for (var depth = 0, len = this.options.blockParams.length; depth < len; depth++) { var blockParams = this.options.blockParams[depth], - param = blockParams && blockParams.indexOf(name); + param = blockParams && indexOf(blockParams, name); if (blockParams && param >= 0) { return [depth, param]; } diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index 8cea50d7..fc2b8464 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -48,6 +48,16 @@ export var isArray = Array.isArray || function(value) { return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false; }; +// Older IE versions do not directly support indexOf so we must implement our own, sadly. +export function indexOf(array, value) { + for (var i = 0, len = array.length; i < len; i++) { + if (array[i] === value) { + return i; + } + } + return -1; +} + export function escapeExpression(string) { // don't escape SafeStrings, since they're already safe From b764fb1ded3c2bb3c56796e6d7264981e63ba0d7 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 27 Dec 2014 13:17:55 -0600 Subject: [PATCH 6/6] Fix sourcemap test --- spec/source-map.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/source-map.js b/spec/source-map.js index a9e8ba35..6eced9ca 100644 --- a/spec/source-map.js +++ b/spec/source-map.js @@ -18,8 +18,8 @@ describe('source-map', function() { equal(!!template.map, !CompilerContext.browser); }); it('should map source properly', function() { - var template = ' b{{hello}} \n {{bar}}a {{#block arg hash=(subex 1 subval)}}{{/block}}'; - template = Handlebars.precompile(template, {destName: 'dest.js', srcName: 'src.hbs'}); + var source = ' b{{hello}} \n {{bar}}a {{#block arg hash=(subex 1 subval)}}{{/block}}', + template = Handlebars.precompile(source, {destName: 'dest.js', srcName: 'src.hbs'}); if (template.map) { var consumer = new SourceMapConsumer(template.map),