Skip to content

Commit

Permalink
Enable LTI in xplat/js/tools
Browse files Browse the repository at this point in the history
Reviewed By: mvitousek

Differential Revision: D41773350

fbshipit-source-id: 1785fb753f01054a5c3f00c5eda9d5beae142b86
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Dec 6, 2022
1 parent 0d43ef9 commit 9c3e20f
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .flowconfig
Expand Up @@ -21,6 +21,8 @@ suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState
suppress_type=$FlowFixMeEmpty

inference_mode=experimental.lti

[lints]
sketchy-null-number=warn
sketchy-null-mixed=warn
Expand Down
10 changes: 5 additions & 5 deletions flow-typed/Promise.js
Expand Up @@ -15,23 +15,23 @@
// These annotations are copy/pasted from the built-in Flow definitions and
// tweaked so that then() and catch() accept `null` arguments, that they
// rightfully do. This should probably be changed in the core lib eventually.
declare class Promise<+R> {
declare class Promise<+R = mixed> {
constructor(
callback: (
resolve: (result?: Promise<R> | R) => void,
reject: (error?: any) => void,
) => mixed,
): void;

then<U>(
then<U = mixed>(
onFulfill?: ?(value: R) => Promise<U> | ?U,
onReject?: ?(error: any) => Promise<U> | ?U,
): Promise<U>;

catch<U>(onReject?: (error: any) => ?Promise<U> | U): Promise<U>;
catch<U = mixed>(onReject?: (error: any) => ?Promise<U> | U): Promise<U>;

static resolve<T>(object?: Promise<T> | T): Promise<T>;
static reject<T>(error?: mixed): Promise<T>;
static resolve<T = mixed>(object?: Promise<T> | T): Promise<T>;
static reject<T = mixed>(error?: mixed): Promise<T>;

static all<T: Iterable<mixed>>(
promises: T,
Expand Down
7 changes: 5 additions & 2 deletions flow-typed/jest.js
Expand Up @@ -11,7 +11,10 @@

// Copied from https://raw.githubusercontent.com/flow-typed/flow-typed/master/definitions/npm/jest_v26.x.x/flow_v0.134.x-/jest_v26.x.x.js

type JestMockFn<TArguments: $ReadOnlyArray<*>, TReturn> = {
type JestMockFn<
TArguments: $ReadOnlyArray<any> = $ReadOnlyArray<any>,
TReturn = any,
> = {
(...args: TArguments): TReturn,
/**
* An object for introspecting mock calls
Expand Down Expand Up @@ -834,7 +837,7 @@ type JestObjectType = {
* Returns a new, unused mock function. Optionally takes a mock
* implementation.
*/
fn<TArguments: $ReadOnlyArray<*>, TReturn>(
fn<TArguments: $ReadOnlyArray<any> = $ReadOnlyArray<any>, TReturn = any>(
implementation?: (...args: TArguments) => TReturn,
): JestMockFn<TArguments, TReturn>,
/**
Expand Down
Expand Up @@ -110,7 +110,11 @@ describe.each(Object.keys(WATCHERS))(

nextEvent = afterFn =>
Promise.all([
new Promise((resolve, reject) => {
new Promise<{
eventType: string,
metadata?: ChangeEventMetadata,
path: string,
}>((resolve, reject) => {
const listener = (
eventType: string,
path: string,
Expand Down Expand Up @@ -139,6 +143,7 @@ describe.each(Object.keys(WATCHERS))(
rejectUnexpected: false,
});

// $FlowFixMe[incompatible-use]
allEvents = (afterFn, expectedEvents, {rejectUnexpected = true} = {}) =>
Promise.all([
new Promise(async (resolve, reject) => {
Expand Down
1 change: 1 addition & 0 deletions packages/metro-source-map/src/Generator.js
Expand Up @@ -179,6 +179,7 @@ class Generator {
version: 3,
file,
sources: this.sources.slice(),
// $FlowFixMe[exponential-spread]
...content,
/* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.111 was deployed. To see the error, delete
Expand Down
2 changes: 1 addition & 1 deletion packages/metro-symbolicate/src/ChromeHeapSnapshot.js
Expand Up @@ -254,9 +254,9 @@ class ChromeHeapSnapshotRecordAccessor {
);
if (Array.isArray(recordTypes)) {
this._fieldToType = new Map<string, ChromeHeapSnapshotFieldType>(
// $FlowIssue[incompatible-call] Object.entries is incompletely typed
Object.entries(recordTypes).map(([offsetStr, type]) => [
recordFields[Number(offsetStr)],
// $FlowIssue[incompatible-call] Object.entries is incompletely typed
type,
]),
);
Expand Down
Expand Up @@ -522,6 +522,7 @@ function importExportPlugin({types: t}: {types: Types, ...}): PluginObj<State> {
state.exportAll.forEach(
(e: {file: string, loc: ?BabelSourceLocation, ...}) => {
body.push(
// $FlowFixMe[incompatible-call]
...withLocation(
exportAllTemplate({
FILE: resolvePath(
Expand Down
9 changes: 6 additions & 3 deletions packages/metro-transform-plugins/src/inline-plugin.js
Expand Up @@ -61,13 +61,16 @@ function inlinePlugin(
options.requireName || 'require',
);

const isGlobal = (binding: ?Binding): boolean %checks => !binding;
function isGlobal(binding: ?Binding): boolean %checks {
return !binding;
}

const isFlowDeclared = (binding: Binding) =>
t.isDeclareVariable(binding.path);

const isGlobalOrFlowDeclared = (binding: ?Binding): boolean %checks =>
isGlobal(binding) || isFlowDeclared(binding);
function isGlobalOrFlowDeclared(binding: ?Binding): boolean %checks {
return isGlobal(binding) || isFlowDeclared(binding);
}

const isLeftHandSideOfAssignmentExpression = (
node: Node,
Expand Down
Expand Up @@ -45,8 +45,8 @@ function normalizePseudoglobals(
}

const pseudoglobals: Array<string> = params
// $FlowFixMe Flow error uncovered by typing Babel more strictly
.map(path => path.node.name)
// $FlowFixMe[incompatible-call] Flow error uncovered by typing Babel more strictly
.filter(name => !reservedNames.has(name));

const usedShortNames = new Set<string>();
Expand Down
Expand Up @@ -116,7 +116,9 @@ function createInlinePlatformChecks(
isWrappedModule,
);

const isGlobal = (binding: void | $FlowFixMe): boolean %checks => !binding;
function isGlobal(binding: mixed): boolean %checks {
return !binding;
}

const isRequireCall = (
node: BabelNodeExpression,
Expand Down
5 changes: 4 additions & 1 deletion packages/metro/src/DeltaBundler/Transformer.js
Expand Up @@ -135,7 +135,10 @@ class Transformer {

// A valid result from the cache is used directly; otherwise we call into
// the transformer to computed the corresponding result.
const data = result
const data: $ReadOnly<{
result: TransformResult<>,
sha1: string,
}> = result
? {result, sha1}
: await this._workerFarm.transform(
localPath,
Expand Down
6 changes: 3 additions & 3 deletions packages/metro/src/HmrServer.js
Expand Up @@ -18,6 +18,7 @@ import type {
HmrMessage,
HmrUpdateMessage,
} from 'metro-runtime/src/modules/types.flow';
import type {UrlWithParsedQuery} from 'url';

const hmrJSBundle = require('./DeltaBundler/Serializers/hmrJSBundle');
const GraphNotFoundError = require('./IncrementalBundler/GraphNotFoundError');
Expand All @@ -34,8 +35,7 @@ const {
const nullthrows = require('nullthrows');
const url = require('url');

type $ReturnType<F> = $Call<<A, R>((...A) => R) => R, F>;
export type EntryPointURL = $ReturnType<typeof url.parse>;
export type EntryPointURL = UrlWithParsedQuery;

export type Client = {
optedIntoHMR: boolean,
Expand Down Expand Up @@ -145,7 +145,7 @@ class HmrServer<TClient: Client> {
const {graph, id} = await revPromise;
client.revisionIds.push(id);

let clientGroup = this._clientGroups.get(id);
let clientGroup: ?ClientGroup = this._clientGroups.get(id);
if (clientGroup != null) {
clientGroup.clients.add(client);
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/metro/src/lib/getAppendScripts.js
Expand Up @@ -37,7 +37,7 @@ function getAppendScripts<T: number | string>(
modules: $ReadOnlyArray<Module<>>,
options: Options<T>,
): $ReadOnlyArray<Module<>> {
const output = [];
const output: Array<Module<>> = [];

if (options.runModule) {
const paths = [...options.runBeforeMainModule, entryPoint];
Expand Down

0 comments on commit 9c3e20f

Please sign in to comment.