File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -242,9 +242,19 @@ let canInlineArg (com: Compiler) identName value body =
242242 | _ ->
243243 let refCount = countReferencesUntil 2 identName body
244244
245+ // Inlining a plain identifier reference is always safe (it's just a rename),
246+ // regardless of whether the ident is captured in a closure.
247+ let isIdentValue =
248+ match value with
249+ | IdentExpr _ -> true
250+ | _ -> false
251+
245252 // Don't inline even side-effect-free values when they're captured in a closure (e.g. object expression
246253 // getter): inlining would create a new value on each closure invocation instead of sharing one instance.
247- ( refCount <= 1 && not ( canHaveSideEffects com value) && not ( isIdentCaptured identName body))
254+ // Exception: plain ident values are always safe to inline (they don't create new objects).
255+ ( refCount <= 1
256+ && not ( canHaveSideEffects com value)
257+ && ( isIdentValue || not ( isIdentCaptured identName body)))
248258 // If it can have side effects, make sure is at least referenced once so the expression is not erased
249259 || ( refCount = 1
250260 && noSideEffectBeforeIdent identName body
You can’t perform that action at this time.
0 commit comments