From e75c7945e3a9aaed4cc4cee0d098fbe1fd3fa55c Mon Sep 17 00:00:00 2001 From: Mark Bell Date: Tue, 23 Sep 2014 06:28:25 +0100 Subject: [PATCH 1/2] Add definitions for mustache.js 0.8.2 Add new definitions for 0.8.2, move 0.7 definitions and tests into versioned files and remove empty .tscparams files. --- mustache/mustache-0.7.0-tests.ts | 11 ++++++ mustache/mustache-0.7.0.d.ts | 54 ++++++++++++++++++++++++++++ mustache/mustache-tests.ts | 17 +++++---- mustache/mustache-tests.ts.tscparams | 1 - mustache/mustache.d.ts | 17 ++++----- mustache/mustache.d.ts.tscparams | 1 - 6 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 mustache/mustache-0.7.0-tests.ts create mode 100644 mustache/mustache-0.7.0.d.ts delete mode 100644 mustache/mustache-tests.ts.tscparams delete mode 100644 mustache/mustache.d.ts.tscparams diff --git a/mustache/mustache-0.7.0-tests.ts b/mustache/mustache-0.7.0-tests.ts new file mode 100644 index 000000000..0f39985ef --- /dev/null +++ b/mustache/mustache-0.7.0-tests.ts @@ -0,0 +1,11 @@ +/// + +var view = { title: "Joe", calc: function () { return 2 + 4; } }; +var output = Mustache.render("{{title}} spends {{calc}}", view); + +var person; +var template = "

{{firstName}} {{lastName}}

Blog: {{blogURL}}"; +var html = Mustache.to_html(template, person); + +var writer = Mustache.compile(template); +var writerOutput = writer(view); diff --git a/mustache/mustache-0.7.0.d.ts b/mustache/mustache-0.7.0.d.ts new file mode 100644 index 000000000..9921231bc --- /dev/null +++ b/mustache/mustache-0.7.0.d.ts @@ -0,0 +1,54 @@ +// Type definitions for Mustache 0.7 +// Project: https://github.com/janl/mustache.js +// Definitions by: Boris Yankov +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +interface MustacheScanner { + string: string; + tail: string; + pos: number; + + eos(): boolean; + scan(re: RegExp): string; + scanUntil(re: RegExp): string; +} + +interface MustacheContext { + view; + parent; + + clearCache(); + push(view): MustacheContext; + lookup(name: string): any; +} + +interface MustacheWriter { + (view: any): string; + clearCache(); + compile(template: string, tags); + compilePartial(name, template, tags); + compileTokens(tokens, template); + render(template, view, partials); +} + +interface MustacheStatic { + name: string; + version: string; + tags: string; + Scanner: MustacheScanner; + Context: MustacheContext; + Writer: MustacheWriter; + escape; + + parse(template: string, tags); + clearCache(): MustacheWriter; + compile(template: string): MustacheWriter; + compile(template: string, tags): MustacheWriter; + compilePartial(name: string, template: string, tags): MustacheWriter; + compileTokens(tokens, template: string): MustacheWriter; + render(template: string, view: any, partials?: any): string; + to_html(template: string, view: any, partials?: any, send?): string; +} + +declare var Mustache: MustacheStatic; diff --git a/mustache/mustache-tests.ts b/mustache/mustache-tests.ts index 9b42131ef..5265dec0a 100644 --- a/mustache/mustache-tests.ts +++ b/mustache/mustache-tests.ts @@ -1,11 +1,14 @@ /// -var view = { title: "Joe", calc: function () { return 2 + 4; } }; -var output = Mustache.render("{{title}} spends {{calc}}", view); +var view1 = { title: "Joe", calc: function () { return 2 + 4; } }; +var template1 = "{{title}} spends {{calc}}"; +var output = Mustache.render(template1, view1); -var person; -var template = "

{{firstName}} {{lastName}}

