mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-04 12:58:38 +08:00
parent
3b31bc3264
commit
ce77ea2980
@ -959,10 +959,39 @@ export function dataMapping(
|
||||
return ret;
|
||||
}
|
||||
|
||||
function matchSynatax(str: string) {
|
||||
let from = 0;
|
||||
while (true) {
|
||||
const idx = str.indexOf('$', from);
|
||||
if (~idx) {
|
||||
const nextToken = str[idx + 1];
|
||||
|
||||
// 如果没有下一个字符,或者下一个字符是引号或者空格
|
||||
// 这个一般不是取值用法
|
||||
if (!nextToken || ~['"', "'", ' '].indexOf(nextToken)) {
|
||||
from = idx + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 如果上个字符是转义也不是取值用法
|
||||
const prevToken = str[idx - 1];
|
||||
if (prevToken && prevToken === '\\') {
|
||||
from = idx + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function register(): Enginer & {name: string} {
|
||||
return {
|
||||
name: 'builtin',
|
||||
test: (str: string) => typeof str === 'string' && /(?<!\\)\$\S/.test(str),
|
||||
test: (str: string) => typeof str === 'string' && matchSynatax(str),
|
||||
removeEscapeToken: (str: string) =>
|
||||
typeof str === 'string' ? str.replace(/\\\$/g, '$') : str,
|
||||
compile: (str: string, data: object, defaultFilter = '| html') =>
|
||||
|
Loading…
Reference in New Issue
Block a user