mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2025-04-06 21:40:23 +08:00
fix(validator): it should not warn variables declared in iife in expression
This commit is contained in:
parent
41c8267384
commit
7f2fdd5f63
@ -71,6 +71,12 @@ describe('Field test', () => {
|
||||
expect(field.refComponentInfos).toEqual({});
|
||||
});
|
||||
|
||||
it('should not count variables declared in iife in refs', () => {
|
||||
const field = new FieldModel('{{(function() {const foo = "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!');
|
||||
|
@ -20,6 +20,7 @@ import escodegen from 'escodegen';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
|
||||
export type FunctionNode = ASTNode & { params: ASTNode[] };
|
||||
export type DeclaratorNode = ASTNode & { id: ASTNode };
|
||||
export class FieldModel implements IFieldModel {
|
||||
isDynamic = false;
|
||||
refComponentInfos: Record<ComponentId | ModuleId, RefInfo> = {};
|
||||
@ -161,7 +162,7 @@ export class FieldModel implements IFieldModel {
|
||||
|
||||
this.astNodes[exp] = node as ASTNode;
|
||||
|
||||
// These are varirables of iife, they should be count in refs.
|
||||
// These are variables of iife, they should be count in refs.
|
||||
let localVariables: ASTNode[] = [];
|
||||
|
||||
simpleWalk(node, {
|
||||
@ -200,6 +201,9 @@ export class FieldModel implements IFieldModel {
|
||||
default:
|
||||
}
|
||||
},
|
||||
VariableDeclarator: declarator => {
|
||||
localVariables.push((declarator as DeclaratorNode).id);
|
||||
},
|
||||
});
|
||||
|
||||
// remove localVariables from refs
|
||||
|
Loading…
x
Reference in New Issue
Block a user