Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update typings for handlebars: Add options param to parse #31380

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion types/handlebars/handlebars-tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

//import Handlebars = require('handlebars');
import * as Handlerbars from 'handlebars';
import * as Handlebars from 'handlebars';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This typo is good evidence that handlebars should switch to the new global syntax:

``ts
export = Handlebars;
export as namespace Handlebars;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! In parallel, I've been working to have Handlebars provide its own typings as part of the package (handlebars-lang/handlebars.js#1487), so I'll look into making this change over there (likely in a follow-up PR).


const context = {
author: { firstName: 'Alan', lastName: 'Johnson' },
Expand Down Expand Up @@ -78,3 +78,10 @@ template6([{url:"", title:""}])
const escapedExpression = Handlebars.Utils.escapeExpression('<script>alert(\'xss\');</script>');

Handlebars.helpers !== undefined;

const parsedTmpl = Handlebars.parse('<p>Hello, my name is {{name}}.</p>', {
srcName: "/foo/bar/baz.hbs",
ignoreStandalone: true
});

const parsedTmplWithoutOptions = Handlebars.parse('<p>Hello, my name is {{name}}.</p>');
7 changes: 6 additions & 1 deletion types/handlebars/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ declare namespace Handlebars {
[key: string]: HelperDelegate;
}

export interface ParseOptions {
srcName?: string,
ignoreStandalone?: boolean
}

export function registerHelper(name: string, fn: HelperDelegate): void;
export function registerHelper(name: HelperDeclareSpec): void;
export function unregisterHelper(name: string): void;
Expand All @@ -52,7 +57,7 @@ declare namespace Handlebars {
export function blockParams(obj: any[], ids: any[]): any[];
export function Exception(message: string): void;
export function log(level: number, obj: any): void;
export function parse(input: string): hbs.AST.Program;
export function parse(input: string, options?: ParseOptions): hbs.AST.Program;
export function compile<T = any>(input: any, options?: CompileOptions): HandlebarsTemplateDelegate<T>;
export function precompile(input: any, options?: PrecompileOptions): TemplateSpecification;
export function template<T = any>(precompilation: TemplateSpecification): HandlebarsTemplateDelegate<T>;
Expand Down
8 changes: 2 additions & 6 deletions types/handlebars/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,5 @@
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"handlebars-tests.ts"
]
}
}
}