Blog: {{blogURL}}"; -var html = Mustache.to_html(template, person); +var view2 = { forename: "Jane", calc: function () { return 10 + 5; } }; +var template2 = "{{forename}} spends {{calc}}"; +Mustache.parse(template2, null); +var output2 = Mustache.render(template2, view2); -var writer = Mustache.compile(template); -var writerOutput = writer(view); +var view3 = { firstName: "John", lastName: "Smith", blogURL: "http://testblog.com" }; +var template3 = "

{{firstName}} {{lastName}}

Blog: {{blogURL}}"; +var html = Mustache.to_html(template3, view3); diff --git a/mustache/mustache-tests.ts.tscparams b/mustache/mustache-tests.ts.tscparams deleted file mode 100644 index d3f5a12fa..000000000 --- a/mustache/mustache-tests.ts.tscparams +++ /dev/null @@ -1 +0,0 @@ - diff --git a/mustache/mustache.d.ts b/mustache/mustache.d.ts index 9cd5e6f69..6737a7dd9 100644 --- a/mustache/mustache.d.ts +++ b/mustache/mustache.d.ts @@ -1,6 +1,6 @@ -// Type definitions for Mustache 0.7 +// Type definitions for Mustache 0.8.2 // Project: https://github.com/janl/mustache.js -// Definitions by: Boris Yankov +// Definitions by: Mark Ashley Bell // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -18,18 +18,17 @@ interface MustacheContext { view; parent; - clearCache(); push(view): MustacheContext; lookup(name: string): any; } interface MustacheWriter { (view: any): string; + clearCache(); - compile(template: string, tags); - compilePartial(name, template, tags); - compileTokens(tokens, template); + parse(template: string, tags?: any); render(template, view, partials); + renderTokens(tokens, context, partials, originalTemplate); } interface MustacheStatic { @@ -41,12 +40,8 @@ interface MustacheStatic { Writer: MustacheWriter; escape; - parse(template: string, tags); clearCache(): MustacheWriter; - compile(template: string): MustacheWriter; - compile(template: string, tags): MustacheWriter; - compilePartial(name: string, template: string, tags): MustacheWriter; - compileTokens(tokens, template: string): MustacheWriter; + parse(template: string, tags?: any); render(template: string, view: any, partials?: any): string; to_html(template: string, view: any, partials?: any, send?): string; } diff --git a/mustache/mustache.d.ts.tscparams b/mustache/mustache.d.ts.tscparams deleted file mode 100644 index d3f5a12fa..000000000 --- a/mustache/mustache.d.ts.tscparams +++ /dev/null @@ -1 +0,0 @@ - From 0778e9dec5954ce5e15982607dde8f5f711bd237 Mon Sep 17 00:00:00 2001 From: Mark Bell Date: Tue, 23 Sep 2014 07:17:08 +0100 Subject: [PATCH 2/2] Add parameter typing, fix old definition version I was omitting the -noImplicitAny flag when testing; interestingly, even the old (0.7.3) definitions failed the Travis CI tests... --- ...0.7.0-tests.ts => mustache-0.7.3-tests.ts} | 4 +-- ...ustache-0.7.0.d.ts => mustache-0.7.3.d.ts} | 33 ++++++++++--------- mustache/mustache.d.ts | 20 +++++------ 3 files changed, 29 insertions(+), 28 deletions(-) rename mustache/{mustache-0.7.0-tests.ts => mustache-0.7.3-tests.ts} (71%) rename mustache/{mustache-0.7.0.d.ts => mustache-0.7.3.d.ts} (52%) diff --git a/mustache/mustache-0.7.0-tests.ts b/mustache/mustache-0.7.3-tests.ts similarity index 71% rename from mustache/mustache-0.7.0-tests.ts rename to mustache/mustache-0.7.3-tests.ts index 0f39985ef..f95913cc7 100644 --- a/mustache/mustache-0.7.0-tests.ts +++ b/mustache/mustache-0.7.3-tests.ts @@ -1,9 +1,9 @@ -/// +/// var view = { title: "Joe", calc: function () { return 2 + 4; } }; var output = Mustache.render("{{title}} spends {{calc}}", view); -var person; +var person = { firstName: "John", lastName: "Smith", blogURL: "http://testblog.com" }; var template = "

