Skip to content

Commit

Permalink
Remove semi-documented _setup and _child APIs
Browse files Browse the repository at this point in the history
These were a bad idea to begin with and without the trackIds implementation they don’t make much sense.
  • Loading branch information
kpdecker committed Dec 12, 2015
1 parent 0f054ef commit 63a0889
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 64 deletions.
15 changes: 1 addition & 14 deletions lib/handlebars/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,25 +461,12 @@ export function compile(input, options = {}, env) {
}

// Template is only compiled on first use and cached after that point.
function ret(context, execOptions) {
return function(context, execOptions) {
if (!compiled) {
compiled = compileInput();
}
return compiled.call(this, context, execOptions);
}
ret._setup = function(setupOptions) {
if (!compiled) {
compiled = compileInput();
}
return compiled._setup(setupOptions);
};
ret._child = function(i, data, blockParams, depths) {
if (!compiled) {
compiled = compileInput();
}
return compiled._child(i, data, blockParams, depths);
};
return ret;
}

function argEquals(a, b) {
Expand Down
16 changes: 3 additions & 13 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function template(templateSpec, env) {
function ret(context, options = {}) {
let data = options.data;

ret._setup(options);
_setup(options);
if (!options.partial && templateSpec.useData) {
data = initData(context, data);
}
Expand All @@ -151,7 +151,7 @@ export function template(templateSpec, env) {
}
ret.isTop = true;

ret._setup = function(options) {
function _setup(options) {
if (!options.partial) {
container.helpers = container.merge(options.helpers, env.helpers);

Expand All @@ -166,18 +166,8 @@ export function template(templateSpec, env) {
container.partials = options.partials;
container.decorators = options.decorators;
}
};

ret._child = function(i, data, blockParams, depths) {
if (templateSpec.useBlockParams && !blockParams) {
throw new Exception('must pass block params');
}
if (templateSpec.useDepths && !depths) {
throw new Exception('must pass parent depths');
}
}

return wrapProgram(container, i, templateSpec[i], data, 0, blockParams, depths);
};
return ret;
}

Expand Down
37 changes: 0 additions & 37 deletions spec/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,6 @@ describe('runtime', function() {
});
});

describe('#child', function() {
if (!Handlebars.compile) {
return;
}

it('should throw for depthed methods without depths', function() {
shouldThrow(function() {
var template = Handlebars.compile('{{#foo}}{{../bar}}{{/foo}}');
// Calling twice to hit the non-compiled case.
template._setup({});
template._setup({});
template._child(1);
}, Error, 'must pass parent depths');
});

it('should throw for block param methods without params', function() {
shouldThrow(function() {
var template = Handlebars.compile('{{#foo as |foo|}}{{foo}}{{/foo}}');
// Calling twice to hit the non-compiled case.
template._setup({});
template._setup({});
template._child(1);
}, Error, 'must pass block params');
});
it('should expose child template', function() {
var template = Handlebars.compile('{{#foo}}bar{{/foo}}');
// Calling twice to hit the non-compiled case.
equal(template._child(1)(), 'bar');
equal(template._child(1)(), 'bar');
});
it('should render depthed content', function() {
var template = Handlebars.compile('{{#foo}}{{../bar}}{{/foo}}');
// Calling twice to hit the non-compiled case.
equal(template._child(1, undefined, [], [{bar: 'baz'}])(), 'baz');
});
});

describe('#noConflict', function() {
if (!CompilerContext.browser) {
return;
Expand Down

0 comments on commit 63a0889

Please sign in to comment.