Skip to content

Commit 133b96a

Browse files
AndrewLeedhamnknapp
authored andcommitted
Add "Handlebars.VM.resolvePartial" to type definitions
- 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 #1534
1 parent f119497 commit 133b96a

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/handlebars/runtime.js

+3
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ export function wrapProgram(container, i, fn, data, declaredBlockParams, blockPa
209209
return prog;
210210
}
211211

212+
/**
213+
* This is currently part of the official API, therefore implementation details should not be changed.
214+
*/
212215
export function resolvePartial(partial, context, options) {
213216
if (!partial) {
214217
if (options.name === '@partial-block') {

types/index.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* - Raanan Weber <https://github.com/RaananW>
88
* - Sergei Dorogin <https://github.com/evil-shrike>
99
* - webbiesdk <https://github.com/webbiesdk>
10+
* - Andrew Leedham <https://github.com/AndrewLeedham>
1011
* For full history prior to their migration to handlebars.js, please see:
1112
* https://github.com/DefinitelyTyped/DefinitelyTyped/commits/1ce60bdc07f10e0b076778c6c953271c072bc894/types/handlebars/index.d.ts
1213
*/
@@ -20,6 +21,7 @@ declare namespace Handlebars {
2021
export type Template<T = any> = TemplateDelegate<T>|string;
2122

2223
export interface RuntimeOptions {
24+
name?: string;
2325
partial?: boolean;
2426
depths?: any[];
2527
helpers?: { [name: string]: Function };
@@ -147,6 +149,13 @@ declare namespace Handlebars {
147149
NullLiteral(): void;
148150
Hash(hash: hbs.AST.Hash): void;
149151
}
152+
153+
export namespace VM {
154+
/**
155+
* @deprecated
156+
*/
157+
export function resolvePartial<T = any>(partial: HandlebarsTemplateDelegate<T> | undefined, context: any, options: RuntimeOptions): HandlebarsTemplateDelegate<T>;
158+
}
150159
}
151160

152161
/**
@@ -223,6 +232,8 @@ interface Logger {
223232
log(level: number, obj: string): void;
224233
}
225234

235+
type CompilerInfo = [number/* revision */, string /* versions */];
236+
226237
declare namespace hbs {
227238
namespace AST {
228239
interface Node {

types/test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ const parsedTmpl = Handlebars.parse('<p>Hello, my name is {{name}}.</p>', {
9090

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

93+
// Custom partial resolution.
94+
const originalResolvePartial = Handlebars.VM.resolvePartial;
95+
Handlebars.VM.resolvePartial = <T>(partial: HandlebarsTemplateDelegate<T> | undefined, context: any, options: RuntimeOptions): HandlebarsTemplateDelegate<T> => {
96+
const name = options.name;
97+
// transform name.
98+
options.name = name;
99+
return originalResolvePartial(partial, context, options);
100+
}
101+
102+
93103
// #1544, allow custom helpers in knownHelpers
94104
Handlebars.compile('test', {
95105
knownHelpers: {

0 commit comments

Comments
 (0)