fix(validator): don't count keys of array destructuring assignment in property refs

This commit is contained in:
Bowen Tan 2022-07-29 16:52:08 +08:00
parent a1c2730fc5
commit 81028bbf42
2 changed files with 10 additions and 0 deletions

View File

@ -106,6 +106,12 @@ describe('Field test', () => {
expect(field.refComponentInfos).toEqual({});
});
it('should not count keys of array destructuring assignment in refs', () => {
const field = new FieldModel('{{ ([bar]) => bar }}');
expect(field.isDynamic).toEqual(true);
expect(field.refComponentInfos).toEqual({});
});
it('get value by path', () => {
const field = new FieldModel({ foo: [{}, { bar: { baz: 'Hello, world!' } }] });
expect(field.getPropertyByPath('foo.1.bar.baz')?.getValue()).toEqual('Hello, world!');

View File

@ -22,6 +22,7 @@ import { JSONSchema7 } from 'json-schema';
export type FunctionNode = ASTNode & { params: ASTNode[] };
export type DeclaratorNode = ASTNode & { id: ASTNode };
export type ObjectPatternNode = ASTNode & { properties: PropertyNode[] };
export type ArrayPatternNode = ASTNode & { elements: ASTNode[] };
export type PropertyNode = ASTNode & { value: ASTNode };
export type LiteralNode = ASTNode & { raw: string };
export type SequenceExpressionNode = ASTNode & { expressions: LiteralNode[] };
@ -224,6 +225,9 @@ export class FieldModel implements IFieldModel {
whiteList.push(property.value);
});
},
ArrayPattern: arrayPatternNode => {
whiteList = [...whiteList, ...(arrayPatternNode as ArrayPatternNode).elements];
},
VariableDeclarator: declarator => {
whiteList.push((declarator as DeclaratorNode).id);
},