diff --git a/Gruntfile.js b/Gruntfile.js index 3bb1c1661..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: [{ @@ -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/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 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/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/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; }; } 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)) { diff --git a/package.json b/package.json index 605380365..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": [ @@ -26,7 +26,7 @@ "source-map": "^0.4.4" }, "optionalDependencies": { - "uglify-js": "~2.4" + "uglify-js": "^2.6" }, "devDependencies": { "aws-sdk": "^2.1.49", @@ -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": { 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); + } + }); +} 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)) 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();