Skip to content

Commit

Permalink
Extracted TypeDeclarationMap from flow and typescript to a common fil…
Browse files Browse the repository at this point in the history
…e parsers/utils.js (#34951)

Summary:
This PR is a part of #34872.
This PR extracts TypeDeclarationMap type from flow and typescript to a common file parsers/utils.js and updates all imports.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extracted TypeDeclarationMap from flow and typescript to a common file parsers/utils.js.

Pull Request resolved: #34951

Test Plan:
yarn jest react-native-codegen
<img width="1129" alt="Screenshot 2022-10-12 at 12 13 48 PM" src="https://user-images.githubusercontent.com/87412080/195270569-fc077863-7e51-49e8-92ef-f3991f838d6a.png">

Reviewed By: NickGerleman

Differential Revision: D40296917

Pulled By: cipolleschi

fbshipit-source-id: d073daf0aadc291d5f9d00c003f0161af9e11319
  • Loading branch information
Vinay Harwani authored and facebook-github-bot committed Oct 13, 2022
1 parent 96027f7 commit 2934399
Show file tree
Hide file tree
Showing 19 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
NamedShape,
CommandTypeAnnotation,
} from '../../../CodegenSchema.js';
import type {TypeDeclarationMap} from '../utils.js';
import type {TypeDeclarationMap} from '../../utils';

const {getValueFromTypes} = require('../utils.js');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
'use strict';

import type {ASTNode} from '../utils';
import type {TypeDeclarationMap} from '../utils.js';
import type {NamedShape} from '../../../CodegenSchema.js';
const {getValueFromTypes} = require('../utils.js');
import type {TypeDeclarationMap} from '../../utils';

function getProperties(
typeName: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

import type {ExtendsPropsShape} from '../../../CodegenSchema.js';
import type {TypeDeclarationMap} from '../utils.js';
import type {TypeDeclarationMap} from '../../utils';

function extendsForProp(prop: PropsAST, types: TypeDeclarationMap) {
if (!prop.argument) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

'use strict';
import type {TypeDeclarationMap} from '../utils';
import type {TypeDeclarationMap} from '../../utils';
import type {CommandOptions} from './options';
import type {ComponentSchemaBuilderConfig} from './schema.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
} = require('./componentsUtils.js');

import type {NamedShape, PropTypeAnnotation} from '../../../CodegenSchema.js';
import type {TypeDeclarationMap} from '../utils.js';
import type {TypeDeclarationMap} from '../../utils';

// $FlowFixMe[unclear-type] there's no flowtype for ASTs
type PropAST = Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
} = require('./componentsUtils.js');

import type {StateTypeAnnotation, NamedShape} from '../../../CodegenSchema.js';
import type {TypeDeclarationMap} from '../utils.js';
import type {TypeDeclarationMap} from '../../utils';

// $FlowFixMe[unclear-type] there's no flowtype for ASTs
type PropAST = Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import type {
Nullable,
} from '../../../CodegenSchema.js';

import type {TypeDeclarationMap} from '../utils.js';
import type {ParserErrorCapturer} from '../../utils';
import type {ParserErrorCapturer, TypeDeclarationMap} from '../../utils';
import type {NativeModuleTypeAnnotation} from '../../../CodegenSchema.js';

const {
Expand Down
3 changes: 1 addition & 2 deletions packages/react-native-codegen/src/parsers/flow/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import type {TypeAliasResolutionStatus} from '../utils';
import type {TypeAliasResolutionStatus, TypeDeclarationMap} from '../utils';

/**
* This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias
Expand All @@ -20,7 +20,6 @@ import type {TypeAliasResolutionStatus} from '../utils';
*
* TODO(T71778680): Flow type AST Nodes
*/
export type TypeDeclarationMap = {[declarationName: string]: $FlowFixMe};

function getTypes(ast: $FlowFixMe): TypeDeclarationMap {
return ast.body.reduce((types, node) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
NamedShape,
CommandTypeAnnotation,
} from '../../../CodegenSchema.js';
import type {TypeDeclarationMap} from '../utils.js';
import type {TypeDeclarationMap} from '../../utils';
const {parseTopLevelType} = require('../parseTopLevelType');

type EventTypeAST = Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

'use strict';
import type {ASTNode} from '../utils';
import type {TypeDeclarationMap} from '../utils.js';
import type {NamedShape} from '../../../CodegenSchema.js';
const {parseTopLevelType} = require('../parseTopLevelType');
import type {TypeDeclarationMap} from '../../utils';

function getProperties(
typeName: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import type {
NamedShape,
EventTypeAnnotation,
} from '../../../CodegenSchema.js';
import type {TypeDeclarationMap} from '../../utils';
const {flattenProperties} = require('./componentsUtils');
const {parseTopLevelType} = require('../parseTopLevelType');
import type {TypeDeclarationMap} from '../utils.js';

function getPropertyType(
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

import type {ExtendsPropsShape} from '../../../CodegenSchema.js';
import type {TypeDeclarationMap} from '../utils.js';
import type {TypeDeclarationMap} from '../../utils';

function extendsForProp(prop: PropsAST, types: TypeDeclarationMap) {
if (!prop.expression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

'use strict';
import type {TypeDeclarationMap} from '../utils';
import type {TypeDeclarationMap} from '../../utils';
import type {CommandOptions} from './options';
import type {ComponentSchemaBuilderConfig} from './schema.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
} = require('./componentsUtils.js');

import type {NamedShape, PropTypeAnnotation} from '../../../CodegenSchema.js';
import type {TypeDeclarationMap} from '../utils.js';
import type {TypeDeclarationMap} from '../../utils';

// $FlowFixMe[unclear-type] there's no flowtype for ASTs
type PropAST = Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
} = require('./componentsUtils.js');

import type {StateTypeAnnotation, NamedShape} from '../../../CodegenSchema.js';
import type {TypeDeclarationMap} from '../utils.js';
import type {TypeDeclarationMap} from '../../utils';

// $FlowFixMe[unclear-type] there's no flowtype for ASTs
type PropAST = Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import type {
Nullable,
} from '../../../CodegenSchema.js';

import type {TypeDeclarationMap} from '../utils.js';
import type {ParserErrorCapturer} from '../../utils';
import type {ParserErrorCapturer, TypeDeclarationMap} from '../../utils';
import type {NativeModuleTypeAnnotation} from '../../../CodegenSchema.js';

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import type {TypeDeclarationMap} from './utils.js';
import type {TypeDeclarationMap} from '../utils';

export type LegalDefaultValues = string | number | boolean | null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@

'use strict';

import type {TypeAliasResolutionStatus} from '../utils';
import type {TypeAliasResolutionStatus, TypeDeclarationMap} from '../utils';

const {parseTopLevelType} = require('./parseTopLevelType');

/**
* TODO(T108222691): Use flow-types for @babel/parser
*/
export type TypeDeclarationMap = {[declarationName: string]: $FlowFixMe};

function getTypes(ast: $FlowFixMe): TypeDeclarationMap {
return ast.body.reduce((types, node) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-codegen/src/parsers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const {ParserError} = require('./errors');

const path = require('path');

export type TypeDeclarationMap = {[declarationName: string]: $FlowFixMe};

export type TypeAliasResolutionStatus =
| $ReadOnly<{
successful: true,
Expand Down

0 comments on commit 2934399

Please sign in to comment.