Add missing types for the Exception class properties (#1583)
* Convert Exception to a class * Add node param type declaration * Test the types
This commit is contained in:
committed by
Nils Knappmeier
parent
62ed3c25c7
commit
b8913fcc65
Vendored
+14
-1
@@ -66,7 +66,6 @@ declare namespace Handlebars {
|
||||
export function K(): void;
|
||||
export function createFrame(object: any): any;
|
||||
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, options?: ParseOptions): hbs.AST.Program;
|
||||
export function parseWithoutProcessing(input: string, options?: ParseOptions): hbs.AST.Program;
|
||||
@@ -87,6 +86,20 @@ declare namespace Handlebars {
|
||||
|
||||
export function noConflict(): typeof Handlebars;
|
||||
|
||||
export class Exception {
|
||||
constructor(message: string, node?: hbs.AST.Node);
|
||||
description: string;
|
||||
fileName: string;
|
||||
lineNumber?: any;
|
||||
endLineNumber?: any;
|
||||
message: string;
|
||||
name: string;
|
||||
number: number;
|
||||
stack?: string;
|
||||
column?: any;
|
||||
endColumn?: any;
|
||||
}
|
||||
|
||||
export class SafeString {
|
||||
constructor(str: string);
|
||||
toString(): string;
|
||||
|
||||
@@ -201,3 +201,42 @@ function testParseWithoutProcessing() {
|
||||
|
||||
const parsedTemplateWithoutOptions: hbs.AST.Program = Handlebars.parseWithoutProcessing('<p>Hello, my name is {{name}}.</p>');
|
||||
}
|
||||
|
||||
function testExceptionTypings() {
|
||||
// Test exception constructor with a single argument - message.
|
||||
let exception: Handlebars.Exception = new Handlebars.Exception('message');
|
||||
|
||||
// Fields
|
||||
let message: string = exception.message;
|
||||
let lineNumber: number = exception.lineNumber;
|
||||
let column: number = exception.column;
|
||||
let endLineNumber: number = exception.endLineNumber;
|
||||
let endColumn: number = exception.endColumn;
|
||||
let description = exception.description;
|
||||
let name: string = exception.name;
|
||||
let fileName: string = exception.fileName;
|
||||
let stack: string | undefined = exception.stack;
|
||||
}
|
||||
|
||||
function testExceptionWithNodeTypings() {
|
||||
// Test exception constructor with both arguments.
|
||||
const exception: Handlebars.Exception = new Handlebars.Exception('message', {
|
||||
type: 'MustacheStatement',
|
||||
loc: {
|
||||
source: 'source',
|
||||
start: { line: 1, column: 5 },
|
||||
end: { line: 10, column: 2 }
|
||||
}
|
||||
});
|
||||
|
||||
// Fields
|
||||
let message: string = exception.message;
|
||||
let lineNumber: number = exception.lineNumber;
|
||||
let column: number = exception.column;
|
||||
let endLineNumber: number = exception.endLineNumber;
|
||||
let endColumn: number = exception.endColumn;
|
||||
let description = exception.description;
|
||||
let name: string = exception.name;
|
||||
let fileName: string = exception.fileName;
|
||||
let stack: string | undefined = exception.stack;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user