Skip to content

Commit

Permalink
Add "Handlebars.VM.resolvePartial" to type definitions
Browse files Browse the repository at this point in the history
- Handlebars.VM is actually not part of the API,
  but Handlebars.VM.resolvePartial is mentioned
  in the documentation and is thus now treated
  as part of the API.

Closes handlebars-lang#1534
  • Loading branch information
AndrewLeedham authored and nknapp committed Sep 3, 2019
1 parent f119497 commit 133b96a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/handlebars/runtime.js
Expand Up @@ -209,6 +209,9 @@ export function wrapProgram(container, i, fn, data, declaredBlockParams, blockPa
return prog;
}

/**
* This is currently part of the official API, therefore implementation details should not be changed.
*/
export function resolvePartial(partial, context, options) {
if (!partial) {
if (options.name === '@partial-block') {
Expand Down
11 changes: 11 additions & 0 deletions types/index.d.ts
Expand Up @@ -7,6 +7,7 @@
* - Raanan Weber <https://github.com/RaananW>
* - Sergei Dorogin <https://github.com/evil-shrike>
* - webbiesdk <https://github.com/webbiesdk>
* - Andrew Leedham <https://github.com/AndrewLeedham>
* For full history prior to their migration to handlebars.js, please see:
* https://github.com/DefinitelyTyped/DefinitelyTyped/commits/1ce60bdc07f10e0b076778c6c953271c072bc894/types/handlebars/index.d.ts
*/
Expand All @@ -20,6 +21,7 @@ declare namespace Handlebars {
export type Template<T = any> = TemplateDelegate<T>|string;

export interface RuntimeOptions {
name?: string;
partial?: boolean;
depths?: any[];
helpers?: { [name: string]: Function };
Expand Down Expand Up @@ -147,6 +149,13 @@ declare namespace Handlebars {
NullLiteral(): void;
Hash(hash: hbs.AST.Hash): void;
}

export namespace VM {
/**
* @deprecated
*/
export function resolvePartial<T = any>(partial: HandlebarsTemplateDelegate<T> | undefined, context: any, options: RuntimeOptions): HandlebarsTemplateDelegate<T>;
}
}

/**
Expand Down Expand Up @@ -223,6 +232,8 @@ interface Logger {
log(level: number, obj: string): void;
}

type CompilerInfo = [number/* revision */, string /* versions */];

declare namespace hbs {
namespace AST {
interface Node {
Expand Down
10 changes: 10 additions & 0 deletions types/test.ts
Expand Up @@ -90,6 +90,16 @@ const parsedTmpl = Handlebars.parse('<p>Hello, my name is {{name}}.</p>', {

const parsedTmplWithoutOptions = Handlebars.parse('<p>Hello, my name is {{name}}.</p>');

// Custom partial resolution.
const originalResolvePartial = Handlebars.VM.resolvePartial;
Handlebars.VM.resolvePartial = <T>(partial: HandlebarsTemplateDelegate<T> | undefined, context: any, options: RuntimeOptions): HandlebarsTemplateDelegate<T> => {
const name = options.name;
// transform name.
options.name = name;
return originalResolvePartial(partial, context, options);
}


// #1544, allow custom helpers in knownHelpers
Handlebars.compile('test', {
knownHelpers: {
Expand Down

0 comments on commit 133b96a

Please sign in to comment.