mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
Adding Ejs and static-eval
This commit is contained in:
parent
d464f5a4e1
commit
fcd91d68c8
4
ejs/ejs.d.ts
vendored
4
ejs/ejs.d.ts
vendored
@ -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;
|
||||
|
||||
@ -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 } }
|
||||
}));
|
||||
8
static-eval/static-eval.d.ts
vendored
8
static-eval/static-eval.d.ts
vendored
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user