{{firstName}} {{lastName}}

Blog: {{blogURL}}"; var html = Mustache.to_html(template, person); diff --git a/mustache/mustache-0.7.0.d.ts b/mustache/mustache-0.7.3.d.ts similarity index 52% rename from mustache/mustache-0.7.0.d.ts rename to mustache/mustache-0.7.3.d.ts index 9921231bc..ac40de0a0 100644 --- a/mustache/mustache-0.7.0.d.ts +++ b/mustache/mustache-0.7.3.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Mustache 0.7 +// Type definitions for Mustache 0.7.3 // Project: https://github.com/janl/mustache.js // Definitions by: Boris Yankov // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -15,21 +15,22 @@ interface MustacheScanner { } interface MustacheContext { - view; - parent; + view: any; + parent: MustacheContext; - clearCache(); - push(view): MustacheContext; + clearCache(): void; + push(view: any): MustacheContext; lookup(name: string): any; } interface MustacheWriter { (view: any): string; - clearCache(); - compile(template: string, tags); - compilePartial(name, template, tags); - compileTokens(tokens, template); - render(template, view, partials); + + clearCache(): void; + compile(template: string, tags: any): any; + compilePartial(name: string, template: string, tags: any): any; + compileTokens(tokens: string[], template: string): any; + render(template: string, view: any, partials: any): any; } interface MustacheStatic { @@ -39,16 +40,16 @@ interface MustacheStatic { Scanner: MustacheScanner; Context: MustacheContext; Writer: MustacheWriter; - escape; + escape: any; - parse(template: string, tags); + parse(template: string, tags: any): any; clearCache(): MustacheWriter; compile(template: string): MustacheWriter; - compile(template: string, tags): MustacheWriter; - compilePartial(name: string, template: string, tags): MustacheWriter; - compileTokens(tokens, template: string): MustacheWriter; + compile(template: string, tags: any): MustacheWriter; + compilePartial(name: string, template: string, tags: any): MustacheWriter; + compileTokens(tokens: string[], template: string): MustacheWriter; render(template: string, view: any, partials?: any): string; - to_html(template: string, view: any, partials?: any, send?): string; + to_html(template: string, view: any, partials?: any, send?: any): string; } declare var Mustache: MustacheStatic; diff --git a/mustache/mustache.d.ts b/mustache/mustache.d.ts index 6737a7dd9..3f0a83dfa 100644 --- a/mustache/mustache.d.ts +++ b/mustache/mustache.d.ts @@ -15,20 +15,20 @@ interface MustacheScanner { } interface MustacheContext { - view; - parent; + view: any; + parentContext: MustacheContext; - push(view): MustacheContext; + push(view: any): MustacheContext; lookup(name: string): any; } interface MustacheWriter { (view: any): string; - clearCache(); - parse(template: string, tags?: any); - render(template, view, partials); - renderTokens(tokens, context, partials, originalTemplate); + clearCache(): void; + parse(template: string, tags?: any): any; + render(template: string, view: any, partials: any): string; + renderTokens(tokens: string[], context: MustacheContext, partials: any, originalTemplate: any): string; } interface MustacheStatic { @@ -38,12 +38,12 @@ interface MustacheStatic { Scanner: MustacheScanner; Context: MustacheContext; Writer: MustacheWriter; - escape; + escape: any; clearCache(): MustacheWriter; - parse(template: string, tags?: any); + parse(template: string, tags?: any): any; render(template: string, view: any, partials?: any): string; - to_html(template: string, view: any, partials?: any, send?): string; + to_html(template: string, view: any, partials?: any, send?: any): any; } declare var Mustache: MustacheStatic;