Skip to content

Commit

Permalink
feat: (core) x-compile-omitted supports object path-like keys
Browse files Browse the repository at this point in the history
  • Loading branch information
charlzyx committed Nov 29, 2024
1 parent 5f9411f commit bd7ebb4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 22 additions & 1 deletion packages/json-schema/src/__tests__/compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}}',
Expand All @@ -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}}',
Expand All @@ -318,6 +335,10 @@ test('patchSchemaCompile x-compile-omitted', () => {
)
expect(targetOmitState).toEqual({
title: '132',
componentProps: {
aa: '{{field.value}}',
bb: 888,
},
validator: [{ remoteCheckUniq: '{{field.value}}' }],
})
})
Expand Down
5 changes: 4 additions & 1 deletion packages/json-schema/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit bd7ebb4

Please sign in to comment.