Prechádzať zdrojové kódy

js-ast语法分析、高级编辑器
TextDesign / ButtonDesign / BaseDesign

luoyifan 3 rokov pred
rodič
commit
5a11816a34
2 zmenil súbory, kde vykonal 23 pridanie a 4 odobranie
  1. 3 3
      src/index.ts
  2. 20 1
      src/lib/systemLib.ts

+ 3 - 3
src/index.ts

@@ -7,6 +7,7 @@ import json5 from 'json5'
 import moment from 'moment'
 import './wotu-ui.css'
 import {PropertyDescriptionTable} from './PropertyDescriptionTable'
+import * as recast from 'recast'
 
 export {
     axios,
@@ -16,14 +17,13 @@ export {
     json5,
     moment,
     Defaults,
-    PropertyDescriptionTable
+    PropertyDescriptionTable,
+    recast,
 }
 
-export * from './message'
 export * from './Scope'
 export * from './init'
 export * from './lib/ajax'
 export * from './lib/Lib'
 export * from './lib/config'
 export * from './lib/systemLib'
-export * from './lib/systemLibEval'

+ 20 - 1
src/lib/systemLib.ts

@@ -2,7 +2,6 @@ import _ from 'lodash'
 import {Lib, lookupScope} from './lib'
 import {ajax} from "./config";
 import {msg as msgSimple, showErrorDialog as showErrorDialogSimple} from "../message";
-import {evalFunction} from "./systemLibEval";
 
 export const SIMPLE_RE = /^(?:\{(?:(\d+)|([a-z_][\w\.]*))\})$/i
 
@@ -1145,4 +1144,24 @@ export function msg(content) {
  */
 export function showErrorDialog(msg, sender?) {
     showErrorDialogSimple(msg, sender)
+}
+
+/**
+ * 用于计算 express 表达式
+ */
+export function evalFunction(data, express) {
+    const keys = []
+    const values = []
+    _.forOwn(data, (value, key) => {
+        keys.push(key)
+        values.push(value)
+    })
+
+    const func = Function(...keys, 'return ' + express)
+
+    try {
+        return func(...values)
+    } catch (e) {
+        return
+    }
 }