Skip to content

Commit

Permalink
Add LTI annotations to function params in xplat/js [2/2]
Browse files Browse the repository at this point in the history
Summary: Add annotations to function parameters required for Flow's Local Type Inference project. This codemod prepares the codebase to match Flow's new typechecking algorithm. The new algorithm will make Flow more reliable and predicatable.

Reviewed By: evanyeung

Differential Revision: D37360113

fbshipit-source-id: 870bcfe680542b3861fefbaf372db0ae8b32cbf3
  • Loading branch information
pieterv authored and facebook-github-bot committed Jun 23, 2022
1 parent 777a92d commit d96744e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Libraries/Image/AssetSourceResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const {
/**
* Returns a path like 'assets/AwesomeModule/[email protected]'
*/
function getScaledAssetPath(asset): string {
function getScaledAssetPath(asset: PackagerAsset): string {
const scale = pickScale(asset.scales, PixelRatio.get());
const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';
const assetDir = getBasePath(asset);
Expand All @@ -45,7 +45,7 @@ function getScaledAssetPath(asset): string {
/**
* Returns a path like 'drawable-mdpi/icon.png'
*/
function getAssetPathInDrawableFolder(asset): string {
function getAssetPathInDrawableFolder(asset: PackagerAsset): string {
const scale = pickScale(asset.scales, PixelRatio.get());
const drawbleFolder = getAndroidResourceFolderName(asset, scale);
const fileName = getAndroidResourceIdentifier(asset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
*/

'use strict';
import type {
PropTypeAnnotation,
EventTypeShape,
ComponentShape,
} from '../../CodegenSchema';

const j = require('jscodeshift');

Expand Down Expand Up @@ -46,7 +51,7 @@ ${componentConfig}
// this multiple times.
const UIMANAGER_IMPORT = 'const {UIManager} = require("react-native")';

function getReactDiffProcessValue(typeAnnotation) {
function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) {
switch (typeAnnotation.type) {
case 'BooleanTypeAnnotation':
case 'StringTypeAnnotation':
Expand Down Expand Up @@ -151,7 +156,7 @@ if (UIManager.hasViewManagerConfig('${componentName}')) {
`.trim();

// Replicates the behavior of RCTNormalizeInputEventName in RCTEventDispatcher.m
function normalizeInputEventName(name) {
function normalizeInputEventName(name: string) {
if (name.startsWith('on')) {
return name.replace(/^on/, 'top');
} else if (!name.startsWith('top')) {
Expand All @@ -162,7 +167,10 @@ function normalizeInputEventName(name) {
}

// Replicates the behavior of viewConfig in RCTComponentData.m
function getValidAttributesForEvents(events, imports) {
function getValidAttributesForEvents(
events: $ReadOnlyArray<EventTypeShape>,
imports: Set<string>,
) {
imports.add(
"const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore');",
);
Expand All @@ -178,7 +186,10 @@ function getValidAttributesForEvents(events, imports) {
]);
}

function generateBubblingEventInfo(event, nameOveride) {
function generateBubblingEventInfo(
event: EventTypeShape,
nameOveride: void | string,
) {
return j.property(
'init',
j.identifier(nameOveride || normalizeInputEventName(event.name)),
Expand All @@ -199,7 +210,10 @@ function generateBubblingEventInfo(event, nameOveride) {
);
}

function generateDirectEventInfo(event, nameOveride) {
function generateDirectEventInfo(
event: EventTypeShape,
nameOveride: void | string,
) {
return j.property(
'init',
j.identifier(nameOveride || normalizeInputEventName(event.name)),
Expand All @@ -216,8 +230,8 @@ function generateDirectEventInfo(event, nameOveride) {
function buildViewConfig(
schema: SchemaType,
componentName: string,
component,
imports,
component: ComponentShape,
imports: Set<string>,
) {
const componentProps = component.props;
const componentEvents = component.events;
Expand Down Expand Up @@ -326,8 +340,8 @@ function buildViewConfig(
function buildCommands(
schema: SchemaType,
componentName: string,
component,
imports,
component: ComponentShape,
imports: Set<string>,
) {
const commands = component.commands;

Expand Down

0 comments on commit d96744e

Please sign in to comment.