MCPcopy
hub / github.com/alibaba/lowcode-engine / parseExpression

Function parseExpression

packages/renderer-core/src/utils/common.ts:208–245  ·  view source on GitHub ↗
(a: any, b?: any, c = false)

Source from the content-addressed store, hash-verified

206}): any;
207function parseExpression(str: any, self: any, thisRequired?: boolean): any;
208function parseExpression(a: any, b?: any, c = false) {
209 let str;
210 let self;
211 let thisRequired;
212 let logScope;
213 if (typeof a === 'object' && b === undefined) {
214 str = a.str;
215 self = a.self;
216 thisRequired = a.thisRequired;
217 logScope = a.logScope;
218 } else {
219 str = a;
220 self = b;
221 thisRequired = c;
222 }
223 try {
224 const contextArr = ['"use strict";', 'var __self = arguments[0];'];
225 contextArr.push('return ');
226 let tarStr: string;
227
228 tarStr = (str.value || '').trim();
229
230 // NOTE: use __self replace 'this' in the original function str
231 // may be wrong in extreme case which contains '__self' already
232 tarStr = tarStr.replace(/this(\W|$)/g, (_a: any, b: any) => `__self${b}`);
233 tarStr = contextArr.join('\n') + tarStr;
234
235 // 默认调用顶层窗口的parseObj, 保障new Function的window对象是顶层的window对象
236 if (inSameDomain() && (window.parent as any).__newFunc) {
237 return (window.parent as any).__newFunc(tarStr)(self);
238 }
239 const code = `with(${thisRequired ? '{}' : '$scope || {}'}) { ${tarStr} }`;
240 return new Function('$scope', code)(self);
241 } catch (err) {
242 logger.error(`${logScope || ''} parseExpression.error`, err, str, self?.__self ?? self);
243 return undefined;
244 }
245}
246
247export {
248 parseExpression,

Callers 6

executeLifeCycleMethodFunction · 0.90
constructorMethod · 0.90
common.test.tsFile · 0.90
parseI18nFunction · 0.70
parseDataFunction · 0.70

Calls 4

inSameDomainFunction · 0.85
pushMethod · 0.80
replaceMethod · 0.80
errorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…