Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c393c81
Relax depth check for context push
kpdecker Dec 12, 2015
6c9f98c
Update build for modern node versions
kpdecker Dec 12, 2015
20c965c
Fix throw when creating exception object in Safari
kpdecker Dec 12, 2015
32d6363
Exclude coverage check in exception conditional
kpdecker Dec 12, 2015
fee2334
Update target browser test versions
kpdecker Dec 12, 2015
400916c
Avoid error in older browsers in test
kpdecker Dec 12, 2015
8fc1636
Add documentation for running tests to contributing.md
ryanmurakami Dec 14, 2015
8c19874
Drop extra Error params
kpdecker Dec 14, 2015
577b760
Fix typos on decorators-api.md.
adjohnson916 Dec 23, 2015
959ee55
Update jsfiddle to point to latest
kpdecker Dec 24, 2015
6272c15
Update license date
timwangdev Jan 6, 2016
1379e8f
Contributing doc fix: failing thats -> failing tests
paulfalgout Jan 19, 2016
45e14b7
Preserve License info in Closure Compiler
gennadiylitvinyuk Feb 5, 2016
1b885d4
Added cory
leo Feb 27, 2016
8ff49ce
Ensure that existing blockParams and depths are respected on dupe pro…
charleso Feb 19, 2016
0d0c4d1
Add a new lightweight package based on handlebars in the README
kabirbaidhya Apr 12, 2016
ef9e0dc
Walk up data frames for nested @partial-block
lawnsea Aug 16, 2016
5ee91cb
Add test reproducing #1185
lawnsea Aug 17, 2016
abc160a
Use XML-like tags in test instead of bizarre dot delimiters
lawnsea Aug 17, 2016
3385de0
v4.0.6
lawnsea Nov 11, 2016
44ce5f4
Update release notes
lawnsea Nov 12, 2016
ad3037c
v4.0.6 (again)
lawnsea Nov 12, 2016
c7dc353
Testcase to verify that compile-errors have a column-property
nknapp Dec 20, 2016
a023cb4
Make "column"-property of Errors enumerable
nknapp Dec 21, 2016
406f2ee
require('sys') is deprecated, using 'util' instead
travnels Nov 16, 2016
01b0f65
Avoid duplicate "sourceMappingURL=" lines.
joonas-lahtinen Feb 13, 2017
5a164d0
Fix for #1252: Using @partial-block twice in a template not possible
nknapp Dec 30, 2016
63a8e0c
Add more tests for partial-blocks and inline partials
nknapp Jan 2, 2017
0fa10b6
Merge branch '4.x'
nknapp Feb 14, 2017
911e676
Merge branch '4.x'
nknapp Feb 14, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "handlebars",
"version": "4.0.5",
"version": "4.0.6",
"main": "handlebars.js",
"license": "MIT",
"dependencies": {}
Expand Down
2 changes: 1 addition & 1 deletion components/handlebars.js.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>handlebars.js</id>
<version>4.0.5</version>
<version>4.0.6</version>
<authors>handlebars.js Authors</authors>
<licenseUrl>https://github.com/wycats/handlebars.js/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/wycats/handlebars.js/</projectUrl>
Expand Down
2 changes: 1 addition & 1 deletion lib/handlebars/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {registerDefaultHelpers} from './helpers';
import {registerDefaultDecorators} from './decorators';
import logger from './logger';

export const VERSION = '4.0.5';
export const VERSION = '4.0.6';
export const COMPILER_REVISION = 7;

