Fable icon indicating copy to clipboard operation
Fable copied to clipboard

[Fable 5] Source maps generation is broken

Open MangelMaxime opened this issue 1 year ago • 6 comments

Description

It seems like we are missing information about the original file file and the source., which cause Fable 5 to break if --sourceMaps is provided.

To me it looks like the last blocking bug we need to fix to release Fable 5. Other things like full support for F# 9 feature can be done over time.

./../quicktest/QuickTest.fs(1,1): error EXCEPTION: Invalid mapping: { generated = { line = 54
                column = 85 }
  name = None
  original = Some { line = 0
                    column = 0 }
  source = Some "unknown" }
   at SourceMapSharp.SourceMapGenerator.ValidateMapping(MappingIndex generated, FSharpOption`1 original, FSharpOption`1 source, FSharpOption`1 name)
   at SourceMapSharp.SourceMapGenerator.AddMapping(MappingIndex generated, FSharpOption`1 original, FSharpOption`1 source, FSharpOption`1 name)
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCallExpression(Printer printer, Expression callee, Expression[] args, TypeAnnotation[] typeArguments, FSharpOption`1 loc) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 1231
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintArrowFunctionExpression(Printer printer, Parameter[] parameters, BlockStatement body, FSharpOption`1 returnType, TypeParameter[] typeParameters, FSharpOption`1 loc) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 1041
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer-PrintCommaSeparatedArray@229-10.Invoke(Printer p, Expression x) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintArray[a](Printer printer, a[] items, FSharpFunc`2 print, FSharpFunc`2 printSeparator) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 135
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCommaSeparatedArray(Printer printer, Expression[] items) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCallExpression(Printer printer, Expression callee, Expression[] args, TypeAnnotation[] typeArguments, FSharpOption`1 loc) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 1235
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer-PrintCommaSeparatedArray@229-10.Invoke(Printer p, Expression x) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintArray[a](Printer printer, a[] items, FSharpFunc`2 print, FSharpFunc`2 printSeparator) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 135
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCommaSeparatedArray(Printer printer, Expression[] items) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCallExpression(Printer printer, Expression callee, Expression[] args, TypeAnnotation[] typeArguments, FSharpOption`1 loc) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 1235
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintArrowFunctionExpression(Printer printer, Parameter[] parameters, BlockStatement body, FSharpOption`1 returnType, TypeParameter[] typeParameters, FSharpOption`1 loc) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 1041
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer-PrintCommaSeparatedArray@229-10.Invoke(Printer p, Expression x) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintArray[a](Printer printer, a[] items, FSharpFunc`2 print, FSharpFunc`2 printSeparator) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 135
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCommaSeparatedArray(Printer printer, Expression[] items) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCallExpression(Printer printer, Expression callee, Expression[] args, TypeAnnotation[] typeArguments, FSharpOption`1 loc) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 1235
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer-PrintCommaSeparatedArray@229-10.Invoke(Printer p, Expression x) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintArray[a](Printer printer, a[] items, FSharpFunc`2 print, FSharpFunc`2 printSeparator) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 135
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCommaSeparatedArray(Printer printer, Expression[] items) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCallExpression(Printer printer, Expression callee, Expression[] args, TypeAnnotation[] typeArguments, FSharpOption`1 loc) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 1235
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintProductiveStatement(Printer printer, Statement s, FSharpOption`1 printSeparator) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 78
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer-PrintBlock@88.Invoke(Printer p, Statement s) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 88
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintBlock[a](Printer printer, a[] nodes, FSharpFunc`2 printNode, FSharpFunc`2 printSeparator, FSharpOption`1 skipNewLineAtEnd) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 61
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintArrowFunctionExpression(Printer printer, Parameter[] parameters, BlockStatement body, FSharpOption`1 returnType, TypeParameter[] typeParameters, FSharpOption`1 loc) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 1041
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer-PrintCommaSeparatedArray@229-10.Invoke(Printer p, Expression x) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintArray[a](Printer printer, a[] items, FSharpFunc`2 print, FSharpFunc`2 printSeparator) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 135
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCommaSeparatedArray(Printer printer, Expression[] items) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCallExpression(Printer printer, Expression callee, Expression[] args, TypeAnnotation[] typeArguments, FSharpOption`1 loc) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 1235
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintProductiveStatement(Printer printer, Statement s, FSharpOption`1 printSeparator) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 78
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer-PrintBlock@88.Invoke(Printer p, Statement s) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 88
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintBlock[a](Printer printer, a[] nodes, FSharpFunc`2 printNode, FSharpFunc`2 printSeparator, FSharpOption`1 skipNewLineAtEnd) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 61
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintDeclaration(Printer printer, Declaration decl) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 664
   at Fable.Transforms.BabelPrinter.printDeclWithExtraLine@1558-1.Invoke(Printer printer, ModuleDeclaration decl) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 1558
   at [email protected](ModuleDeclaration decl) in /Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/Fable.Transforms/BabelPrinter.fs:line 1585
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 510
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 112

Repro code

Add |> CmdLine.appendRaw "--sourceMaps" to src/Fable.Build/Quicktest/Core.fs and run ./build.sh quicktest javascript

Expected and actual results

Should compile

Related information

  • Fable version: 5.0.0-alpha.2
  • Operating system: OSX

MangelMaxime avatar Dec 17 '24 16:12 MangelMaxime

It looks like the issue happens when a CE exist in the code:

let testCaseAsync f =
    async {
        do! f ()
    }

