( expression: string, data: Record<string, any> )
| 2325 | } |
| 2326 | |
| 2327 | export function evalTrackExpression( |
| 2328 | expression: string, |
| 2329 | data: Record<string, any> |
| 2330 | ) { |
| 2331 | if (typeof expression !== 'string') { |
| 2332 | return ''; |
| 2333 | } |
| 2334 | |
| 2335 | const parts: Array<{ |
| 2336 | type: 'text' | 'script'; |
| 2337 | value: string; |
| 2338 | }> = []; |
| 2339 | while (true) { |
| 2340 | // 这个是自动提取的时候才会用到,用户配置不要用到这个语法 |
| 2341 | const idx = expression.indexOf('<script>'); |
| 2342 | if (idx === -1) { |
| 2343 | break; |
| 2344 | } |
| 2345 | const endIdx = expression.indexOf('</script>'); |
| 2346 | if (endIdx === -1) { |
| 2347 | throw new Error( |
| 2348 | 'Invalid trackExpression miss end script token `</script>`' |
| 2349 | ); |
| 2350 | } |
| 2351 | if (idx) { |
| 2352 | parts.push({ |
| 2353 | type: 'text', |
| 2354 | value: expression.substring(0, idx) |
| 2355 | }); |
| 2356 | } |
| 2357 | |
| 2358 | parts.push({ |
| 2359 | type: 'script', |
| 2360 | value: expression.substring(idx + 8, endIdx) |
| 2361 | }); |
| 2362 | expression = expression.substring(endIdx + 9); |
| 2363 | } |
| 2364 | |
| 2365 | expression && |
| 2366 | parts.push({ |
| 2367 | type: 'text', |
| 2368 | value: expression |
| 2369 | }); |
| 2370 | |
| 2371 | return parts |
| 2372 | .map(item => { |
| 2373 | if (item.type === 'text') { |
| 2374 | return tokenize(item.value, data); |
| 2375 | } |
| 2376 | |
| 2377 | return evalExpression(item.value, data); |
| 2378 | }) |
| 2379 | .join(''); |
| 2380 | } |
| 2381 | |
| 2382 | // 很奇怪的问题,react-json-view import 有些情况下 mod.default 才是 esModule |
| 2383 | export function importLazyComponent(mod: any) { |
no test coverage detected