Skip to content

Commit

Permalink
Release 2.3.0-beta-001
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Apr 12, 2019
1 parent acfe5e1 commit c12678d
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 71 deletions.
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Fable.Cli/Fable.Cli.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Cli/Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Fable.Cli

module Literals =

let [<Literal>] VERSION = "2.2.3"
let [<Literal>] VERSION = "2.3.0-beta-001"
let [<Literal>] CORE_VERSION = "2.1.0"
let [<Literal>] DEFAULT_PORT = 61225
let [<Literal>] FORCE = "force:"
Expand Down
4 changes: 4 additions & 0 deletions src/Fable.Core/Fable.Core.JsInterop.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ let importSideEffects (path: string): unit = jsNative
/// Imports a file dynamically at runtime
let importDynamic<'T> (path: string): JS.Promise<'T> = jsNative

/// Imports a reference from an external file dynamically at runtime
/// ATENTION: Needs fable-compiler 2.3, pass the reference directly in argument position (avoid pipes)
let importValueDynamic (x: 'T): JS.Promise<'T> = jsNative

/// Used when you need to send an F# record to a JS library accepting only plain JS objects (POJOs)
let toPlainJsObj(o: 'T): obj = jsNative

Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Core/Fable.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>3.0.0</Version>
<PackageVersion>3.0.0-beta-005</PackageVersion>
<PackageVersion>3.0.0-beta-006</PackageVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
Expand Down
4 changes: 4 additions & 0 deletions src/Fable.Core/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 3.0.0-beta-006

* Add `JsInterop.importValueDynamic`

### 3.0.0-beta-005

* Move `nameof` operators to Experimental module
Expand Down
59 changes: 35 additions & 24 deletions src/Fable.Transforms/FSharp2Fable.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open Fable.AST
open Fable.Transforms

type Context =
{ Scope: (FSharpMemberOrFunctionOrValue * Fable.Expr) list
{ Scope: (FSharpMemberOrFunctionOrValue * Fable.Ident * Fable.Expr option) list
ScopeInlineValues: (FSharpMemberOrFunctionOrValue * FSharpExpr) list
GenericArgs: Map<string, Fable.Type>
EnclosingMember: FSharpMemberOrFunctionOrValue option
Expand Down Expand Up @@ -327,11 +327,11 @@ module Patterns =
/// Detects AST pattern of "raise MatchFailureException()"
let (|RaisingMatchFailureExpr|_|) (expr: FSharpExpr) =
match expr with
| BasicPatterns.Call(None, methodInfo, [ ], [unitType], [value]) ->
| BasicPatterns.Call(None, methodInfo, [ ], [_unitType], [value]) ->
match methodInfo.FullName with
| "Microsoft.FSharp.Core.Operators.raise" ->
match value with
| BasicPatterns.NewRecord(recordType, [ BasicPatterns.Const (value, valueT) ; rangeFrom; rangeTo ]) ->
| BasicPatterns.NewRecord(recordType, [BasicPatterns.Const (value, _valueT) ; _rangeFrom; _rangeTo]) ->
match recordType.TypeDefinition.FullName with
| "Microsoft.FSharp.Core.MatchFailureException"-> Some (value.ToString())
| _ -> None
Expand Down Expand Up @@ -664,8 +664,8 @@ module Identifiers =
open Helpers
open TypeHelpers

let bindExpr (ctx: Context) (fsRef: FSharpMemberOrFunctionOrValue) expr =
{ ctx with Scope = (fsRef, expr)::ctx.Scope}
let putIdentInScope (ctx: Context) (fsRef: FSharpMemberOrFunctionOrValue) (ident: Fable.Ident) value =
{ ctx with Scope = (fsRef, ident, value)::ctx.Scope}

let makeIdentFrom (com: IFableCompiler) (ctx: Context) (fsRef: FSharpMemberOrFunctionOrValue): Fable.Ident =
let sanitizedName = (fsRef.CompiledName, Naming.NoMemberPart)
Expand All @@ -682,25 +682,36 @@ module Identifiers =
Range = { makeRange fsRef.DeclarationLocation
with identifierName = Some fsRef.DisplayName } |> Some }

/// Sanitize F# identifier and create new context
let bindIdentFrom com ctx (fsRef: FSharpMemberOrFunctionOrValue): Context*Fable.Ident =
let putArgInScope com ctx (fsRef: FSharpMemberOrFunctionOrValue): Context*Fable.Ident =
let ident = makeIdentFrom com ctx fsRef
bindExpr ctx fsRef (Fable.IdentExpr ident), ident
putIdentInScope ctx fsRef ident None, ident

let (|PutArgInScope|) com ctx fsRef = putArgInScope com ctx fsRef

let (|BindIdent|) com ctx fsRef = bindIdentFrom com ctx fsRef

let inline tryGetBoundExprWhere (ctx: Context) r predicate =
match List.tryFind (fun (fsRef,_) -> predicate fsRef) ctx.Scope with
| Some(_, Fable.IdentExpr ident) ->
let putBindingInScope com ctx (fsRef: FSharpMemberOrFunctionOrValue) value: Context*Fable.Ident =
let ident = makeIdentFrom com ctx fsRef
putIdentInScope ctx fsRef ident (Some value), ident

let inline tryGetIdentFromScopeIf (ctx: Context) r predicate =
match List.tryFind (fun (fsRef,_,_) -> predicate fsRef) ctx.Scope with
| Some(_,ident,_) ->
let originalName = ident.Range |> Option.bind (fun r -> r.identifierName)
{ ident with Range = r |> Option.map (fun r -> { r with identifierName = originalName }) }
|> Fable.IdentExpr |> Some
| Some(_, boundExpr) -> Some boundExpr
| None -> None

/// Get corresponding identifier to F# value in current scope
let tryGetBoundExpr (ctx: Context) r (fsRef: FSharpMemberOrFunctionOrValue) =
tryGetBoundExprWhere ctx r (fun fsRef' -> obj.Equals(fsRef, fsRef'))
let tryGetIdentFromScope (ctx: Context) r (fsRef: FSharpMemberOrFunctionOrValue) =
tryGetIdentFromScopeIf ctx r (fun fsRef' -> obj.Equals(fsRef, fsRef'))

let rec tryGetBoundValueFromScope (ctx: Context) identName =
match ctx.Scope |> List.tryFind (fun (_,ident,_) -> ident.Name = identName) with
| Some(_,_,value) ->
match value with
| Some(Fable.IdentExpr ident) when not ident.IsMutable ->
tryGetBoundValueFromScope ctx ident.Name
| v -> v
| None -> None

module Util =
open Helpers
Expand All @@ -712,7 +723,7 @@ module Util =
let ctx, args =
((ctx, []), args)
||> List.fold (fun (ctx, accArgs) var ->
let newContext, arg = bindIdentFrom com ctx var
let newContext, arg = putArgInScope com ctx var
newContext, arg::accArgs)
ctx, List.rev args

Expand All @@ -722,7 +733,7 @@ module Util =
// Within private members (first arg is ConstructorThisValue) F# AST uses
// ThisValue instead of Value (with .IsMemberConstructorThisValue = true)
| (firstArg::restArgs1)::restArgs2 when firstArg.IsConstructorThisValue || firstArg.IsMemberThisValue ->
let ctx, thisArg = bindIdentFrom com ctx firstArg
let ctx, thisArg = putArgInScope com ctx firstArg
let thisArg = { thisArg with Kind = Fable.ThisArgIdentDeclaration }
let ctx =
if firstArg.IsConstructorThisValue
Expand All @@ -740,7 +751,7 @@ module Util =
let makeTryCatch com ctx r (Transform com ctx body) catchClause finalBody =
let catchClause =
match catchClause with
| Some (BindIdent com ctx (catchContext, catchVar), catchBody) ->
| Some (PutArgInScope com ctx (catchContext, catchVar), catchBody) ->
// Add caughtException to context so it can be retrieved by `reraise`
let catchContext = { catchContext with CaughtException = Some catchVar }
Some (catchVar, com.Transform(catchContext, catchBody))
Expand Down Expand Up @@ -889,7 +900,7 @@ module Util =
if file = com.CurrentFile then
makeIdentExprNonMangled entityName
elif isPublicEntity ent then
makeInternalImport Fable.Any entityName file
makeInternalImport com Fable.Any entityName file
else
error "Cannot inline functions that reference private entities"

Expand Down Expand Up @@ -917,7 +928,7 @@ module Util =
{ makeTypedIdentNonMangled typ memberName with Range = r }
|> Fable.IdentExpr
elif isPublicMember memb then
makeInternalImport typ memberName file
makeInternalImport com typ memberName file
else
defaultArg (memb.TryGetFullDisplayName()) memb.CompiledName
|> sprintf "Cannot reference private members from other files: %s"
Expand Down Expand Up @@ -1061,7 +1072,7 @@ module Util =
let ident = { makeIdentFrom com ctx argId with
Type = arg.Type
IsCompilerGenerated = true }
let ctx = bindExpr ctx argId (Fable.IdentExpr ident)
let ctx = putIdentInScope ctx argId ident (Some arg)
ctx, (ident, arg)::bindings)
let ctx = { ctx with GenericArgs = genArgs.Value |> Map
InlinedFunction = Some memb
Expand Down Expand Up @@ -1132,7 +1143,7 @@ module Util =
| Imported com r typ (Some argInfo) isModuleValue imported -> imported
| Replaced com ctx r typ argTypes genArgs argInfo isModuleValue replaced -> replaced
| Inlined com ctx r genArgs callee args expr, _ -> expr
| Try (tryGetBoundExpr ctx r) funcExpr, _ ->
| Try (tryGetIdentFromScope ctx r) funcExpr, _ ->
if isModuleValue
then funcExpr
else staticCall r typ argInfo funcExpr
Expand Down Expand Up @@ -1162,5 +1173,5 @@ module Util =
| Emitted com r typ None emitted, _ -> emitted
| Imported com r typ None true imported -> imported
// TODO: Replaced? Check if there're failing tests
| Try (tryGetBoundExpr ctx r) expr, _ -> expr
| Try (tryGetIdentFromScope ctx r) expr, _ -> expr
| _ -> memberRefTyped com ctx r typ v
Loading

0 comments on commit c12678d

Please sign in to comment.