Adding Ejs and static-eval

This commit is contained in:
benliddicott 2015-09-21 11:37:37 +01:00
parent d464f5a4e1
commit fcd91d68c8
3 changed files with 16 additions and 7 deletions

4
ejs/ejs.d.ts vendored
View File

@ -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<T1>(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;

View File

@ -1,14 +1,17 @@
/// <reference path="static-eval.d.ts" />
/// <reference path="../esprima/esprima.d.ts" />
/// <reference path="static-eval.d.ts" />
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 = (<ESTree.ExpressionStatement>(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 } }
}));

View File

@ -3,8 +3,14 @@
// Definitions by: Ben Liddicott <https://github.com/benliddicott/DefinitelyTyped>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../esprima/esprima.d.ts" />
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;
}