Skip to content

Commit fcd91d6

Browse files
committed
Adding Ejs and static-eval
1 parent d464f5a commit fcd91d6

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

ejs/ejs.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
declare module "ejs" {
8-
module Ejs {
8+
namespace Ejs {
99
type Data = { [name: string]: any };
1010
type Dependencies = string[];
1111
var cache: Cache;
@@ -60,7 +60,7 @@ declare module "ejs" {
6060
function shallowCopy<T1>(to: T1, fro: any): T1;
6161
interface Cache {
6262
_data: { [name: string]: any };
63-
set(key: string, val: any);
63+
set(key: string, val: any): any;
6464
get(key: string): any;
6565
}
6666
var cache: Cache;

static-eval/static-eval-tests.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
/// <reference path="static-eval.d.ts" />
21
/// <reference path="../esprima/esprima.d.ts" />
2+
/// <reference path="static-eval.d.ts" />
33

44
import evaluate = require('static-eval');
5-
import parse = require('../esprima/esprima').parse;
5+
import esprima = require('esprima');
6+
var parse = esprima.parse;
7+
68

79
var src = '[1,2,3+4*10+n,foo(3+5),obj[""+"x"].y]';
8-
var ast = parse(src).body[0].expression;
10+
11+
var ast = (<ESTree.ExpressionStatement>(parse(src).body[0])).expression;
912

1013
console.log(evaluate(ast, {
1114
n: 6,
12-
foo: function (x) { return x * 100 },
15+
foo: function (x: number) { return x * 100 },
1316
obj: { x: { y: 555 } }
1417
}));

static-eval/static-eval.d.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// Definitions by: Ben Liddicott <https://github.com/benliddicott/DefinitelyTyped>
44
// Definitions: https://github.com/borisyankov/DefinitelyTyped
55

6+
/// <reference path="../esprima/esprima.d.ts" />
67

78
declare module 'static-eval' {
8-
function evaluate(ast, vars: { [name: string]: any });
9+
/**
10+
* Evaluates the given ESTree.Expression, with the given named variables in place.
11+
* @param ast [ESTree.Expression] An esprima expression derived from parse.body[].expression
12+
* @param vars Named variables, objects or functions which may be referenced in the expression.
13+
*/
14+
function evaluate(ast : ESTree.Expression, vars: { [name: string]: any }): any;
915
export =evaluate;
1016
}

0 commit comments

Comments
 (0)