Skip to content

Commit 91a66c8

Browse files
committed
tighten parser union type
1 parent c7f05f0 commit 91a66c8

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

resources/buildConfigDefinitions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function mapperFor(elt, t) {
160160
return wrap(t.identifier('objectParser'));
161161
} else if (t.isUnionTypeAnnotation(elt)) {
162162
const unionTypes = elt.typeAnnotation?.types || elt.types;
163-
if (unionTypes?.some(type => t.isBooleanTypeAnnotation(type))) {
163+
if (unionTypes?.some(type => t.isBooleanTypeAnnotation(type)) && unionTypes?.some(type => t.isFunctionTypeAnnotation(type))) {
164164
return wrap(t.identifier('booleanOrFunctionParser'));
165165
}
166166
} else if (t.isGenericTypeAnnotation(elt)) {

spec/buildConfigDefinitions.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ describe('buildConfigDefinitions', () => {
183183
expect(result).toBeUndefined();
184184
});
185185

186+
it('should return undefined for UnionTypeAnnotation with boolean but without function', () => {
187+
const mockElement = {
188+
type: 'UnionTypeAnnotation',
189+
typeAnnotation: {
190+
types: [
191+
{ type: 'BooleanTypeAnnotation' },
192+
{ type: 'VoidTypeAnnotation' },
193+
],
194+
},
195+
};
196+
197+
const result = mapperFor(mockElement, t);
198+
199+
expect(result).toBeUndefined();
200+
});
201+
186202
it('should return objectParser for unknown GenericTypeAnnotation', () => {
187203
const mockElement = {
188204
type: 'GenericTypeAnnotation',

0 commit comments

Comments
 (0)