Fable: print AST

Created on 8 Apr 2018  路  4Comments  路  Source: fable-compiler/Fable

This is a question rather than an actual problem.
I'm currently working on a presentation about Fable and I'd like to show the intermediate steps of how Fable compiles the F# to JS.

I took an easy example

let add a b = a + b

And now I want to show how the Fable AST looks like.
To compare with the Babel AST later on.

I'm also showing in a slide how the FCS AST looks like to illustrate the differences.

[Let
 (false,
  [Binding
     (None,NormalBinding,false,false,[],
      PreXmlDoc
        (Microsoft.FSharp.Compiler.Range+pos,
         Microsoft.FSharp.Compiler.Ast+XmlDocCollector),
      SynValData
        (None,
         SynValInfo
           ([[SynArgInfo ([],false,Some a)];
             [SynArgInfo ([],false,Some b)]],
            SynArgInfo ([],false,None)),None),
      LongIdent
        (LongIdentWithDots ([add],[]),None,None,
         Pats
           [Named
              (Wild Program.fs (2,8--2,9) IsSynthetic=false,a,false,
               None,Program.fs (2,8--2,9) IsSynthetic=false);
            Named
              (Wild Program.fs (2,10--2,11) IsSynthetic=false,b,
               false,None,Program.fs (2,10--2,11) IsSynthetic=false)],
         None,Program.fs (2,4--2,11) IsSynthetic=false),None,

What functions do I use to print the AST?

Most helpful comment

Thanks, changed some code in the rollup-loader and got the babel ast.

All 4 comments

We had some rough Fable AST printers but I commented them out because they were causing problems. We could try uncommenting it and see if it works with the quicktest, by uncommenting also this line.

Thanks Alfonso, I was able to print the Fable AST with those changes.

Entity
  (QuickTest,
   [MemberOrFunctionOrValue
      (val add,[[val a]; [val b]],
       Call
  (None,val op_Addition,[],
   [type Microsoft.FSharp.Core.int; type Microsoft.FSharp.Core.int;
    type Microsoft.FSharp.Core.int],[Value val a; Value val b]))])

As for the Babel AST, I'm guessing I want to print something in Fable2Babel?
I'm expecting the Babel AST is just some json right?

Ah, great! Sometimes printing the type name gave me some issues but hopefully is fixed now. In the next version I will uncomment those lines (you still have to opt-in the AST printer, so it shouldn't affect anybody else). About the Babel AST, it is converted to JSON before sending it to the JS client yest. Whenever I had to check, I either print it in the JS client (fable-splitter, fable-loader) or right before sending the json over the TCP channel.

Thanks, changed some code in the rollup-loader and got the babel ast.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

forki picture forki  路  3Comments

et1975 picture et1975  路  3Comments

et1975 picture et1975  路  3Comments

nozzlegear picture nozzlegear  路  3Comments

alfonsogarciacaro picture alfonsogarciacaro  路  3Comments