Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fable-compiler-js that consumes and produces raw content #3967

Closed
PawelStadnicki opened this issue Dec 2, 2024 · 1 comment
Closed

fable-compiler-js that consumes and produces raw content #3967

PawelStadnicki opened this issue Dec 2, 2024 · 1 comment

Comments

@PawelStadnicki
Copy link

PawelStadnicki commented Dec 2, 2024

Today I noticed that fable-compile-js was refreshed several months ago.
That is amazing, thank you!

I wonder if something as below could be possible (without too much work):

  • call run directly from proprietary js code
    let run opts projectFileName outDir =

    I can see it is exported in app.js so I believe this one can be ☑
    export function run(opts, projectFileName, outDir) {
  • extend the function to accept a raw fs code (string), write that content as a dedicated file, add it at the end of *.fsproj, so it will become some sort of Main.fs,
  • execute fable against the *.fsproj and return transpiled js content so it can be further used in JS eval()

As a context, I would like to play with F# in a place where currently squint (a light-weight version of ClojureScript) is used:

import { compileString } from 'squint-cljs';

const f = eval(compileString("(fn [] 1)"
                             , {"context": "expr",
                                "elide-imports": true}
                            ));

console.log(f()); // prints 1

Having this example, let's say I'm talking about this compileString Fable equivalent.
I'm asking if you see any obstacles or burdens to achieve it.
I can proceed then on my own with PR

@PawelStadnicki PawelStadnicki changed the title fable-compiler-js that consumes (fs) and produces (js) the raw string content fable-compiler-js that consumes and produces raw content Dec 2, 2024
@MangelMaxime
Copy link
Member

I think what you want is to use @fable-org/fable-standalone which is the actual project which host and expose the compiler API.

This is what fable-compiler-js and Fable REPL use, for compiling F# code in different environnement. It will allows you to decide how you want the project file to be resolved, should there be additional API available, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants