@samitouri / QOS-React / commits / 37c6ea849c

[compiler] Typedefs for Array.prototype.flatMap

ghstack-source-id: af4c7ac2fd26f6ff332a1af0055c80b70838efee Pull Request resolved: https://github.com/facebook/react/pull/30794

Joe Savona committed Aug 22, 2024 at 16:51 UTC 37c6ea849c1445deb8d6704487b6295f7970a470
1 file changed +28
compiler/packages/babel-plugin-react-compiler/src/HIR/ObjectShape.ts
+28
@@ -317,6 +317,23 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [
317 mutableOnlyIfOperandsAreMutable: true,
318 }),
319 ],
320 + [
321 + 'flatMap',
322 + addFunction(BUILTIN_SHAPES, [], {
323 + positionalParams: [],
324 + restParam: Effect.ConditionallyMutate,
325 + returnType: {kind: 'Object', shapeId: BuiltInArrayId},
326 + /*
327 + * callee is ConditionallyMutate because items of the array
328 + * flow into the lambda and may be mutated there, even though
329 + * the array object itself is not modified
330 + */
331 + calleeEffect: Effect.ConditionallyMutate,
332 + returnValueKind: ValueKind.Mutable,
333 + noAlias: true,
334 + mutableOnlyIfOperandsAreMutable: true,
335 + }),
336 + ],
337 [
338 'filter',
339 addFunction(BUILTIN_SHAPES, [], {
@@ -534,6 +551,17 @@ addObject(BUILTIN_SHAPES, BuiltInMixedReadonlyId, [
551 noAlias: true,
552 }),
553 ],
554 + [
555 + 'flatMap',
556 + addFunction(BUILTIN_SHAPES, [], {
557 + positionalParams: [],
558 + restParam: Effect.Read,
559 + returnType: {kind: 'Object', shapeId: BuiltInArrayId},
560 + calleeEffect: Effect.ConditionallyMutate,
561 + returnValueKind: ValueKind.Mutable,
562 + noAlias: true,
563 + }),
564 + ],
565 [
566 'filter',
567 addFunction(BUILTIN_SHAPES, [], {