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

Add ts-prune #4772

Merged
merged 13 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/static-root-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
cache: 'yarn'
- name: Clear annotations
run: scripts/clear-annotations.sh

- name: Install node dependencies
run: yarn
- name: Check types
Expand All @@ -36,7 +35,9 @@ jobs:
run: yarn type:check-api
- name: Lint
run: yarn lint:js
- name: Finding circular dependencies
- name: Find unused code
run: yarn find-unused-code:js
- name: Find circular dependencies
run: yarn circular_dependency_check
- name: Jest test:unit
- name: Run jest unit tests
run: yarn test:unit
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"format:ios": "find ios/ -iname *.h -o -iname *.m -o -iname *.mm -o -iname *.cpp | xargs clang-format -i --Werror",
"format:android": "find android/src/ -iname *.h -o -iname *.cpp | xargs clang-format -i",
"format:common": "find Common/ -iname *.h -o -iname *.cpp | xargs clang-format -i",
"find-unused-code:js": "yarn ts-prune --ignore \"index\" --error ",
"type:check": "yarn tsc --noEmit && cd plugin && yarn type:check && cd ..",
"type:check-api": "yarn tsc --noEmit --target es6 --module ESNext --jsx react-native --skipLibCheck true --allowSyntheticDefaultImports true --moduleResolution node --esModuleInterop true --strict true --forceConsistentCasingInFileNames true --resolveJsonModule true app/src/App.tsx",
"prepare": "yarn plugin && bob build && husky install && yarn app",
Expand Down Expand Up @@ -147,6 +148,7 @@
"react-native-web": "~0.18.12",
"react-test-renderer": "17.0.2",
"shelljs": "^0.8.5",
"ts-prune": "^0.10.3",
"typescript": "^4.1.3"
},
"lint-staged": {
Expand Down
4 changes: 2 additions & 2 deletions src/createAnimatedComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ interface AnimatedProps extends Record<string, unknown> {
initial?: SharedValue<StyleProps>;
}

export type AnimatedComponentProps<P extends Record<string, unknown>> = P & {
type AnimatedComponentProps<P extends Record<string, unknown>> = P & {
forwardedRef?: Ref<Component>;
style?: NestedArray<StyleProps>;
animatedProps?: Partial<AnimatedComponentProps<AnimatedProps>>;
Expand Down Expand Up @@ -247,7 +247,7 @@ interface ComponentRef extends Component {
getAnimatableRef?: () => ComponentRef;
}

export interface InitialComponentProps extends Record<string, unknown> {
interface InitialComponentProps extends Record<string, unknown> {
ref?: Ref<Component>;
collapsable?: boolean;
}
Expand Down
4 changes: 2 additions & 2 deletions src/reanimated2/UpdateProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ViewRefSet } from './ViewDescriptorsSet';
import { runOnUIImmediately } from './threads';

// copied from react-native/Libraries/Components/View/ReactNativeStyleAttributes
export const colorProps = [
const colorProps = [
'backgroundColor',
'borderBottomColor',
'borderColor',
Expand All @@ -33,7 +33,7 @@ export const colorProps = [

export const ColorProperties = makeShareable(colorProps);

export let updateProps: (
let updateProps: (
viewDescriptor: SharedValue<Descriptor[]>,
updates: StyleProps | AnimatedStyle,
maybeViewRef: ViewRefSet<any> | undefined
Expand Down
1 change: 1 addition & 0 deletions src/reanimated2/__mocks__/NativeReanimated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const NOOP = () => {
// noop
};

// ts-prune-ignore-next
tjzel marked this conversation as resolved.
Show resolved Hide resolved
export default {
installCoreFunctions: NOOP,
makeShareable: (worklet) => worklet,
Expand Down
2 changes: 1 addition & 1 deletion src/reanimated2/animation/decay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface DecayAnimation extends Animation<DecayAnimation> {
current: AnimatableValue;
}

export interface InnerDecayAnimation
interface InnerDecayAnimation
extends Omit<DecayAnimation, 'current'>,
AnimationObject {
current: number;
Expand Down
4 changes: 2 additions & 2 deletions src/reanimated2/animation/styleAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { processColor } from '../Colors';

// resolves path to value for nested objects
// if path cannot be resolved returns undefined
export function resolvePath<T>(
function resolvePath<T>(
obj: NestedObject<T>,
path: AnimatableValue[] | AnimatableValue
): NestedObjectValues<T> | undefined {
Expand All @@ -39,7 +39,7 @@ export function resolvePath<T>(

// set value at given path
type Path = Array<string | number> | string | number;
export function setPath<T>(
function setPath<T>(
obj: NestedObject<T>,
path: Path,
value: NestedObjectValues<T>
Expand Down
2 changes: 1 addition & 1 deletion src/reanimated2/animation/timing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface TimingAnimation extends Animation<TimingAnimation> {
current: AnimatableValue;
}

export interface InnerTimingAnimation
interface InnerTimingAnimation
extends Omit<TimingAnimation, 'toValue' | 'current'> {
toValue: number;
current: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type AffineMatrix = FixedLengthArray<FixedLengthArray<number, 4>, 4>;

export type AffineMatrixFlat = FixedLengthArray<number, 16>;

export type TransformMatrixDecomposition = Record<
type TransformMatrixDecomposition = Record<
'translationMatrix' | 'scaleMatrix' | 'rotationMatrix' | 'skewMatrix',
AffineMatrix
>;
Expand Down
5 changes: 1 addition & 4 deletions src/reanimated2/animation/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {
toGammaSpace,
toLinearSpace,
} from '../Colors';

import type {
AnimatedStyle,
SharedValue,
AnimatableValue,
Animation,
Expand All @@ -37,8 +35,6 @@ import {

let IN_STYLE_UPDATER = false;

export type UserUpdater = () => AnimatedStyle;

export function initialUpdaterRun<T>(updater: () => T): T {
IN_STYLE_UPDATER = true;
const result = updater();
Expand Down Expand Up @@ -451,6 +447,7 @@ export function cancelAnimation<T>(sharedValue: SharedValue<T>): void {
}

// TODO it should work only if there was no animation before.
// ts-prune-ignore-next
export function withStartValue(
tjzel marked this conversation as resolved.
Show resolved Hide resolved
startValue: AnimatableValue,
animation: NextAnimation<AnimationObject>
Expand Down
2 changes: 1 addition & 1 deletion src/reanimated2/component/FlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ declare class ReanimatedFlatListClass<T> extends Component<
getNode(): FlatList;
}

export interface ReanimatedFlatListProps<ItemT> extends FlatListProps<ItemT> {
interface ReanimatedFlatListProps<ItemT> extends FlatListProps<ItemT> {
itemLayoutAnimation?: ILayoutAnimationBuilder;
}

Expand Down
1 change: 1 addition & 0 deletions src/reanimated2/fabricUtils.web.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ts-prune-ignore-next
tjzel marked this conversation as resolved.
Show resolved Hide resolved
export function getShadowNodeWrapperFromRef() {
throw new Error(
'[Reanimated] Trying to call `getShadowNodeWrapperFromRef` on web.'
Expand Down
2 changes: 0 additions & 2 deletions src/reanimated2/helperTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ export type AnimateProps<P extends object> = NonStyleAnimatedProps<P> &
animatedProps?: Partial<AnimatedPropsProp<P>>;
};

export type AnimatedProps<P extends object> = AnimateProps<P>;
tjzel marked this conversation as resolved.
Show resolved Hide resolved

export type AnimatedPropsAdapterFunction = (
props: Record<string, unknown>
) => void;
Expand Down
4 changes: 2 additions & 2 deletions src/reanimated2/hook/useAnimatedGestureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface GestureHandlers<T, TContext extends Context> {
onFinish?: Handler<T, TContext>;
}

export const EventType = {
const EventType = {
UNDETERMINED: 0,
FAILED: 1,
BEGAN: 2,
Expand All @@ -25,7 +25,7 @@ export const EventType = {
END: 5,
};

export interface GestureHandlerNativeEvent {
interface GestureHandlerNativeEvent {
handlerTag: number;
numberOfPointers: number;
state: (typeof EventType)[keyof typeof EventType];
Expand Down
1 change: 1 addition & 0 deletions src/reanimated2/hook/useReducedMotion.web.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ts-prune-ignore-next
tjzel marked this conversation as resolved.
Show resolved Hide resolved
export function useReducedMotion() {
return !window.matchMedia('(prefers-reduced-motion: no-preference)').matches;
}
32 changes: 3 additions & 29 deletions src/reanimated2/hook/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { MutableRefObject } from 'react';
import { useEffect, useRef } from 'react';
import { processColor } from '../Colors';
import type {
AnimatedStyle,
Context,
Expand All @@ -11,7 +10,6 @@ import type {
} from '../commonTypes';
import { makeRemote } from '../core';
import { isWeb, isJest } from '../PlatformChecker';
import { colorProps } from '../UpdateProps';
import WorkletEventHandler from '../WorkletEventHandler';
import type { ContextWithDependencies, DependencyList } from './commonTypes';
import type { NativeSyntheticEvent } from 'react-native';
Expand All @@ -23,7 +21,7 @@ interface Handlers<T, TContext extends Context> {
[key: string]: Handler<T, TContext> | undefined;
}

export interface UseHandlerContext<TContext extends Context> {
interface UseHandlerContext<TContext extends Context> {
context: TContext;
doDependenciesDiffer: boolean;
useWeb: boolean;
Expand Down Expand Up @@ -104,7 +102,7 @@ export function buildWorkletsHash(
}

// builds dependencies array for gesture handlers
export function buildDependencies(
function buildDependencies(
dependencies: DependencyList,
handlers: Record<string, WorkletFunction | undefined>
): Array<unknown> {
Expand All @@ -126,7 +124,7 @@ export function buildDependencies(
}

// this is supposed to work as useEffect comparison
export function areDependenciesEqual(
function areDependenciesEqual(
nextDeps: DependencyList,
prevDeps: DependencyList
): boolean {
Expand Down Expand Up @@ -156,30 +154,6 @@ export function areDependenciesEqual(
return areHookInputsEqual(nextDeps, prevDeps);
}

export function hasColorProps(updates: AnimatedStyle): boolean {
const colorPropsSet = new Set(colorProps);
for (const key in updates) {
if (colorPropsSet.has(key)) {
return true;
}
}
return false;
}

export function parseColors(updates: AnimatedStyle): void {
'worklet';
for (const key in updates) {
if (colorProps.indexOf(key) !== -1) {
// value could be an animation in which case processColor will recognize it and will return undefined
// -> in such a case we don't want to override style of that key
const processedColor = processColor(updates[key]);
if (processedColor !== undefined) {
updates[key] = processedColor;
}
}
}
}

export function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {
'worklet';
if (Array.isArray(prop)) {
Expand Down
1 change: 1 addition & 0 deletions src/reanimated2/jestUtils.web.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Stubbed for web, where we don't use this file;
*/
// ts-prune-ignore-next
tjzel marked this conversation as resolved.
Show resolved Hide resolved
export default {};
1 change: 1 addition & 0 deletions src/reanimated2/js-reanimated/MapperRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { JSReanimated } from './commonTypes';
import type Mapper from './Mapper';

// ts-prune-ignore-next
tjzel marked this conversation as resolved.
Show resolved Hide resolved
export default class MapperRegistry<T> {
sortedMappers: Mapper<T>[] = [];
mappers: Map<number, Mapper<T>> = new Map();
Expand Down
4 changes: 2 additions & 2 deletions src/reanimated2/js-reanimated/commonTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Timestamp, NestedObjectValues } from '../commonTypes';
import type MutableValue from './MutableValue';

export interface Mapper<T> {
interface Mapper<T> {
MAPPER_ID?: number;
id: number;
inputs: MutableValue<T>[];
Expand All @@ -14,7 +14,7 @@ export interface Mapper<T> {
): MutableValue<T>[];
}

export interface MapperRegistry<T> {
interface MapperRegistry<T> {
sortedMappers: Mapper<T>[];
mappers: Map<number, Mapper<T>>;
_module: JSReanimated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import type {
KeyframeProps,
} from './commonTypes';
import type { TransformProperty, StyleProps } from '../../commonTypes';
export interface KeyframePoint {
interface KeyframePoint {
duration: number;
value: number | string;
easing?: EasingFn;
}
export interface ParsedKeyframesDefinition {
interface ParsedKeyframesDefinition {
initialValues: StyleProps;
keyframes: Record<string, KeyframePoint[]>;
}
Expand Down
4 changes: 2 additions & 2 deletions src/reanimated2/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { isSharedValue } from './utils';

const IS_JEST = isJest();

export type Mapper = {
type Mapper = {
id: number;
dirty: boolean;
worklet: () => void;
inputs: SharedValue<any>[];
outputs?: SharedValue<any>[];
};

export function createMapperRegistry() {
function createMapperRegistry() {
'worklet';
const mappers = new Map();
let sortedMappers: Mapper[] = [];
Expand Down
1 change: 0 additions & 1 deletion src/reanimated2/mutables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from './shareables';
import { runOnUI } from './threads';
import { valueSetter } from './valueSetter';
export { stopMapper } from './mappers';

export function makeUIMutable<T>(
initial: T,
Expand Down
1 change: 1 addition & 0 deletions src/reanimated2/platform-specific/checkCppVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function checkCppVersion() {
}
}

// ts-prune-ignore-next
tjzel marked this conversation as resolved.
Show resolved Hide resolved
export function matchVersion(version1: string, version2: string) {
if (version1.match(/^\d+\.\d+\.\d+$/) && version2.match(/^\d+\.\d+\.\d+$/)) {
// x.y.z, compare only major and minor, skip patch
Expand Down
1 change: 1 addition & 0 deletions src/reanimated2/platform-specific/checkVersion.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
* Checks that native and js versions of reanimated match.
* Stubbed for web, where this check is unnecessary.
*/
// ts-prune-ignore-next
tjzel marked this conversation as resolved.
Show resolved Hide resolved
export function checkVersion(): void {}
1 change: 0 additions & 1 deletion src/reanimated2/valueSetter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { AnimationObject, AnimatableValue } from './commonTypes';
import type { Descriptor } from './hook/commonTypes';
export { stopMapper } from './mappers';

export function valueSetter(sv: any, value: any): void {
'worklet';
Expand Down
2 changes: 1 addition & 1 deletion src/setAndForwardRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type { MutableRefObject } from 'react';
* module.exports = MyViewWithRef;
*/

export type ForwardedRef<T> = () => MutableRefObject<T> | ((ref: T) => void);
type ForwardedRef<T> = () => MutableRefObject<T> | ((ref: T) => void);

function setAndForwardRef<T>({
getForwardedRef,
Expand Down
Loading