export const REVISION_CHANGES = {
Expand Down
5 changes: 4 additions & 1 deletion lib/handlebars/exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ function Exception(message, node) {
// Work around issue under safari where we can't directly set the column value
/* istanbul ignore next */
if (Object.defineProperty) {
Object.defineProperty(this, 'column', {value: column});
Object.defineProperty(this, 'column', {
value: column,
enumerable: true
});
} else {
this.column = column;
}
Expand Down
24 changes: 14 additions & 10 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,7 @@ export function wrapProgram(container, i, fn, data, declaredBlockParams, blockPa
export function resolvePartial(partial, context, options) {
if (!partial) {
if (options.name === '@partial-block') {
let data = options.data;
while (data['partial-block'] === noop) {
data = data._parent;
}
partial = data['partial-block'];
data['partial-block'] = noop;
partial = options.data['partial-block'];
} else {
partial = options.partials[options.name];
}
Expand All @@ -215,15 +210,24 @@ export function resolvePartial(partial, context, options) {
}

export function invokePartial(partial, context, options) {
// Use the current closure context to save the partial-block if this partial
const currentPartialBlock = options.data && options.data['partial-block'];
options.partial = true;

let partialBlock;
if (options.fn && options.fn !== noop) {
options.data = createFrame(options.data);
partialBlock = options.data['partial-block'] = options.fn;

if (partialBlock.partials) {
options.partials = Utils.extend({}, options.partials, partialBlock.partials);
// Wrapper function to get access to currentPartialBlock from the closure
let fn = options.fn;
partialBlock = options.data['partial-block'] = function partialBlockWrapper(context, options) {
// Restore the partial-block from the closure for the execution of the block
// i.e. the part inside the block of the partial call.
options.data = createFrame(options.data);
options.data['partial-block'] = currentPartialBlock;
return fn(context, options);
};
if (fn.partials) {
options.partials = Utils.extend({}, options.partials, fn.partials);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "handlebars",
"barename": "handlebars",
"version": "4.0.5",
"version": "4.0.6",
"description": "Handlebars provides the power necessary to let you build semantic templates effectively with no frustration",
"homepage": "http://www.handlebarsjs.com/",
"keywords": [
Expand Down
23 changes: 22 additions & 1 deletion release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,28 @@

## Development

[Commits](https://github.com/wycats/handlebars.js/compare/v4.0.5...master)
[Commits](https://github.com/lawnsea/handlebars.js/compare/v4.0.6...master)

## v4.0.6 - November 12th, 2016
- [#1243](https://github.com/wycats/handlebars.js/pull/1243) - Walk up data frames for nested @partial-block ([@lawnsea](https://github.com/lawnsea))
- [#1210](https://github.com/wycats/handlebars.js/pull/1210) - Add a new lightweight package based on handlebars in the README ([@kabirbaidhya](https://github.com/kabirbaidhya))
- [#1187](https://github.com/wycats/handlebars.js/pull/1187) - Ensure that existing blockParams and depths are respected on dupe programs ([@charleso](https://github.com/charleso))
- [#1191](https://github.com/wycats/handlebars.js/pull/1191) - Added cory ([@leo](https://github.com/leo))
- [#1177](https://github.com/wycats/handlebars.js/pull/1177) - Preserve License info in Closure Compiler ([@gennadiylitvinyuk](https://github.com/gennadiylitvinyuk))
- [#1171](https://github.com/wycats/handlebars.js/pull/1171) - Contributing doc fix: failing thats -> failing tests ([@paulfalgout](https://github.com/paulfalgout))
- [#1166](https://github.com/wycats/handlebars.js/pull/1166) - Update license date ([@timwangdev](https://github.com/timwangdev))
- Update jsfiddle to point to latest - 959ee55 (originally dfc7554 by [@kpdecker](https://github.com/kpdecker))
- [#1163](https://github.com/wycats/handlebars.js/pull/1163) - Fix typos on decorators-api.md. ([@adjohnson916](https://github.com/adjohnson916))
- Drop extra Error params - 8c19874 (originally 63fdb92 by [@kpdecker](https://github.com/kpdecker))
- [#1153](https://github.com/wycats/handlebars.js/pull/1153) - Add documentation for running tests to contributing.md ([@ryanmurakami](https://github.com/ryanmurakami))
- Avoid error in older browsers in test - 400916c (originally a6121ca by [@kpdecker](https://github.com/kpdecker))
- Update target browser test versions - fee2334 (originally 871c32a by [@kpdecker](https://github.com/kpdecker))
- Exclude coverage check in exception conditional - 32d6363 (originally 326734b by [@kpdecker](https://github.com/kpdecker))
- Fix throw when creating exception object in Safari - 20c965c (originally 2ea6119 by [@kpdecker](https://github.com/kpdecker))
- Update build for modern node versions - 6c9f98c (originally 8289c0b by [@kpdecker](https://github.com/kpdecker))
- [#1135](https://github.com/wycats/handlebars.js/issues/1135) - Relax depth check for context push - c393c81 (originally 25458fd by [@kpdecker](https://github.com/kpdecker))

[Commits](https://github.com/wycats/handlebars.js/compare/v4.0.5...v4.0.6)

## 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))
Expand Down
25 changes: 25 additions & 0 deletions spec/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ describe('compiler', function() {
}, Error, 'You must pass a string or Handlebars AST to Handlebars.compile. You passed [object Object]');
});

it('should include the location in the error (row and column)', function() {
try {
Handlebars.compile(' \n {{#if}}\n{{/def}}')();
equal(true, false, 'Statement must throw exception. This line should not be executed.');
} catch (err) {
equal(err.message, 'if doesn\'t match def - 2:5', 'Checking error message');
if (Object.getOwnPropertyDescriptor(err, 'column').writable) {
// In Safari 8, the column-property is read-only. This means that even if it is set with defineProperty,
// its value won't change (https://github.com/jquery/esprima/issues/1290#issuecomment-132455482)
// Since this was neither working in Handlebars 3 nor in 4.0.5, we only check the column for other browsers.
equal(err.column, 5, 'Checking error column');
}
equal(err.lineNumber, 2, 'Checking error row');
}
});

it('should include the location as enumerable property', function() {
try {
Handlebars.compile(' \n {{#if}}\n{{/def}}')();
equal(true, false, 'Statement must throw exception. This line should not be executed.');
} catch (err) {
equal(err.propertyIsEnumerable('column'), true, 'Checking error column');
}
});

it('can utilize AST instance', function() {
equal(Handlebars.compile({
type: 'Program',
Expand Down
95 changes: 95 additions & 0 deletions spec/partials.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,46 @@ describe('partials', function() {
true,
'success');
});
it('should be able to render the partial-block twice', function() {
shouldCompileToWithPartials(
'{{#> dude}}success{{/dude}}',
[{}, {}, {dude: '{{> @partial-block }} {{> @partial-block }}'}],
true,
'success success');
});
it('should render block from partial with context', function() {
shouldCompileToWithPartials(
'{{#> dude}}{{value}}{{/dude}}',
[{context: {value: 'success'}}, {}, {dude: '{{#with context}}{{> @partial-block }}{{/with}}'}],
true,
'success');
});
it('should allow the #each-helper to be used along with partial-blocks', function() {
shouldCompileToWithPartials(
'<template>{{#> list value}}value = {{.}}{{/list}}</template>',
[
{value: ['a', 'b', 'c']},
{},
{
list: '<list>{{#each .}}<item>{{> @partial-block}}</item>{{/each}}</list>'
}
],
true,
'<template><list><item>value = a</item><item>value = b</item><item>value = c</item></list></template>');
});
it('should render block from partial with context (twice)', function() {
shouldCompileToWithPartials(
'{{#> dude}}{{value}}{{/dude}}',
[
{context: {value: 'success'}},
{},
{
dude: '{{#with context}}{{> @partial-block }} {{> @partial-block }}{{/with}}'
}
],
true,
'success success');
});
it('should render block from partial with context', function() {
shouldCompileToWithPartials(
'{{#> dude}}{{../context/value}}{{/dude}}',
Expand Down Expand Up @@ -284,6 +317,50 @@ describe('partials', function() {
true,
'<template><outer><nested><outer-block>success</outer-block></nested></outer></template>');
});
it('should render nested partial blocks at different nesting levels', function() {
shouldCompileToWithPartials(
'<template>{{#> outer}}{{value}}{{/outer}}</template>',
[
{value: 'success'},
{},
{
outer: '<outer>{{#> nested}}<outer-block>{{> @partial-block}}</outer-block>{{/nested}}{{> @partial-block}}</outer>',
nested: '<nested>{{> @partial-block}}</nested>'
}
],
true,
'<template><outer><nested><outer-block>success</outer-block></nested>success</outer></template>');
});
it('should render nested partial blocks at different nesting levels (twice)', function() {
shouldCompileToWithPartials(
'<template>{{#> outer}}{{value}}{{/outer}}</template>',
[
{value: 'success'},
{},
{
outer: '<outer>{{#> nested}}<outer-block>{{> @partial-block}} {{> @partial-block}}</outer-block>{{/nested}}{{> @partial-block}}+{{> @partial-block}}</outer>',
nested: '<nested>{{> @partial-block}}</nested>'
}
],
true,
'<template><outer><nested><outer-block>success success</outer-block></nested>success+success</outer></template>');
});
it('should render nested partial blocks (twice at each level)', function() {
shouldCompileToWithPartials(
'<template>{{#> outer}}{{value}}{{/outer}}</template>',
[
{value: 'success'},
{},
{
outer: '<outer>{{#> nested}}<outer-block>{{> @partial-block}} {{> @partial-block}}</outer-block>{{/nested}}</outer>',
nested: '<nested>{{> @partial-block}}{{> @partial-block}}</nested>'
}
],
true,
'<template><outer>' +
'<nested><outer-block>success success</outer-block><outer-block>success success</outer-block></nested>' +
'</outer></template>');
});
});

describe('inline partials', function() {
Expand Down Expand Up @@ -332,6 +409,24 @@ describe('partials', function() {
true,
'<inner><outer-block>success</outer-block></inner>');
});
it('should render nested inline partials with partial-blocks on different nesting levels', function() {
shouldCompileToWithPartials(
'{{#*inline "outer"}}{{#>inner}}<outer-block>{{>@partial-block}}</outer-block>{{/inner}}{{>@partial-block}}{{/inline}}' +
'{{#*inline "inner"}}<inner>{{>@partial-block}}</inner>{{/inline}}' +
'{{#>outer}}{{value}}{{/outer}}',
[{value: 'success'}, {}, {}],
true,
'<inner><outer-block>success</outer-block></inner>success');
});
it('should render nested inline partials (twice at each level)', function() {
shouldCompileToWithPartials(
'{{#*inline "outer"}}{{#>inner}}<outer-block>{{>@partial-block}} {{>@partial-block}}</outer-block>{{/inner}}{{/inline}}' +
'{{#*inline "inner"}}<inner>{{>@partial-block}}{{>@partial-block}}</inner>{{/inline}}' +
'{{#>outer}}{{value}}{{/outer}}',
[{value: 'success'}, {}, {}],
true,
'<inner><outer-block>success success</outer-block><outer-block>success success</outer-block></inner>');
});
});

it('should pass compiler flags', function() {
Expand Down