UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

43 lines (36 loc) 814 B
import { parse } from 'amis-formula'; const cache = <any>{}; export function memoryParse( input: string, options: { /** * 直接是运算表达式?还是从模板开始 ${} 里面才算运算表达式 */ evalMode?: boolean; /** * 只支持取变量。 */ variableMode?: boolean; /** * 是否允许 filter 语法,比如: * * ${abc | html} */ allowFilter?: boolean; variableNamespaces?: Array<string>; } = { evalMode: false } ) { // @todo 优化内存缓存释放,比如只缓存最高频的模版 if (typeof input !== 'string') { return; } const key = input + JSON.stringify(options); if (cache[key]) { return cache[key]; } const ast = parse(input, options); cache[key] = ast; return ast; }