From 98a6717e9ea71323da04e8e01e59c60ac46d42d1 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Fri, 30 Oct 2015 12:21:15 -0500 Subject: [PATCH 01/11] Add print-script helper script --- print-script | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 print-script diff --git a/print-script b/print-script new file mode 100755 index 000000000..046b99c17 --- /dev/null +++ b/print-script @@ -0,0 +1,95 @@ +#! /usr/bin/env node +/* eslint-disable no-console, no-var */ +// Util script for debugging source code generation issues + +var script = process.argv[2].replace(/\\n/g, '\n'), + verbose = process.argv[3] === '-v'; + +var Handlebars = require('./lib'), + SourceMap = require('source-map'), + SourceMapConsumer = SourceMap.SourceMapConsumer; + +var template = Handlebars.precompile(script, { + srcName: 'input.hbs', + destName: 'output.js', + + assumeObjects: true, + compat: false, + strict: true, + trackIds: true, + knownHelpersOnly: false + }); + +if (!verbose) { + console.log(template); +} else { + var consumer = new SourceMapConsumer(template.map), + lines = template.code.split('\n'), + srcLines = script.split('\n'); + + console.log(); + console.log('Source:'); + srcLines.forEach(function(source, index) { + console.log(index + 1, source); + }); + console.log(); + console.log('Generated:'); + console.log(template.code); + lines.forEach(function(source, index) { + console.log(index + 1, source); + }); + console.log(); + console.log('Map:'); + console.log(template.map); + console.log(); + + function collectSource(lines, lineName, colName, order) { + var ret = {}, + ordered = [], + last; + + function collect(current) { + if (last) { + var mapLines = lines.slice(last[lineName] - 1, current && current[lineName]); + if (mapLines.length) { + if (current) { + mapLines[mapLines.length - 1] = mapLines[mapLines.length - 1].slice(0, current[colName]); + } + mapLines[0] = mapLines[0].slice(last[colName]); + } + ret[last[lineName] + ':' + last[colName]] = mapLines.join('\n'); + ordered.push({ + startLine: last[lineName], + startCol: last[colName], + endLine: current && current[lineName] + }); + } + last = current; + } + + consumer.eachMapping(collect, undefined, order); + collect(); + + return ret; + } + + srcLines = collectSource(srcLines, 'originalLine', 'originalColumn', SourceMapConsumer.ORIGINAL_ORDER); + lines = collectSource(lines, 'generatedLine', 'generatedColumn'); + + consumer.eachMapping(function(mapping) { + var originalSrc = srcLines[mapping.originalLine + ':' + mapping.originalColumn], + generatedSrc = lines[mapping.generatedLine + ':' + mapping.generatedColumn]; + + if (!mapping.originalLine) { + console.log('generated', mapping.generatedLine + ':' + mapping.generatedColumn, generatedSrc); + } else { + console.log('map', + mapping.source, + mapping.originalLine + ':' + mapping.originalColumn, + originalSrc, + '->', + mapping.generatedLine + ':' + mapping.generatedColumn, + generatedSrc); + } + }); +} From 7b48a284e0b0d02f60284b4df1de71c3af87eadf Mon Sep 17 00:00:00 2001 From: Victor Bastos Date: Sat, 31 Oct 2015 13:51:14 -0200 Subject: [PATCH 02/11] Tag DOMBars as deprecated --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 22b8a51f4..904b9e0c6 100644 --- a/README.markdown +++ b/README.markdown @@ -148,7 +148,7 @@ Handlebars in the Wild templating engine, extending it with automatic data binding support. * [YUI](http://yuilibrary.com/yui/docs/handlebars/) implements a port of handlebars * [Swag](https://github.com/elving/swag) by [@elving](https://github.com/elving) is a growing collection of helpers for handlebars.js. Give your handlebars.js templates some swag son! -* [DOMBars](https://github.com/blakeembrey/dombars) is a DOM-based templating engine built on the Handlebars parser and runtime +* [DOMBars](https://github.com/blakeembrey/dombars) is a DOM-based templating engine built on the Handlebars parser and runtime **DEPRECATED** * [promised-handlebars](https://github.com/nknapp/promised-handlebars) is a wrapper for Handlebars that allows helpers to return Promises. External Resources From 9f59de9657ac8aa3b2773e056956e63fe197fe29 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 31 Oct 2015 13:32:43 -0500 Subject: [PATCH 03/11] Fix lint errors under latest eslint --- lib/handlebars/compiler/javascript-compiler.js | 2 +- lib/handlebars/utils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index bd48e9b1c..97939df00 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -12,7 +12,7 @@ function JavaScriptCompiler() {} JavaScriptCompiler.prototype = { // PUBLIC API: You can override these methods in a subclass to provide // alternative compiled forms for name lookup and buffering semantics - nameLookup: function(parent, name /* , type*/) { + nameLookup: function(parent, name/* , type*/) { if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) { return [parent, '.', name]; } else { diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index 1cf7e3219..2584601ef 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -15,7 +15,7 @@ function escapeChar(chr) { return escape[chr]; } -export function extend(obj /* , ...source */) { +export function extend(obj/* , ...source */) { for (let i = 1; i < arguments.length; i++) { for (let key in arguments[i]) { if (Object.prototype.hasOwnProperty.call(arguments[i], key)) { From 1dc417f1a5b4ec5a81bc3113e63476b18d0efc17 Mon Sep 17 00:00:00 2001 From: Paul Lynch Date: Mon, 16 Nov 2015 18:23:25 -0500 Subject: [PATCH 04/11] Update uglify-js to avoid vulnerability --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 605380365..1da9b0971 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "source-map": "^0.4.4" }, "optionalDependencies": { - "uglify-js": "~2.4" + "uglify-js": "~2.6" }, "devDependencies": { "aws-sdk": "^2.1.49", From c21118d04bcd42c385536a2dcbab1a0f5ee68c57 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 19 Nov 2015 22:53:23 -0600 Subject: [PATCH 05/11] Include tests for minimized artifacts --- Gruntfile.js | 2 +- spec/env/browser.js | 7 ++++++- spec/env/runner.js | 24 ++++++++++++++++++++---- spec/env/runtime.js | 7 ++++++- tasks/test.js | 11 +++++++++++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 3bb1c1661..1b705c49c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -211,7 +211,7 @@ module.exports = function(grunt) { this.registerTask('globals', ['webpack']); this.registerTask('tests', ['concat:tests']); - this.registerTask('release', 'Build final packages', ['eslint', 'amd', 'uglify', 'copy:dist', 'copy:components', 'copy:cdnjs']); + this.registerTask('release', 'Build final packages', ['eslint', 'amd', 'uglify', 'test:min', 'copy:dist', 'copy:components', 'copy:cdnjs']); // Load tasks from npm grunt.loadNpmTasks('grunt-contrib-clean'); diff --git a/spec/env/browser.js b/spec/env/browser.js index 8049dda0e..60a5d3547 100644 --- a/spec/env/browser.js +++ b/spec/env/browser.js @@ -4,7 +4,12 @@ var fs = require('fs'), vm = require('vm'); global.Handlebars = 'no-conflict'; -vm.runInThisContext(fs.readFileSync(__dirname + '/../../dist/handlebars.js'), 'dist/handlebars.js'); + +var filename = 'dist/handlebars.js'; +if (global.minimizedTest) { + filename = 'dist/handlebars.min.js'; +} +vm.runInThisContext(fs.readFileSync(__dirname + '/../../' + filename), filename); global.CompilerContext = { browser: true, diff --git a/spec/env/runner.js b/spec/env/runner.js index 4ff1e7e48..f4b23d825 100644 --- a/spec/env/runner.js +++ b/spec/env/runner.js @@ -7,19 +7,35 @@ var errors = 0, testDir = path.dirname(__dirname), grep = process.argv[2]; +// Lazy hack, but whatever +if (grep === '--min') { + global.minimizedTest = true; + grep = undefined; +} + var files = fs.readdirSync(testDir) .filter(function(name) { return (/.*\.js$/).test(name); }) .map(function(name) { return testDir + '/' + name; }); -run('./runtime', function() { - run('./browser', function() { - run('./node', function() { +if (global.minimizedTest) { + run('./runtime', function() { + run('./browser', function() { /* eslint-disable no-process-exit */ process.exit(errors); /* eslint-enable no-process-exit */ }); }); -}); +} else { + run('./runtime', function() { + run('./browser', function() { + run('./node', function() { + /* eslint-disable no-process-exit */ + process.exit(errors); + /* eslint-enable no-process-exit */ + }); + }); + }); +} function run(env, callback) { diff --git a/spec/env/runtime.js b/spec/env/runtime.js index 9d1c04995..642acd348 100644 --- a/spec/env/runtime.js +++ b/spec/env/runtime.js @@ -4,7 +4,12 @@ var fs = require('fs'), vm = require('vm'); global.Handlebars = 'no-conflict'; -vm.runInThisContext(fs.readFileSync(__dirname + '/../../dist/handlebars.runtime.js'), 'dist/handlebars.runtime.js'); + +var filename = 'dist/handlebars.runtime.js'; +if (global.minimizedTest) { + filename = 'dist/handlebars.runtime.min.js'; +} +vm.runInThisContext(fs.readFileSync(__dirname + '/../../' + filename), filename); var parse = require('../../dist/cjs/handlebars/compiler/base').parse; var compiler = require('../../dist/cjs/handlebars/compiler/compiler'); diff --git a/tasks/test.js b/tasks/test.js index 7d6659b09..18a6c26ba 100644 --- a/tasks/test.js +++ b/tasks/test.js @@ -40,6 +40,17 @@ module.exports = function(grunt) { done(); }); }); + grunt.registerTask('test:min', function() { + var done = this.async(); + + var runner = childProcess.fork('./spec/env/runner', ['--min'], {stdio: 'inherit'}); + runner.on('close', function(code) { + if (code != 0) { + grunt.fatal(code + ' tests failed'); + } + done(); + }); + }); grunt.registerTask('test:check-cov', function() { var done = this.async(); From 251ec3b1288f4392ea63eba4fd3334efd1710318 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 19 Nov 2015 22:54:10 -0600 Subject: [PATCH 06/11] Work around uglify preserveComments some issue Root cause: https://github.com/gruntjs/grunt-contrib-uglify/issues/366 Fixes #1129 --- Gruntfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 1b705c49c..fd76518a6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -125,7 +125,7 @@ module.exports = function(grunt) { options: { mangle: true, compress: true, - preserveComments: 'some' + preserveComments: /(?:^!|@(?:license|preserve|cc_on))/ }, dist: { files: [{ From 0a3b3c28312d57f1bae1d4089341c6c417c57b84 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 19 Nov 2015 22:54:39 -0600 Subject: [PATCH 07/11] Further relax uglify dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1da9b0971..75cb456bc 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "source-map": "^0.4.4" }, "optionalDependencies": { - "uglify-js": "~2.6" + "uglify-js": "^2.6" }, "devDependencies": { "aws-sdk": "^2.1.49", From 7a6c22859279b42f5a12eef06cc99999e3152461 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 19 Nov 2015 22:55:03 -0600 Subject: [PATCH 08/11] Add webpack to dev dependency to support npm 3 --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 75cb456bc..3c86e7396 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,9 @@ "mock-stdin": "^0.3.0", "mustache": "^2.1.3", "semver": "^5.0.1", - "underscore": "^1.5.1" + "underscore": "^1.5.1", + "webpack": "^1.12.6", + "webpack-dev-server": "^1.12.1" }, "main": "lib/index.js", "bin": { From 685cf92bcb67aba80665fc48bd6565a946ab32b7 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 19 Nov 2015 22:58:26 -0600 Subject: [PATCH 09/11] Return current handlebars instance from noConflict Fixes wycats/handlebars-site#131 --- lib/handlebars/no-conflict.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/handlebars/no-conflict.js b/lib/handlebars/no-conflict.js index ad41e96fa..40a44d7a6 100644 --- a/lib/handlebars/no-conflict.js +++ b/lib/handlebars/no-conflict.js @@ -8,5 +8,6 @@ export default function(Handlebars) { if (root.Handlebars === Handlebars) { root.Handlebars = $Handlebars; } + return Handlebars; }; } From ddaff8ea2987812f600dbbace75c71f805cf67f7 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 19 Nov 2015 23:06:29 -0600 Subject: [PATCH 10/11] Update release notes --- release-notes.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/release-notes.md b/release-notes.md index 5ea873efe..497f5e898 100644 --- a/release-notes.md +++ b/release-notes.md @@ -2,7 +2,19 @@ ## Development -[Commits](https://github.com/wycats/handlebars.js/compare/v4.0.4...master) +[Commits](https://github.com/wycats/handlebars.js/compare/v4.0.5...master) + +## v4.0.5 - November 19th, 2015 +- [#1132](https://github.com/wycats/handlebars.js/pull/1132) - Update uglify-js to avoid vulnerability ([@plynchnlm](https://api.github.com/users/plynchnlm)) +- [#1129](https://github.com/wycats/handlebars.js/issues/1129) - Minified lib returns an empty string ([@bricss](https://api.github.com/users/bricss)) +- Return current handlebars instance from noConflict - 685cf92 +- Add webpack to dev dependency to support npm 3 - 7a6c228 +- Further relax uglify dependency - 0a3b3c2 +- Include tests for minimized artifacts - c21118d +- Fix lint errors under latest eslint - 9f59de9 +- Add print-script helper script - 98a6717 + +[Commits](https://github.com/wycats/handlebars.js/compare/v4.0.4...v4.0.5) ## v4.0.4 - October 29th, 2015 - [#1121](https://github.com/wycats/handlebars.js/pull/1121) - Include partial name in 'undefined partial' exception message ([@shinypb](https://api.github.com/users/shinypb)) From 205c61cfb1acdb599bbdfcf2d356641254e09e5c Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 19 Nov 2015 23:06:54 -0600 Subject: [PATCH 11/11] v4.0.5 --- components/bower.json | 2 +- components/handlebars.js.nuspec | 2 +- lib/handlebars/base.js | 2 +- package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/bower.json b/components/bower.json index e4aaab97e..840c77235 100644 --- a/components/bower.json +++ b/components/bower.json @@ -1,6 +1,6 @@ { "name": "handlebars", - "version": "4.0.4", + "version": "4.0.5", "main": "handlebars.js", "license": "MIT", "dependencies": {} diff --git a/components/handlebars.js.nuspec b/components/handlebars.js.nuspec index 326827e16..9ede3d607 100644 --- a/components/handlebars.js.nuspec +++ b/components/handlebars.js.nuspec @@ -2,7 +2,7 @@ handlebars.js - 4.0.4 + 4.0.5 handlebars.js Authors https://github.com/wycats/handlebars.js/blob/master/LICENSE https://github.com/wycats/handlebars.js/ diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js index 84a89158f..836422d1e 100644 --- a/lib/handlebars/base.js +++ b/lib/handlebars/base.js @@ -4,7 +4,7 @@ import {registerDefaultHelpers} from './helpers'; import {registerDefaultDecorators} from './decorators'; import logger from './logger'; -export const VERSION = '4.0.4'; +export const VERSION = '4.0.5'; export const COMPILER_REVISION = 7; export const REVISION_CHANGES = { diff --git a/package.json b/package.json index 3c86e7396..a5b788796 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "handlebars", "barename": "handlebars", - "version": "4.0.4", + "version": "4.0.5", "description": "Handlebars provides the power necessary to let you build semantic templates effectively with no frustration", "homepage": "http://www.handlebarsjs.com/", "keywords": [