本文整理汇总了TypeScript中@project/expression/src/exports.expression_parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript expression_parse函数的具体用法?TypeScript expression_parse怎么用?TypeScript expression_parse使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了expression_parse函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: expression_parse
var awaiters = arr.map(async str => {
var ast = expression_parse('"I`m " + user->name + user->name');
eq_(ast.async, true);
var user = {name: 'John'};
var result = await expression_eval(ast, { user });
deepEq_(result, 'I`m JohnJohn');
});
示例2: require
import { expression_eval, expression_parse } from '@project/expression/src/exports';
import { listeners_on, listeners_off } from '@core/util/listeners'
import sinon = require('sinon');
UTest({
$config: {
breakOnError: true
},
async 'should parse and evaluate simple expression' () {
var ast = expression_parse('await someFn()');
eq_(ast.async, true);
var someFn = sinon.spy(async function(){
return { foo: 'Foo'};
})
var dfr = expression_eval(ast, { someFn })
is_(dfr.then, 'Function');
var result = await dfr;
deepEq_(result, {foo: 'Foo'});
eq_(someFn.callCount, 1);
eq_(someFn.args[0].length, 0);
},
'getters on statements': {
'should run getter on SYNC statement' () {
var someFn = assert.await(function(){
示例3: UTest
import { expression_parse } from '@project/expression/src/exports';
UTest({
'should serialize function call with arguments' () {
let expr = 'this.foo(bar)';
let ast = expression_parse(expr);
let str = ast.toString();
eq_(str, expr);
}
});