本文整理匯總了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);
}
});