Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Codegen]: Extract contents of the case 'VoidTypeAnnotation' into a single emitVoid function #34932

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,6 +17,7 @@ const {
emitNumber,
emitInt32,
emitRootTag,
emitVoid,
typeAliasResolution,
} = require('../parsers-primitives.js');

Expand Down Expand Up @@ -150,6 +151,32 @@ describe('emitDouble', () => {
});
});

describe('emitVoid', () => {
describe('when nullable is true', () => {
it('returns nullable type annotation', () => {
const result = emitVoid(true);
const expected = {
type: 'NullableTypeAnnotation',
typeAnnotation: {
type: 'VoidTypeAnnotation',
},
};

expect(result).toEqual(expected);
});
});
describe('when nullable is false', () => {
it('returns non nullable type annotation', () => {
const result = emitVoid(false);
const expected = {
type: 'VoidTypeAnnotation',
};

expect(result).toEqual(expected);
});
});
});

describe('typeAliasResolution', () => {
const objectTypeAnnotation = {
type: 'ObjectTypeAnnotation',
Expand Down
Expand Up @@ -39,6 +39,7 @@ const {
emitNumber,
emitInt32,
emitRootTag,
emitVoid,
typeAliasResolution,
} = require('../../parsers-primitives');
const {
Expand Down Expand Up @@ -343,9 +344,7 @@ function translateTypeAnnotation(
return emitNumber(nullable);
}
case 'VoidTypeAnnotation': {
return wrapNullable(nullable, {
type: 'VoidTypeAnnotation',
});
return emitVoid(nullable);
}
case 'StringTypeAnnotation': {
return wrapNullable(nullable, {
Expand Down
Expand Up @@ -21,6 +21,7 @@ import type {
Int32TypeAnnotation,
ReservedTypeAnnotation,
ObjectTypeAnnotation,
VoidTypeAnnotation,
} from '../CodegenSchema';
import type {TypeAliasResolutionStatus} from './utils';

Expand Down Expand Up @@ -59,6 +60,12 @@ function emitDouble(nullable: boolean): Nullable<DoubleTypeAnnotation> {
});
}

function emitVoid(nullable: boolean): Nullable<VoidTypeAnnotation> {
return wrapNullable(nullable, {
type: 'VoidTypeAnnotation',
});
}

function typeAliasResolution(
typeAliasResolutionStatus: TypeAliasResolutionStatus,
objectTypeAnnotation: ObjectTypeAnnotation<
Expand Down Expand Up @@ -119,5 +126,6 @@ module.exports = {
emitInt32,
emitNumber,
emitRootTag,
emitVoid,
typeAliasResolution,
};
Expand Up @@ -39,6 +39,7 @@ const {
emitNumber,
emitInt32,
emitRootTag,
emitVoid,
typeAliasResolution,
} = require('../../parsers-primitives');
const {
Expand Down Expand Up @@ -379,9 +380,7 @@ function translateTypeAnnotation(
return emitNumber(nullable);
}
case 'TSVoidKeyword': {
return wrapNullable(nullable, {
type: 'VoidTypeAnnotation',
});
return emitVoid(nullable);
}
case 'TSStringKeyword': {
return wrapNullable(nullable, {
Expand Down