From 99d76c206de26598eb454acf0d093f6191980d54 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Thu, 22 Aug 2024 16:51:56 -0700 Subject: [PATCH] [compiler] Typedefs for Array.prototype.flatMap [ghstack-poisoned] --- .../src/HIR/ObjectShape.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/ObjectShape.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/ObjectShape.ts index 9554878578ca0..04f85e496453a 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/ObjectShape.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/ObjectShape.ts @@ -317,6 +317,23 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [ mutableOnlyIfOperandsAreMutable: true, }), ], + [ + 'flatMap', + addFunction(BUILTIN_SHAPES, [], { + positionalParams: [], + restParam: Effect.ConditionallyMutate, + returnType: {kind: 'Object', shapeId: BuiltInArrayId}, + /* + * callee is ConditionallyMutate because items of the array + * flow into the lambda and may be mutated there, even though + * the array object itself is not modified + */ + calleeEffect: Effect.ConditionallyMutate, + returnValueKind: ValueKind.Mutable, + noAlias: true, + mutableOnlyIfOperandsAreMutable: true, + }), + ], [ 'filter', addFunction(BUILTIN_SHAPES, [], { @@ -534,6 +551,17 @@ addObject(BUILTIN_SHAPES, BuiltInMixedReadonlyId, [ noAlias: true, }), ], + [ + 'flatMap', + addFunction(BUILTIN_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: {kind: 'Object', shapeId: BuiltInArrayId}, + calleeEffect: Effect.ConditionallyMutate, + returnValueKind: ValueKind.Mutable, + noAlias: true, + }), + ], [ 'filter', addFunction(BUILTIN_SHAPES, [], {