Skip to content

Commit b8913fc

Browse files
kabirbaidhyanknapp
authored andcommitted
Add missing types for the Exception class properties (#1583)
* Convert Exception to a class * Add node param type declaration * Test the types
1 parent 62ed3c2 commit b8913fc

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

types/index.d.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ declare namespace Handlebars {
6666
export function K(): void;
6767
export function createFrame(object: any): any;
6868
export function blockParams(obj: any[], ids: any[]): any[];
69-
export function Exception(message: string): void;
7069
export function log(level: number, obj: any): void;
7170
export function parse(input: string, options?: ParseOptions): hbs.AST.Program;
7271
export function parseWithoutProcessing(input: string, options?: ParseOptions): hbs.AST.Program;
@@ -87,6 +86,20 @@ declare namespace Handlebars {
8786

8887
export function noConflict(): typeof Handlebars;
8988

89+
export class Exception {
90+
constructor(message: string, node?: hbs.AST.Node);
91+
description: string;
92+
fileName: string;
93+
lineNumber?: any;
94+
endLineNumber?: any;
95+
message: string;
96+
name: string;
97+
number: number;
98+
stack?: string;
99+
column?: any;
100+
endColumn?: any;
101+
}
102+
90103
export class SafeString {
91104
constructor(str: string);
92105
toString(): string;

types/test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,42 @@ function testParseWithoutProcessing() {
201201

202202
const parsedTemplateWithoutOptions: hbs.AST.Program = Handlebars.parseWithoutProcessing('<p>Hello, my name is {{name}}.</p>');
203203
}
204+
205+
function testExceptionTypings() {
206+
// Test exception constructor with a single argument - message.
207+
let exception: Handlebars.Exception = new Handlebars.Exception('message');
208+
209+
// Fields
210+
let message: string = exception.message;
211+
let lineNumber: number = exception.lineNumber;
212+
let column: number = exception.column;
213+
let endLineNumber: number = exception.endLineNumber;
214+
let endColumn: number = exception.endColumn;
215+
let description = exception.description;
216+
let name: string = exception.name;
217+
let fileName: string = exception.fileName;
218+
let stack: string | undefined = exception.stack;
219+
}
220+
221+
function testExceptionWithNodeTypings() {
222+
// Test exception constructor with both arguments.
223+
const exception: Handlebars.Exception = new Handlebars.Exception('message', {
224+
type: 'MustacheStatement',
225+
loc: {
226+
source: 'source',
227+
start: { line: 1, column: 5 },
228+
end: { line: 10, column: 2 }
229+
}
230+
});
231+
232+
// Fields
233+
let message: string = exception.message;
234+
let lineNumber: number = exception.lineNumber;
235+
let column: number = exception.column;
236+
let endLineNumber: number = exception.endLineNumber;
237+
let endColumn: number = exception.endColumn;
238+
let description = exception.description;
239+
let name: string = exception.name;
240+
let fileName: string = exception.fileName;
241+
let stack: string | undefined = exception.stack;
242+
}

0 commit comments

Comments
 (0)