You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[JS] Rework how we handle static field on class #4419
Great proposal! I had a look at the existing infrastructure — it's closer to ready than it might seem.
Existing building blocks
ClassProperty with isStatic: bool already exists in the Babel AST (src/Fable.Transforms/Global/Babel.fs), and ClassMember.classProperty is already used for TypeScript class property declarations (e.g. for [(DefaultValue)] fields in declareDefaultValueStaticFieldInits). So the AST and printer already support native static class fields.
Where the IIFE currently comes from
static let bindings in F# are compiled by FCS into a class static constructor (.cctor). Fable emits the .cctor body as an ActionDeclaration immediately after the class declaration, which then becomes an IIFE in the JS output. The class body itself doesn't see the static initializer at all — it arrives as a separate top-level declaration.
Key technical consideration
Native static field = value runs when the class expression is evaluated (i.e. when the module is first imported), not after the full module has been initialised. For simple literal values (static let count = 42) this is always safe. For initializers that reference other module-level bindings (static let items = ResizeArray(), static let logger = createLogger()) it may also be safe, but for ones that refer to values declared after the class in the source, the IIFE pattern provides a guarantee the native field initializer does not.
Suggested implementation path
In FSharp2Fable.fs, identify when a .cctor action contains only simple assignments to one class's static fields (i.e. no cross-class or cross-module dependencies).
Tag those ActionDeclarations (or the corresponding MemberDecls) so Fable2Babel.fs can recognise them.
In Fable2Babel.fs, instead of emitting those as an IIFE after the class, fold them into the class body as ClassMember.classProperty with isStatic = true.
For initializers that can't be safely inlined (complex expressions with potential order-of-init dependencies), keep the IIFE as a fallback.
A simpler first cut could handle only the [(DefaultValue)] path (which declareDefaultValueStaticFieldInits already handles) and the literal-initializer .cctor case.
Note
🔒 Integrity filtering filtered 58 items
Integrity filtering activated and filtered the following items during workflow execution.
This happens when a tool call accesses a resource that does not meet the required integrity or secrecy level of the workflow.
#4454 (list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
#4393 (list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
#4220 (list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
#4166 (list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
#4143 (list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
#4104 (list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
#4044 (list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
#4038 (list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
#3290 (list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
#2279 (list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
#2154 (list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
issue:[Feature] Array2D operations #1764 (list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
issue:DateTime.ParseExact breaks REPL #2003 (list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
Activity
github-actions commentedon Mar 28, 2026
🤖 This is an automated response from Repo Assist.
Great proposal! I had a look at the existing infrastructure — it's closer to ready than it might seem.
Existing building blocks
ClassPropertywithisStatic: boolalready exists in the Babel AST (src/Fable.Transforms/Global/Babel.fs), andClassMember.classPropertyis already used for TypeScript class property declarations (e.g. for[(DefaultValue)]fields indeclareDefaultValueStaticFieldInits). So the AST and printer already support native static class fields.Where the IIFE currently comes from
static letbindings in F# are compiled by FCS into a class static constructor (.cctor). Fable emits the.cctorbody as anActionDeclarationimmediately after the class declaration, which then becomes an IIFE in the JS output. The class body itself doesn't see the static initializer at all — it arrives as a separate top-level declaration.Key technical consideration
Native
static field = valueruns when the class expression is evaluated (i.e. when the module is first imported), not after the full module has been initialised. For simple literal values (static let count = 42) this is always safe. For initializers that reference other module-level bindings (static let items = ResizeArray(),static let logger = createLogger()) it may also be safe, but for ones that refer to values declared after the class in the source, the IIFE pattern provides a guarantee the native field initializer does not.Suggested implementation path
FSharp2Fable.fs, identify when a.cctoraction contains only simple assignments to one class's static fields (i.e. no cross-class or cross-module dependencies).ActionDeclarations (or the correspondingMemberDecls) soFable2Babel.fscan recognise them.Fable2Babel.fs, instead of emitting those as an IIFE after the class, fold them into the class body asClassMember.classPropertywithisStatic = true.A simpler first cut could handle only the
[(DefaultValue)]path (whichdeclareDefaultValueStaticFieldInitsalready handles) and the literal-initializer.cctorcase.Note
🔒 Integrity filtering filtered 58 items
Integrity filtering activated and filtered the following items during workflow execution.
This happens when a tool call accesses a resource that does not meet the required integrity or secrecy level of the workflow.
list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)