From bd7ebb40cc5e019784c847bc3cbd6124a2948899 Mon Sep 17 00:00:00 2001 From: charlzyx Date: Fri, 29 Nov 2024 16:12:20 +0800 Subject: [PATCH] feat: (core) x-compile-omitted supports object path-like keys --- .../src/__tests__/compiler.spec.ts | 23 ++++++++++++++++++- packages/json-schema/src/shared.ts | 5 +++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/json-schema/src/__tests__/compiler.spec.ts b/packages/json-schema/src/__tests__/compiler.spec.ts index 6abe8705ccb..e591ad9d8a5 100644 --- a/packages/json-schema/src/__tests__/compiler.spec.ts +++ b/packages/json-schema/src/__tests__/compiler.spec.ts @@ -271,11 +271,17 @@ test('patchSchemaCompile x-compile-omitted', () => { const targetState = { title: '', validator: [], + componentProps: { + aa: 0, + }, } patchSchemaCompile( targetState as any, { title: '132', + 'x-component-props': { + aa: '{{field.value}}', + }, 'x-validator': [ { remoteCheckUniq: '{{field.value}}', @@ -292,17 +298,28 @@ test('patchSchemaCompile x-compile-omitted', () => { expect(targetState).toEqual({ title: '132', validator: [{ remoteCheckUniq: 888 }], + componentProps: { + aa: 888, + }, }) const targetOmitState = { title: '', validator: [], + componentProps: { + aa: 0, + bb: 0, + }, } patchSchemaCompile( targetOmitState as any, { title: '132', - 'x-compile-omitted': ['x-validator'], + 'x-compile-omitted': ['x-validator', 'x-component-props.aa'], + 'x-component-props': { + aa: '{{field.value}}', + bb: '{{field.value}}', + }, 'x-validator': [ { remoteCheckUniq: '{{field.value}}', @@ -318,6 +335,10 @@ test('patchSchemaCompile x-compile-omitted', () => { ) expect(targetOmitState).toEqual({ title: '132', + componentProps: { + aa: '{{field.value}}', + bb: 888, + }, validator: [{ remoteCheckUniq: '{{field.value}}' }], }) }) diff --git a/packages/json-schema/src/shared.ts b/packages/json-schema/src/shared.ts index 7ed112c82a4..3920605cdc6 100644 --- a/packages/json-schema/src/shared.ts +++ b/packages/json-schema/src/shared.ts @@ -119,7 +119,10 @@ export const traverseSchema = ( return if (String(path[0]).indexOf('x-') == -1 && isFn(target)) return if (SchemaNestedMap[path[0]]) return - if (schema['x-compile-omitted']?.indexOf(path[0]) > -1) { + if ( + schema['x-compile-omitted']?.indexOf(path[0]) > -1 || + schema['x-compile-omitted']?.indexOf(path.join('.')) > -1 + ) { visitor(target, path, true) return }