From 36b6312eeed6a0bdaae2eb98270a27aba4cfbf58 Mon Sep 17 00:00:00 2001 From: Tyler Johnson Date: Tue, 14 Aug 2018 13:03:55 -0600 Subject: [PATCH 1/4] add typings for async getSource and runtime.SafeString class --- types/nunjucks/index.d.ts | 8 +++++++- types/nunjucks/nunjucks-tests.ts | 2 ++ types/nunjucks/tslint.json | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/types/nunjucks/index.d.ts b/types/nunjucks/index.d.ts index d307bd27d5..1908f7e4c0 100644 --- a/types/nunjucks/index.d.ts +++ b/types/nunjucks/index.d.ts @@ -94,7 +94,7 @@ export function installJinjaCompat(): void; export interface ILoader { async?: boolean; - getSource(name: string): LoaderSource; + getSource(name: string, callback?: (err?: any, result?: LoaderSource) => void): LoaderSource | void; extend?(extender: ILoader): ILoader; } @@ -137,3 +137,9 @@ export class PrecompiledLoader extends Loader implements ILoader { init(searchPaths: string[], opts: any): void; getSource(name: string): LoaderSource; } + +export namespace runtime { + class SafeString { + constructor(...args: any[]); + } +} diff --git a/types/nunjucks/nunjucks-tests.ts b/types/nunjucks/nunjucks-tests.ts index 9f3afcddfe..91caf67a73 100644 --- a/types/nunjucks/nunjucks-tests.ts +++ b/types/nunjucks/nunjucks-tests.ts @@ -52,3 +52,5 @@ class MyLoader extends nunjucks.Loader implements nunjucks.ILoader { } env = new nunjucks.Environment(new MyLoader()); + +new nunjucks.runtime.SafeString(); diff --git a/types/nunjucks/tslint.json b/types/nunjucks/tslint.json index 2c7c1bed53..65fb79195f 100644 --- a/types/nunjucks/tslint.json +++ b/types/nunjucks/tslint.json @@ -1,6 +1,7 @@ { "extends": "dtslint/dt.json", "rules": { - "interface-name": false + "interface-name": false, + "no-unnecessary-class": false // to allow SafeString class } } From 44988b0a8102c27738d4a700cffae5d5ae0e4900 Mon Sep 17 00:00:00 2001 From: Tyler Johnson Date: Tue, 14 Aug 2018 13:12:01 -0600 Subject: [PATCH 2/4] WebLoader extends Loader, set version to 3.1 --- types/nunjucks/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/nunjucks/index.d.ts b/types/nunjucks/index.d.ts index 1908f7e4c0..b0a1e86508 100644 --- a/types/nunjucks/index.d.ts +++ b/types/nunjucks/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for nunjucks 3.0 +// Type definitions for nunjucks 3.1 // Project: http://mozilla.github.io/nunjucks/ // Definitions by: Ruben Slabbert // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -128,7 +128,7 @@ export class FileSystemLoader extends Loader implements ILoader { constructor(searchPaths?: string | string[], opts?: FileSystemLoaderOptions); } -export class WebLoader implements ILoader { +export class WebLoader extends Loader implements ILoader { constructor(baseUrl: string, opts?: any); getSource(name: string): LoaderSource; } From f0c300861b310dba0e22efc0f38e9a87a0944b4e Mon Sep 17 00:00:00 2001 From: Tyler Johnson Date: Tue, 14 Aug 2018 13:16:50 -0600 Subject: [PATCH 3/4] add missing safestring methods --- types/nunjucks/index.d.ts | 6 +++++- types/nunjucks/nunjucks-tests.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/types/nunjucks/index.d.ts b/types/nunjucks/index.d.ts index b0a1e86508..e2bdbf2a8a 100644 --- a/types/nunjucks/index.d.ts +++ b/types/nunjucks/index.d.ts @@ -140,6 +140,10 @@ export class PrecompiledLoader extends Loader implements ILoader { export namespace runtime { class SafeString { - constructor(...args: any[]); + constructor(val: string); + val: string; + length: number; + valueOf(): string; + toString(): string; } } diff --git a/types/nunjucks/nunjucks-tests.ts b/types/nunjucks/nunjucks-tests.ts index 91caf67a73..6dd4d8fed7 100644 --- a/types/nunjucks/nunjucks-tests.ts +++ b/types/nunjucks/nunjucks-tests.ts @@ -53,4 +53,4 @@ class MyLoader extends nunjucks.Loader implements nunjucks.ILoader { env = new nunjucks.Environment(new MyLoader()); -new nunjucks.runtime.SafeString(); +new nunjucks.runtime.SafeString("an unsafe string"); From d723c81ce8becbe61712dbd6daf5321338080502 Mon Sep 17 00:00:00 2001 From: Tyler Johnson Date: Wed, 15 Aug 2018 18:10:53 -0600 Subject: [PATCH 4/4] add overloaded getSource method --- types/nunjucks/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/nunjucks/index.d.ts b/types/nunjucks/index.d.ts index e2bdbf2a8a..13869f0d60 100644 --- a/types/nunjucks/index.d.ts +++ b/types/nunjucks/index.d.ts @@ -94,7 +94,8 @@ export function installJinjaCompat(): void; export interface ILoader { async?: boolean; - getSource(name: string, callback?: (err?: any, result?: LoaderSource) => void): LoaderSource | void; + getSource(name: string): LoaderSource; + getSource(name: string, callback: (err?: any, result?: LoaderSource) => void): void; extend?(extender: ILoader): ILoader; }