inline variable has no identifier and should not cause runtime error

This commit is contained in:
Yanzhen Yu 2022-05-16 10:28:42 +08:00
parent b36dfddeb5
commit da033ab695
2 changed files with 12 additions and 6 deletions

View File

@ -15,6 +15,12 @@ describe('Field test', () => {
expect(field.rawValue).toEqual('{{input.value}} + {{list[0].text}}');
});
it('parse inline variable in expression', () => {
const field = new FieldModel('{{ [].length }}');
expect(field.isDynamic).toEqual(true);
expect(field.refs).toEqual({});
});
it('parse object property', () => {
const field = new FieldModel({ raw: '{{input.value}}', format: 'md' });
expect(field.isDynamic).toEqual(false);
@ -47,11 +53,11 @@ describe('Field test', () => {
const field = new FieldModel({ data: ['A', 'B'] });
expect(field.rawValue).toEqual({ data: ['A', 'B'] });
field.update({data: ['B']});
field.update({ data: ['B'] });
expect(field.rawValue).toEqual({ data: ['B'] });
field.update({data: ['C']});
field.update({ data: ['C'] });
expect(field.rawValue).toEqual({ data: ['C'] });
})
});
it('update object property', () => {
const field = new FieldModel({ data: { a: 1, b: 2 }, value: '' });
@ -63,5 +69,5 @@ describe('Field test', () => {
expect(field.rawValue).toEqual({ data: { a: 2 }, value: '' });
field.update({ value: 'text' });
expect(field.rawValue).toEqual({ data: { a: 2 }, value: 'text' });
})
});
});

View File

@ -125,7 +125,7 @@ export class FieldModel implements IFieldModel {
if (path.startsWith('.')) {
path = path.slice(1, path.length);
}
this.refs[lastIdentifier].push(path);
this.refs[lastIdentifier]?.push(path);
break;
default:
}