mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:48:13 +08:00
fix: text文本框下默认值不支持不加空格的“-”减法运算
This commit is contained in:
parent
3552983f74
commit
6febae76df
@ -10,7 +10,11 @@ exports[`lexer:filter 1`] = `
|
|||||||
"<Identifier> date",
|
"<Identifier> date",
|
||||||
"<Punctuator> :",
|
"<Punctuator> :",
|
||||||
"<Char> ",
|
"<Char> ",
|
||||||
"<Identifier> YYYY-MM-DD",
|
"<Identifier> YYYY",
|
||||||
|
"<Punctuator> -",
|
||||||
|
"<Identifier> MM",
|
||||||
|
"<Punctuator> -",
|
||||||
|
"<Identifier> DD",
|
||||||
"<Char> ",
|
"<Char> ",
|
||||||
"<Identifier> HH:mm:ss",
|
"<Identifier> HH:mm:ss",
|
||||||
"<CloseScript> }",
|
"<CloseScript> }",
|
||||||
|
@ -270,14 +270,14 @@ test('evalute:literal', async () => {
|
|||||||
|
|
||||||
test('evalute:variableName', async () => {
|
test('evalute:variableName', async () => {
|
||||||
const data = {
|
const data = {
|
||||||
'a-b': 'c',
|
'a_b': 'c',
|
||||||
'222': 10222,
|
'222': 10222,
|
||||||
'222_221': 233,
|
'222_221': 233,
|
||||||
'222_abcde': 'abcde',
|
'222_abcde': 'abcde',
|
||||||
'222-221': 333
|
'222-221': 333
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(await evaluateForAsync('${a-b}', data)).toBe('c');
|
expect(await evaluateForAsync('${a_b}', data)).toBe('c');
|
||||||
expect(await evaluateForAsync('${222}', data)).toBe(222);
|
expect(await evaluateForAsync('${222}', data)).toBe(222);
|
||||||
expect(await evaluateForAsync('${222_221}', data)).toBe('233');
|
expect(await evaluateForAsync('${222_221}', data)).toBe('233');
|
||||||
expect(await evaluateForAsync('${222-221}', data)).toBe(1);
|
expect(await evaluateForAsync('${222-221}', data)).toBe(1);
|
||||||
|
@ -256,14 +256,14 @@ test('evalute:literal', () => {
|
|||||||
|
|
||||||
test('evalute:variableName', () => {
|
test('evalute:variableName', () => {
|
||||||
const data = {
|
const data = {
|
||||||
'a-b': 'c',
|
'a_b': 'c',
|
||||||
'222': 10222,
|
'222': 10222,
|
||||||
'222_221': 233,
|
'222_221': 233,
|
||||||
'222_abcde': 'abcde',
|
'222_abcde': 'abcde',
|
||||||
'222-221': 333
|
'222-221': 333
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(evaluate('${a-b}', data)).toBe('c');
|
expect(evaluate('${a_b}', data)).toBe('c');
|
||||||
expect(evaluate('${222}', data)).toBe(222);
|
expect(evaluate('${222}', data)).toBe(222);
|
||||||
expect(evaluate('${222_221}', data)).toBe('233');
|
expect(evaluate('${222_221}', data)).toBe('233');
|
||||||
expect(evaluate('${222-221}', data)).toBe(1);
|
expect(evaluate('${222-221}', data)).toBe(1);
|
||||||
|
@ -728,7 +728,7 @@ export function lexer(input: string, options?: LexerOptions) {
|
|||||||
// 所以纯变量模式支持纯数字作为变量名
|
// 所以纯变量模式支持纯数字作为变量名
|
||||||
const reg = options?.variableMode
|
const reg = options?.variableMode
|
||||||
? /^[\u4e00-\u9fa5A-Za-z0-9_$@][\u4e00-\u9fa5A-Za-z0-9_\-$@]*/
|
? /^[\u4e00-\u9fa5A-Za-z0-9_$@][\u4e00-\u9fa5A-Za-z0-9_\-$@]*/
|
||||||
: /^(?:[\u4e00-\u9fa5A-Za-z_$@]([\u4e00-\u9fa5A-Za-z0-9_\-$@]|\\(?:\.|\[|\]|\(|\)|\{|\}|\s|=|!|>|<|\||&|\+|-|\*|\/|\^|~|%|&|\?|:|;|,))*|\d+[\u4e00-\u9fa5A-Za-z_$@](?:[\u4e00-\u9fa5A-Za-z0-9_\-$@]|\\(?:\.|\[|\]|\(|\)|\{|\}|\s|=|!|>|<|\||&|\+|-|\*|\/|\^|~|%|&|\?|:|;|,))*)/;
|
: /^(?:[\u4e00-\u9fa5A-Za-z_$@]([\u4e00-\u9fa5A-Za-z0-9_$@]|\\(?:\.|\[|\]|\(|\)|\{|\}|\s|=|!|>|<|\||&|\+|-|\*|\/|\^|~|%|&|\?|:|;|,))*|\d+[\u4e00-\u9fa5A-Za-z_$@](?:[\u4e00-\u9fa5A-Za-z0-9_$@]|\\(?:\.|\[|\]|\(|\)|\{|\}|\s|=|!|>|<|\||&|\+|-|\*|\/|\^|~|%|&|\?|:|;|,))*)/;
|
||||||
|
|
||||||
const match = reg.exec(
|
const match = reg.exec(
|
||||||
input.substring(index, index + 256) // 变量长度不能超过 256
|
input.substring(index, index + 256) // 变量长度不能超过 256
|
||||||
|
Loading…
Reference in New Issue
Block a user