or

let testCaseAsync f =
    promise {
        do! f ()
    }

both fails

MangelMaxime avatar Dec 17 '24 17:12 MangelMaxime

Comparing the calls to AddSourceMapping

https://github.com/fable-compiler/Fable/blob/935f05a00f77b1fe56c666acb44194d79126522c/src/Fable.Cli/Pipeline.fs#L152

It seems like the problem is from do! which don't return its information now:

Fable 4.24.0

srcLine: 9
srcCol: 4
genLine: 4
genCol: 11
file: Some
  "/Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/quicktest/QuickTest.fs"
displayName: None
                    

srcLine: 9
srcCol: 4
genLine: 4
genCol: 11
file: Some
  "/Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/quicktest/QuickTest.fs"
displayName: Some "``builder@``"

srcLine: 10
srcCol: 12
genLine: 4
genCol: 33
file: Some
  "/Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/quicktest/QuickTest.fs"
displayName: None

Fable 5

srcLine: 9
srcCol: 4
genLine: 4
genCol: 11
file: Some
  "/Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/quicktest/QuickTest.fs"
displayName: None
                    

srcLine: 9
srcCol: 4
genLine: 4
genCol: 11
file: Some
  "/Users/mmangel/Workspaces/Github/fable-compiler/Fable/src/quicktest/QuickTest.fs"
displayName: Some "``builder@``"
                    

srcLine: 0
srcCol: 0
genLine: 4
genCol: 33
file: Some "unknown"
displayName: None

See the last paragraph

MangelMaxime avatar Dec 17 '24 19:12 MangelMaxime

Looks like this issue also affects fable 4.26.0 (I know it's unlisted, and not expecting any support, but thought I'd mention this here in case it provides any insight). Getting similar errors after updating from 4.24.0 (can't test 4.25.0 because of #4176):

.\..\App.Logic\Views\LoggedOut\KitchenSink.fs(1,1): error EXCEPTION: Invalid mapping: { generated = { line = 10
                column = 33 }
  name = None
  original = Some { line = 0
                    column = 0 }
  source = Some "unknown" }
   at SourceMapSharp.SourceMapGenerator.ValidateMapping(MappingIndex generated, FSharpOption`1 original, FSharpOption`1 source, FSharpOption`1 name)
   at SourceMapSharp.SourceMapGenerator.AddMapping(MappingIndex generated, FSharpOption`1 original, FSharpOption`1 source, FSharpOption`1 name)
   at Fable.Transforms.Printer.PrinterImpl.addLoc(FSharpOption`1 loc) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/Printer.fs:line 42
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCallExpression(Printer printer, Expression callee, Expression[] args, TypeAnnotation[] typeArguments, FSharpOption`1 loc) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 1231
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.Print(Printer printer, Expression expr) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 552
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer-PrintCommaSeparatedArray@229-10.Invoke(Printer p, Expression x) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCommaSeparatedArray(Printer printer, Expression[] items) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 229
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintCallExpression(Printer printer, Expression callee, Expression[] args, TypeAnnotation[] typeArguments, FSharpOption`1 loc) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 1235
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.Print(Printer printer, Expression expr) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 507
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer-PrintBlock@88.Invoke(Printer p, Statement s) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 88
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintBlock[a](Printer printer, a[] nodes, FSharpFunc`2 printNode, FSharpFunc`2 printSeparator, FSharpOption`1 skipNewLineAtEnd) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 61
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintBlock(Printer printer, Statement[] nodes, FSharpOption`1 skipNewLineAtEnd) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 86
   at Fable.Transforms.BabelPrinter.PrinterExtensions.Printer.PrintDeclaration(Printer printer, Declaration decl) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 664
   at Fable.Transforms.BabelPrinter.printDeclWithExtraLine@1558-1.Invoke(Printer printer, ModuleDeclaration decl) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 1558
   at [email protected](ModuleDeclaration decl) in /home/mmangel/Workspaces/Github/fable-compiler/Fable/fable4/src/Fable.Transforms/BabelPrinter.fs:line 1585
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 510
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 112

Code in question:

let timerCmd dispatch =
    async {
        do! Async.Sleep(TimeSpan.FromSeconds(5.0))
        dispatch SetIsDone
    }

If you have any pointers on what might be causing this, I'd be happy to look into contributing a fix (for Fable 5).

OrfeasZ avatar Nov 12 '25 21:11 OrfeasZ

This is normal for 4.26.0 because we upgraded the FCS in it similarly to Fable 5.

It is unlisted and will not be fixed as people should not use that version of Fable.

MangelMaxime avatar Nov 13 '25 19:11 MangelMaxime

Yep, that's all good, and like I said I don't expect that to be fixed in 4.x, but would like to see if I can contribute a fix for 5.x. Since you mentioned FCS, is the issue that FCS no longer provides relevant information? Just asking so I know where to start.

OrfeasZ avatar Nov 13 '25 20:11 OrfeasZ

I don't know what is the cause of this issue unfortunately.

We don't have the error happening in Fable 5 anymore because I made a hot fix:

https://github.com/fable-compiler/Fable/blob/a9faaa03895169d62ff5d3032942e1a10ee746d1/src/Fable.Cli/Pipeline.fs#L164-L170

I think if we wanted to investigate we would need to disable that workaround, and try to compare the information from Fable 4 and Fable 5 to try narrowing down the source of issue.

MangelMaxime avatar Nov 13 '25 20:11 MangelMaxime