Skip to content

Commit

Permalink
Pre-suppress unsafe string key access errors in xplat/js
Browse files Browse the repository at this point in the history
Reviewed By: alexmckenley

Differential Revision: D56477899

fbshipit-source-id: 5676b8685bd3157a519fe433cfce0fa28e003502
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Apr 23, 2024
1 parent bfcbcdd commit b2cf404
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/react-relay/ReactRelayPaginationContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,9 @@ function createContainerWithFragments<
PAGE_INFO,
connectionData,
);
// $FlowFixMe[invalid-computed-prop]
const edges = connectionData[EDGES];
// $FlowFixMe[invalid-computed-prop]
const pageInfo = connectionData[PAGE_INFO];
if (edges == null || pageInfo == null) {
return null;
Expand Down
1 change: 1 addition & 0 deletions packages/react-relay/getRootVariablesForFragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function getRootVariablesForFragments<TProps: {...}>(
// should all point to the same owner
Object.keys(fragments).forEach(key => {
const fragmentNode = fragments[key];
// $FlowFixMe[invalid-computed-prop]
const fragmentRef = props[key];
const selector = getSelector(fragmentNode, fragmentRef);
const fragmentOwnerVariables =
Expand Down
1 change: 1 addition & 0 deletions packages/relay-runtime/store/RelayConcreteVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function getLocalVariables(
const nextVariables = {...currentVariables};
const nextArgs = args ? getArgumentValues(args, currentVariables) : {};
argumentDefinitions.forEach(def => {
// $FlowFixMe[invalid-computed-prop]
const value = nextArgs[def.name] ?? def.defaultValue;
nextVariables[def.name] = value;
});
Expand Down
1 change: 1 addition & 0 deletions packages/relay-runtime/store/RelayReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ class RelayReader {
// At this point, backingFieldData is an object with a single key (fieldName)
// whose value is the value returned from the resolver, or a suspense sentinel.

// $FlowFixMe[invalid-computed-prop]
const clientEdgeResolverResponse = backingFieldData[fieldName];
if (
clientEdgeResolverResponse == null ||
Expand Down
4 changes: 4 additions & 0 deletions packages/relay-runtime/store/__tests__/DataChecker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,11 @@ describe('check()', () => {

loader = {
get: jest.fn(
// $FlowFixMe[invalid-computed-prop]
(moduleName: mixed) => nodes[String(moduleName).replace(/\$.*/, '')],
),
load: jest.fn((moduleName: mixed) =>
// $FlowFixMe[invalid-computed-prop]
Promise.resolve(nodes[String(moduleName).replace(/\$.*/, '')]),
),
};
Expand Down Expand Up @@ -1169,9 +1171,11 @@ describe('check()', () => {

loader = {
get: jest.fn(
// $FlowFixMe[invalid-computed-prop]
(moduleName: mixed) => nodes[String(moduleName).replace(/\$.*/, '')],
),
load: jest.fn((moduleName: mixed) =>
// $FlowFixMe[invalid-computed-prop]
Promise.resolve(nodes[String(moduleName).replace(/\$.*/, '')]),
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function assertIsDeeplyFrozen(value: ?{...} | ?$ReadOnlyArray<{...}>): void {
value.forEach(item => assertIsDeeplyFrozen(item));
} else if (typeof value === 'object' && value !== null) {
for (const key in value) {
// $FlowFixMe[invalid-computed-prop]
assertIsDeeplyFrozen(value[key]);
}
}
Expand All @@ -63,6 +64,7 @@ function cloneEventWithSets(event: LogEvent) {
const nextEvent = {};
for (const key in event) {
if (event.hasOwnProperty(key)) {
// $FlowFixMe[invalid-computed-prop]
const val = event[key];
if (val instanceof Set) {
// $FlowFixMe[prop-missing]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function assertIsDeeplyFrozen(value: ?{...} | ?$ReadOnlyArray<{...}>): void {
value.forEach(item => assertIsDeeplyFrozen(item));
} else if (typeof value === 'object' && value !== null) {
for (const key in value) {
// $FlowFixMe[invalid-computed-prop]
assertIsDeeplyFrozen(value[key]);
}
}
Expand All @@ -73,6 +74,7 @@ function cloneEventWithSets(event: LogEvent) {
const nextEvent = {};
for (const key in event) {
if (event.hasOwnProperty(key)) {
// $FlowFixMe[invalid-computed-prop]
const val = event[key];
if (val instanceof Set) {
// $FlowFixMe[prop-missing]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,11 @@ describe('RelayReferenceMarker', () => {
`;
loader = {
get: jest.fn(
// $FlowFixMe[invalid-computed-prop]
(moduleName: mixed) => nodes[String(moduleName).replace(/\$.*/, '')],
),
load: jest.fn((moduleName: mixed) =>
// $FlowFixMe[invalid-computed-prop]
Promise.resolve(nodes[String(moduleName).replace(/\$.*/, '')]),
),
};
Expand Down Expand Up @@ -868,9 +870,11 @@ describe('RelayReferenceMarker', () => {
const references = new Set<DataID>();
const loader = {
get: jest.fn(
// $FlowFixMe[invalid-computed-prop]
(moduleName: mixed) => nodes[String(moduleName).replace(/\$.*/, '')],
),
load: jest.fn((moduleName: mixed) =>
// $FlowFixMe[invalid-computed-prop]
Promise.resolve(nodes[String(moduleName).replace(/\$.*/, '')]),
),
};
Expand Down Expand Up @@ -917,9 +921,11 @@ describe('RelayReferenceMarker', () => {
const references = new Set<DataID>();
const loader = {
get: jest.fn(
// $FlowFixMe[invalid-computed-prop]
(moduleName: mixed) => nodes[String(moduleName).replace(/\$.*/, '')],
),
load: jest.fn((moduleName: mixed) =>
// $FlowFixMe[invalid-computed-prop]
Promise.resolve(nodes[String(moduleName).replace(/\$.*/, '')]),
),
};
Expand Down Expand Up @@ -965,9 +971,11 @@ describe('RelayReferenceMarker', () => {
const references = new Set<DataID>();
const loader = {
get: jest.fn(
// $FlowFixMe[invalid-computed-prop]
(moduleName: mixed) => nodes[String(moduleName).replace(/\$.*/, '')],
),
load: jest.fn((moduleName: mixed) =>
// $FlowFixMe[invalid-computed-prop]
Promise.resolve(nodes[String(moduleName).replace(/\$.*/, '')]),
),
};
Expand Down Expand Up @@ -1057,9 +1065,11 @@ describe('RelayReferenceMarker', () => {
`;
loader = {
get: jest.fn(
// $FlowFixMe[invalid-computed-prop]
(moduleName: mixed) => nodes[String(moduleName).replace(/\$.*/, '')],
),
load: jest.fn((moduleName: mixed) =>
// $FlowFixMe[invalid-computed-prop]
Promise.resolve(nodes[String(moduleName).replace(/\$.*/, '')]),
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ function resolverDataInjector<TFragmentType: FragmentType, TData: ?{...}>(
if (fieldName in data) {
if (isRequiredField === true) {
invariant(
// $FlowFixMe[invalid-computed-prop]
data[fieldName] != null,
'Expected required resolver field `%s` in fragment `%s` to be non-null.',
fieldName,
fragment.name,
);
}

// $FlowFixMe[invalid-computed-prop]
return resolverFn(data[fieldName], args);
} else {
// If both `data` and `fieldName` is available, we expect the
Expand Down

0 comments on commit b2cf404

Please sign in to comment.