babel-plugin-react-compiler 0.0.0-experimental-7f3c872-20250318 → 0.0.0-experimental-afa1d5a-20250319

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +110 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -139766,7 +139766,8 @@ function collectHoistablePropertyLoads(fn, temporaries, hoistableFromOptionals)
139766
139766
  knownImmutableIdentifiers,
139767
139767
  hoistableFromOptionals,
139768
139768
  registry,
139769
- nestedFnImmutableContext: null
139769
+ nestedFnImmutableContext: null,
139770
+ assumedInvokedFns: fn.env.config.enableTreatFunctionDepsAsConditional ? /* @__PURE__ */ new Set() : getAssumedInvokedFunctions(fn)
139770
139771
  });
139771
139772
  }
139772
139773
  function collectHoistablePropertyLoadsImpl(fn, context) {
@@ -139904,23 +139905,25 @@ function collectNonNullsInBlocks(fn, context) {
139904
139905
  if (maybeNonNull != null && isImmutableAtInstr(maybeNonNull.fullPath.identifier, instr.id, context)) {
139905
139906
  assumedNonNullObjects.add(maybeNonNull);
139906
139907
  }
139907
- if ((instr.value.kind === "FunctionExpression" || instr.value.kind === "ObjectMethod") && !fn.env.config.enableTreatFunctionDepsAsConditional) {
139908
+ if (instr.value.kind === "FunctionExpression") {
139908
139909
  const innerFn = instr.value.loweredFunc;
139909
- const innerHoistableMap = collectHoistablePropertyLoadsImpl(
139910
- innerFn.func,
139911
- __spreadProps(__spreadValues({}, context), {
139912
- nestedFnImmutableContext: (_a = context.nestedFnImmutableContext) != null ? _a : new Set(
139913
- innerFn.func.context.filter(
139914
- (place) => isImmutableAtInstr(place.identifier, instr.id, context)
139915
- ).map((place) => place.identifier.id)
139916
- )
139917
- })
139918
- );
139919
- const innerHoistables = assertNonNull(
139920
- innerHoistableMap.get(innerFn.func.body.entry)
139921
- );
139922
- for (const entry of innerHoistables.assumedNonNullObjects) {
139923
- assumedNonNullObjects.add(entry);
139910
+ if (context.assumedInvokedFns.has(innerFn)) {
139911
+ const innerHoistableMap = collectHoistablePropertyLoadsImpl(
139912
+ innerFn.func,
139913
+ __spreadProps(__spreadValues({}, context), {
139914
+ nestedFnImmutableContext: (_a = context.nestedFnImmutableContext) != null ? _a : new Set(
139915
+ innerFn.func.context.filter(
139916
+ (place) => isImmutableAtInstr(place.identifier, instr.id, context)
139917
+ ).map((place) => place.identifier.id)
139918
+ )
139919
+ })
139920
+ );
139921
+ const innerHoistables = assertNonNull(
139922
+ innerHoistableMap.get(innerFn.func.body.entry)
139923
+ );
139924
+ for (const entry of innerHoistables.assumedNonNullObjects) {
139925
+ assumedNonNullObjects.add(entry);
139926
+ }
139924
139927
  }
139925
139928
  }
139926
139929
  }
@@ -140048,6 +140051,96 @@ function reduceMaybeOptionalChains(nodes, registry) {
140048
140051
  }
140049
140052
  } while (changed);
140050
140053
  }
140054
+ function getAssumedInvokedFunctions(fn, temporaries = /* @__PURE__ */ new Map()) {
140055
+ var _a;
140056
+ const hoistableFunctions = /* @__PURE__ */ new Set();
140057
+ for (const block of fn.body.blocks.values()) {
140058
+ for (const { lvalue, value } of block.instructions) {
140059
+ if (value.kind === "FunctionExpression") {
140060
+ temporaries.set(lvalue.identifier.id, {
140061
+ fn: value.loweredFunc,
140062
+ mayInvoke: /* @__PURE__ */ new Set()
140063
+ });
140064
+ } else if (value.kind === "StoreLocal") {
140065
+ const lvalue2 = value.lvalue.place.identifier;
140066
+ const maybeLoweredFunc = temporaries.get(value.value.identifier.id);
140067
+ if (maybeLoweredFunc != null) {
140068
+ temporaries.set(lvalue2.id, maybeLoweredFunc);
140069
+ }
140070
+ } else if (value.kind === "LoadLocal") {
140071
+ const maybeLoweredFunc = temporaries.get(value.place.identifier.id);
140072
+ if (maybeLoweredFunc != null) {
140073
+ temporaries.set(lvalue.identifier.id, maybeLoweredFunc);
140074
+ }
140075
+ }
140076
+ }
140077
+ }
140078
+ for (const block of fn.body.blocks.values()) {
140079
+ for (const { lvalue, value } of block.instructions) {
140080
+ if (value.kind === "CallExpression") {
140081
+ const callee = value.callee;
140082
+ const maybeHook = getHookKind(fn.env, callee.identifier);
140083
+ const maybeLoweredFunc = temporaries.get(callee.identifier.id);
140084
+ if (maybeLoweredFunc != null) {
140085
+ hoistableFunctions.add(maybeLoweredFunc.fn);
140086
+ } else if (maybeHook != null) {
140087
+ for (const arg of value.args) {
140088
+ if (arg.kind === "Identifier") {
140089
+ const maybeLoweredFunc2 = temporaries.get(arg.identifier.id);
140090
+ if (maybeLoweredFunc2 != null) {
140091
+ hoistableFunctions.add(maybeLoweredFunc2.fn);
140092
+ }
140093
+ }
140094
+ }
140095
+ }
140096
+ } else if (value.kind === "JsxExpression") {
140097
+ for (const attr of value.props) {
140098
+ if (attr.kind === "JsxSpreadAttribute") {
140099
+ continue;
140100
+ }
140101
+ const maybeLoweredFunc = temporaries.get(attr.place.identifier.id);
140102
+ if (maybeLoweredFunc != null) {
140103
+ hoistableFunctions.add(maybeLoweredFunc.fn);
140104
+ }
140105
+ }
140106
+ for (const child of (_a = value.children) != null ? _a : []) {
140107
+ const maybeLoweredFunc = temporaries.get(child.identifier.id);
140108
+ if (maybeLoweredFunc != null) {
140109
+ hoistableFunctions.add(maybeLoweredFunc.fn);
140110
+ }
140111
+ }
140112
+ } else if (value.kind === "FunctionExpression") {
140113
+ const loweredFunc = value.loweredFunc.func;
140114
+ const lambdasCalled = getAssumedInvokedFunctions(
140115
+ loweredFunc,
140116
+ temporaries
140117
+ );
140118
+ const maybeLoweredFunc = temporaries.get(lvalue.identifier.id);
140119
+ if (maybeLoweredFunc != null) {
140120
+ for (const called of lambdasCalled) {
140121
+ maybeLoweredFunc.mayInvoke.add(called);
140122
+ }
140123
+ }
140124
+ }
140125
+ }
140126
+ if (block.terminal.kind === "return") {
140127
+ const maybeLoweredFunc = temporaries.get(
140128
+ block.terminal.value.identifier.id
140129
+ );
140130
+ if (maybeLoweredFunc != null) {
140131
+ hoistableFunctions.add(maybeLoweredFunc.fn);
140132
+ }
140133
+ }
140134
+ }
140135
+ for (const [_, { fn: fn2, mayInvoke }] of temporaries) {
140136
+ if (hoistableFunctions.has(fn2)) {
140137
+ for (const called of mayInvoke) {
140138
+ hoistableFunctions.add(called);
140139
+ }
140140
+ }
140141
+ }
140142
+ return hoistableFunctions;
140143
+ }
140051
140144
 
140052
140145
  // src/Utils/Stack.ts
140053
140146
  function empty() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-react-compiler",
3
- "version": "0.0.0-experimental-7f3c872-20250318",
3
+ "version": "0.0.0-experimental-afa1d5a-20250319",
4
4
  "description": "Babel plugin for React Compiler.",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",