Fable 1.2.4 broke importMember function

Created on 16 Oct 2017  Â·  9Comments  Â·  Source: fable-compiler/Fable

Description

I updated my VSCode extension sample to Fable 1.2.4 from 1.2.3 and this broke the importMember function. If I change my code to use the import function or the Import-Attribute it works.

Repro code

Clone the repository from above and checkout the fable-broken-import-member branch. Then follow the instructions from the readme.

Expected and actual results

This is what I get:

./src/wordcount.fsproj → ./out/extension.js...
fable: Compiled src\wordcount.fsproj
[!] (fable plugin) Error: D:/projects/experiments/fable/vscode-rollup-sample/src/extension.fs(1,1): error FABLE: `importMember` must be assigned to a variable
 Make sure Fable server is running on port 61225
src\extension.fs
Error: D:/projects/experiments/fable/vscode-rollup-sample/src/extension.fs(1,1): error FABLE: `importMember` must be assigned to a variable
 Make sure Fable server is running on port 61225
    at error (D:\projects\experiments\fable\vscode-rollup-sample\node_modules\rollup\dist\rollup.js:185:14)
    at Promise.resolve.then.catch.err (D:\projects\experiments\fable\vscode-rollup-sample\node_modules\rollup\dist\rollup.js:9182:6)

Related information

  • Fable version (dotnet fable --version): 1.2.4
  • Operating system: Windows 7 x64

All 9 comments

I just tried to import a string with importMember, and it worked. Looks like importing (curried?) functions is broken.

Looks like importing (curried?) functions is broken.

Doing this change makes it work again:

diff --git a/src/extension.fs b/src/extension.fs
index d532c07..eff85ce 100644
--- a/src/extension.fs
+++ b/src/extension.fs
@@ -8,7 +8,7 @@ open Fable.Import.vscode
 [<Emit("$0.match(/\w+/g)")>]
 let wordsIn (str : string) : obj = jsNative

-let formatCount : int -> string = importMember "./formatter"
+let formatCount : System.Func<int, string> = importMember "./formatter"

 let activate (context : ExtensionContext) =
   let sb = window.createStatusBarItem StatusBarAlignment.Left
@@ -23,7 +23,7 @@ open Fable.Import.vscode
     | Some e ->
       let d = e.document
       if d.languageId = "markdown" then
-        sb.text <- d |> wordCount |> formatCount
+        sb.text <- d |> wordCount |> formatCount.Invoke
         sb.show ()
       else
         sb.hide ()

@inosik What about the following? (havn't testsed it tho)

let formatCount (n: int) : string = importMember "./formatter"

I thought this should work, then you wouldn't have to call .Invoke on the application

@Zaid-Ajaj Yes, that works as well. But I'd still consider this a regression, because that caused existing code to break.

Though it's true that let formatCount (n: int) : string = importMember "./formatter" is the preferred way now as @Zaid-Ajaj points out, it's also true this is indeed a regression. Thanks for pointing out that it happened after updating to 1.2.4 @inosik, this probably means this commit or this one are the culprits, I'll check :+1: Actually I hit something like that in one of my projects though, weird enough, I wasn't using 1.2.4.

I don't remember why I did int -> string in the first place :smile: And I agree that giving names to the arguments is probably more user-friendly, at least in this case.

Sorry @inosik, can you please check if this is fixed with Fable 1.3?

No, unfortunately it's still the same with 1.3.0.

The transformation which happens in this else block is missing in the then block above. I think I fixed it, let me wrap it up cleanly and create a PR.

See #1239.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexfoxgill picture alexfoxgill  Â·  39Comments

alfonsogarciacaro picture alfonsogarciacaro  Â·  35Comments

tomcl picture tomcl  Â·  26Comments

sandeepc24 picture sandeepc24  Â·  46Comments

chrisvanderpennen picture chrisvanderpennen  Â·  31Comments