Skip to content

Commit 8ac2028

Browse files
authored
Merge pull request #1534 from AndrewLeedham/4.x
Add VM TS mapping
2 parents f119497 + 888750e commit 8ac2028

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

Gruntfile.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ module.exports = function(grunt) {
55
pkg: grunt.file.readJSON('package.json'),
66

77
eslint: {
8-
options: {
9-
},
108
files: [
119
'*.js',
1210
'bench/**/*.js',
1311
'tasks/**/*.js',
1412
'lib/**/!(*.min|parser).js',
1513
'spec/**/!(*.amd|json2|require).js',
16-
'integration-testing/**/*.js'
14+
'integration-testing/multi-nodejs-test/*.js',
15+
'integration-testing/webpack-test/*.js',
16+
'integration-testing/webpack-test/src/*.js'
1717
]
1818
},
1919

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

+20
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
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>
11+
* - Nils Knappmeier <https://github.com/nknapp>
1012
* For full history prior to their migration to handlebars.js, please see:
1113
* https://github.com/DefinitelyTyped/DefinitelyTyped/commits/1ce60bdc07f10e0b076778c6c953271c072bc894/types/handlebars/index.d.ts
1214
*/
@@ -147,6 +149,22 @@ declare namespace Handlebars {
147149
NullLiteral(): void;
148150
Hash(hash: hbs.AST.Hash): void;
149151
}
152+
153+
154+
export interface ResolvePartialOptions {
155+
name: string;
156+
helpers?: { [name: string]: Function };
157+
partials?: { [name: string]: HandlebarsTemplateDelegate };
158+
decorators?: { [name: string]: Function };
159+
data?: any;
160+
}
161+
162+
export namespace VM {
163+
/**
164+
* @deprecated
165+
*/
166+
export function resolvePartial<T = any>(partial: HandlebarsTemplateDelegate<T> | undefined, context: any, options: ResolvePartialOptions): HandlebarsTemplateDelegate<T>;
167+
}
150168
}
151169

152170
/**
@@ -223,6 +241,8 @@ interface Logger {
223241
log(level: number, obj: string): void;
224242
}
225243

244+
type CompilerInfo = [number/* revision */, string /* versions */];
245+
226246
declare namespace hbs {
227247
namespace AST {
228248
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: Handlebars.ResolvePartialOptions): HandlebarsTemplateDelegate<T> => {
96+
const name = options.name.replace(/my/,'your');
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)