From a9b7384eb475599db9afe5b31b97a0d160922d01 Mon Sep 17 00:00:00 2001 From: benliddicott Date: Sat, 15 Aug 2015 11:26:16 +0100 Subject: [PATCH 1/7] static-eval.d.ts --- static-eval/static-eval.d.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 static-eval/static-eval.d.ts diff --git a/static-eval/static-eval.d.ts b/static-eval/static-eval.d.ts new file mode 100644 index 0000000000..61db0b4056 --- /dev/null +++ b/static-eval/static-eval.d.ts @@ -0,0 +1,4 @@ +declare module 'static-eval' { + function evaluate(ast, vars: { [name: string]: any }); + export =evaluate; +} From 87d055979089cb5c498672d63ef6e1a8f725b6e9 Mon Sep 17 00:00:00 2001 From: benliddicott Date: Thu, 17 Sep 2015 14:18:23 +0100 Subject: [PATCH 2/7] EJS Typing --- ejs/ejs-tests.ts | 4 +++ ejs/ejs.d.ts | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 ejs/ejs-tests.ts create mode 100644 ejs/ejs.d.ts diff --git a/ejs/ejs-tests.ts b/ejs/ejs-tests.ts new file mode 100644 index 0000000000..fd03dd1e09 --- /dev/null +++ b/ejs/ejs-tests.ts @@ -0,0 +1,4 @@ +/// +import ejs = require("ejs"); +var people = ['geddy', 'neil', 'alex']; +var html = ejs.render('<%= people.join(", "); %>', { people: people }); diff --git a/ejs/ejs.d.ts b/ejs/ejs.d.ts new file mode 100644 index 0000000000..95ca168c38 --- /dev/null +++ b/ejs/ejs.d.ts @@ -0,0 +1,91 @@ +// Type definitions for ejs.js v2.3.3 +// Project: http://ejs.co/ +// Definitions by: Ben Liddicott +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +declare module "ejs" { + module Ejs { + type Data = { [name: string]: any }; + type Dependencies = string[]; + var cache: Cache; + var localsName: string; + function resolveInclude(name: string, filename: string): string; + function compile(template: string, opts?: Options): (TemplateFunction); + function render(template: string, data?: Data, opts?: Options): string; + function renderFile(path: string, data?: Data, opts?: Options, cb?: Function): any;// TODO RenderFileCallback return type + function clearCache(): any; + + function TemplateFunction(data: Data): any; + interface TemplateFunction { + dependencies: Dependencies; + } + interface Options { + cache?: any; + filename?: string; + context?: any; + compileDebug?: boolean; + client?: boolean; + delimiter?: string; + debug?: any; + _with?: boolean; + } + class Template { + constructor(text: string, opts: Options); + opts: Options; + templateText: string; + mode: string; + truncate: boolean; + currentLine: number; + source: string; + dependencies: Dependencies; + createRegex(): RegExp; + compile(): TemplateFunction; + generateSource(): any; + parseTemplateText(): string[]; + scanLine(line: string): any; + + } + module Template { + interface MODES { + EVAL: string; + ESCAPED: string; + RAW: string; + COMMENT: string; + LITERAL: string; + } + } + function escapeRegexChars(s: string): string; + function escapeXML(markup: string): string; + function shallowCopy(to: T1, fro: any): T1; + interface Cache { + _data: { [name: string]: any }; + set(key: string, val: any); + get(key: string): any; + } + var cache: Cache; + function resolve(from1: string, to: string): string; + function resolve(from1: string, from2: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, from8: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, from8: string, from9: string, to: string): string; + function resolve(...args: string[]): string; + function normalize(path: string): string; + function isAbsolute(path: string): boolean; + function join(...args: string[]): string; + function relative(from: string, to: string): string; + var sep: string; + var delimiter: string; + function dirname(path: string): string; + function basename(path: string): string; + function extname(path: string): string; + function filter(xs: any, f: any): any; // TODO WHUT? + + + } + export = Ejs; +} \ No newline at end of file From d2f21a1d08fe25cbcb2ddf2b27f57a688391cb9c Mon Sep 17 00:00:00 2001 From: benliddicott Date: Sat, 15 Aug 2015 11:26:16 +0100 Subject: [PATCH 3/7] static-eval.d.ts --- static-eval/static-eval.d.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 static-eval/static-eval.d.ts diff --git a/static-eval/static-eval.d.ts b/static-eval/static-eval.d.ts new file mode 100644 index 0000000000..61db0b4056 --- /dev/null +++ b/static-eval/static-eval.d.ts @@ -0,0 +1,4 @@ +declare module 'static-eval' { + function evaluate(ast, vars: { [name: string]: any }); + export =evaluate; +} From 89456dbce061106c41a01549ae703f0be8c27f98 Mon Sep 17 00:00:00 2001 From: benliddicott Date: Thu, 17 Sep 2015 14:18:23 +0100 Subject: [PATCH 4/7] EJS Typing --- ejs/ejs-tests.ts | 4 +++ ejs/ejs.d.ts | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 ejs/ejs-tests.ts create mode 100644 ejs/ejs.d.ts diff --git a/ejs/ejs-tests.ts b/ejs/ejs-tests.ts new file mode 100644 index 0000000000..fd03dd1e09 --- /dev/null +++ b/ejs/ejs-tests.ts @@ -0,0 +1,4 @@ +/// +import ejs = require("ejs"); +var people = ['geddy', 'neil', 'alex']; +var html = ejs.render('<%= people.join(", "); %>', { people: people }); diff --git a/ejs/ejs.d.ts b/ejs/ejs.d.ts new file mode 100644 index 0000000000..95ca168c38 --- /dev/null +++ b/ejs/ejs.d.ts @@ -0,0 +1,91 @@ +// Type definitions for ejs.js v2.3.3 +// Project: http://ejs.co/ +// Definitions by: Ben Liddicott +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +declare module "ejs" { + module Ejs { + type Data = { [name: string]: any }; + type Dependencies = string[]; + var cache: Cache; + var localsName: string; + function resolveInclude(name: string, filename: string): string; + function compile(template: string, opts?: Options): (TemplateFunction); + function render(template: string, data?: Data, opts?: Options): string; + function renderFile(path: string, data?: Data, opts?: Options, cb?: Function): any;// TODO RenderFileCallback return type + function clearCache(): any; + + function TemplateFunction(data: Data): any; + interface TemplateFunction { + dependencies: Dependencies; + } + interface Options { + cache?: any; + filename?: string; + context?: any; + compileDebug?: boolean; + client?: boolean; + delimiter?: string; + debug?: any; + _with?: boolean; + } + class Template { + constructor(text: string, opts: Options); + opts: Options; + templateText: string; + mode: string; + truncate: boolean; + currentLine: number; + source: string; + dependencies: Dependencies; + createRegex(): RegExp; + compile(): TemplateFunction; + generateSource(): any; + parseTemplateText(): string[]; + scanLine(line: string): any; + + } + module Template { + interface MODES { + EVAL: string; + ESCAPED: string; + RAW: string; + COMMENT: string; + LITERAL: string; + } + } + function escapeRegexChars(s: string): string; + function escapeXML(markup: string): string; + function shallowCopy(to: T1, fro: any): T1; + interface Cache { + _data: { [name: string]: any }; + set(key: string, val: any); + get(key: string): any; + } + var cache: Cache; + function resolve(from1: string, to: string): string; + function resolve(from1: string, from2: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, from8: string, to: string): string; + function resolve(from1: string, from2: string, from3: string, from4: string, from5: string, from6: string, from7: string, from8: string, from9: string, to: string): string; + function resolve(...args: string[]): string; + function normalize(path: string): string; + function isAbsolute(path: string): boolean; + function join(...args: string[]): string; + function relative(from: string, to: string): string; + var sep: string; + var delimiter: string; + function dirname(path: string): string; + function basename(path: string): string; + function extname(path: string): string; + function filter(xs: any, f: any): any; // TODO WHUT? + + + } + export = Ejs; +} \ No newline at end of file From 8b36b63838077369de2eea584136c991bfb09393 Mon Sep 17 00:00:00 2001 From: benliddicott Date: Thu, 17 Sep 2015 15:46:41 +0100 Subject: [PATCH 5/7] add static-eval --- static-eval/static-eval-tests.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 static-eval/static-eval-tests.ts diff --git a/static-eval/static-eval-tests.ts b/static-eval/static-eval-tests.ts new file mode 100644 index 0000000000..5657a8c62b --- /dev/null +++ b/static-eval/static-eval-tests.ts @@ -0,0 +1,14 @@ +/// +/// + +import evaluate = require('static-eval'); +import parse = require('../esprima/esprima').parse; + +var src = '[1,2,3+4*10+n,foo(3+5),obj[""+"x"].y]'; +var ast = parse(src).body[0].expression; + +console.log(evaluate(ast, { + n: 6, + foo: function (x) { return x * 100 }, + obj: { x: { y: 555 } } +})); \ No newline at end of file From d464f5a4e10431a5f47e89666c933ff7a72d8313 Mon Sep 17 00:00:00 2001 From: benliddicott Date: Thu, 17 Sep 2015 15:51:30 +0100 Subject: [PATCH 6/7] Updated header --- static-eval/static-eval.d.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/static-eval/static-eval.d.ts b/static-eval/static-eval.d.ts index 61db0b4056..bb3461ad69 100644 --- a/static-eval/static-eval.d.ts +++ b/static-eval/static-eval.d.ts @@ -1,4 +1,10 @@ -declare module 'static-eval' { +// Type definitions for static-eval v0.2.4 +// Project: https://github.com/substack/static-eval +// Definitions by: Ben Liddicott +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +declare module 'static-eval' { function evaluate(ast, vars: { [name: string]: any }); export =evaluate; } From fcd91d68c8a4a72b5732c7ec5dc04010f888f89f Mon Sep 17 00:00:00 2001 From: benliddicott Date: Mon, 21 Sep 2015 11:37:37 +0100 Subject: [PATCH 7/7] Adding Ejs and static-eval --- ejs/ejs.d.ts | 4 ++-- static-eval/static-eval-tests.ts | 11 +++++++---- static-eval/static-eval.d.ts | 8 +++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ejs/ejs.d.ts b/ejs/ejs.d.ts index 95ca168c38..56e755a460 100644 --- a/ejs/ejs.d.ts +++ b/ejs/ejs.d.ts @@ -5,7 +5,7 @@ declare module "ejs" { - module Ejs { + namespace Ejs { type Data = { [name: string]: any }; type Dependencies = string[]; var cache: Cache; @@ -60,7 +60,7 @@ declare module "ejs" { function shallowCopy(to: T1, fro: any): T1; interface Cache { _data: { [name: string]: any }; - set(key: string, val: any); + set(key: string, val: any): any; get(key: string): any; } var cache: Cache; diff --git a/static-eval/static-eval-tests.ts b/static-eval/static-eval-tests.ts index 5657a8c62b..fe42c3d4d2 100644 --- a/static-eval/static-eval-tests.ts +++ b/static-eval/static-eval-tests.ts @@ -1,14 +1,17 @@ -/// /// +/// import evaluate = require('static-eval'); -import parse = require('../esprima/esprima').parse; +import esprima = require('esprima'); +var parse = esprima.parse; + var src = '[1,2,3+4*10+n,foo(3+5),obj[""+"x"].y]'; -var ast = parse(src).body[0].expression; + +var ast = ((parse(src).body[0])).expression; console.log(evaluate(ast, { n: 6, - foo: function (x) { return x * 100 }, + foo: function (x: number) { return x * 100 }, obj: { x: { y: 555 } } })); \ No newline at end of file diff --git a/static-eval/static-eval.d.ts b/static-eval/static-eval.d.ts index bb3461ad69..e44294c27e 100644 --- a/static-eval/static-eval.d.ts +++ b/static-eval/static-eval.d.ts @@ -3,8 +3,14 @@ // Definitions by: Ben Liddicott // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// declare module 'static-eval' { - function evaluate(ast, vars: { [name: string]: any }); + /** + * Evaluates the given ESTree.Expression, with the given named variables in place. + * @param ast [ESTree.Expression] An esprima expression derived from parse.body[].expression + * @param vars Named variables, objects or functions which may be referenced in the expression. + */ + function evaluate(ast : ESTree.Expression, vars: { [name: string]: any }): any; export =evaluate; }