Skip to content

Commit

Permalink
Changed typed flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ncave committed May 6, 2020
1 parent 38c3d43 commit b23f9f4
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"name": "bench-compile (Node)",
"program": "${workspaceRoot}/src/fable-standalone/test/bench-compiler/out-node/app.js",
// "args": ["${workspaceRoot}/tests/Main/Fable.Tests.fsproj", "out-tests", "--commonjs"],
"args": ["${workspaceRoot}/../fable-test/fable-test.fsproj", "out-test", "--typed"],
"args": ["${workspaceRoot}/../fable-test/fable-test.fsproj", "out-test", "--typescript"],
"cwd": "${workspaceRoot}/src/fable-standalone/test/bench-compiler"
},
{
Expand All @@ -59,7 +59,7 @@
"name": "bench-compile (.NET)",
"program": "${workspaceFolder}/src/fable-standalone/test/bench-compiler/bin/Debug/netcoreapp2.1/bench-compiler.dll",
// "args": ["${workspaceRoot}/tests/Main/Fable.Tests.fsproj", "out-tests", "--commonjs"],
"args": ["${workspaceRoot}/../fable-test/fable-test.fsproj", "out-test", "--typed"],
"args": ["${workspaceRoot}/../fable-test/fable-test.fsproj", "out-test", "--typescript"],
"cwd": "${workspaceFolder}/src/fable-standalone/test/bench-compiler"
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Cli/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let private parseDic (key: string) (o: JObject): IDictionary<string,string> =
let toCompilerOptions (msg: Message): CompilerOptions =
{ typedArrays = msg.typedArrays
clampByteArrays = msg.clampByteArrays
typeDecls = msg.extra.ContainsKey("typed")
typeDecls = msg.extra.ContainsKey("typescript")
debugMode = Array.contains "DEBUG" msg.define
verbosity = GlobalParams.Singleton.Verbosity
outputPublicInlinedFunctions = Array.contains "FABLE_REPL_LIB" msg.define
Expand Down
21 changes: 12 additions & 9 deletions src/Fable.Transforms/Fable2Babel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1717,12 +1717,12 @@ module Util =
let classExpr = ClassExpression(classBody, ?superClass=baseExpr, ?loc=r)
classExpr |> declareModuleMember r isPublic name false

let declareType com ctx r isPublic (ent: FSharpEntity) name (consArgs: Pattern[]) (consBody: BlockStatement) baseExpr: U2<Statement, ModuleDeclaration> list =
let declareType (com: IBabelCompiler) ctx r isPublic (ent: FSharpEntity) name (consArgs: Pattern[]) (consBody: BlockStatement) baseExpr: U2<Statement, ModuleDeclaration> list =
let typeDeclaration =
// if ent.IsFSharpUnion || ent.IsFSharpRecord || ent.IsValueType || ent.IsFSharpExceptionDeclaration
// if com.Options.typeDecls && (ent.IsFSharpUnion || ent.IsFSharpRecord || ent.IsValueType || ent.IsFSharpExceptionDeclaration)
// then declareClassType com ctx r isPublic ent name consArgs consBody baseExpr
// else
declareObjectType com ctx r isPublic ent name consArgs consBody baseExpr
declareObjectType com ctx r isPublic ent name consArgs consBody baseExpr
let reflectionDeclaration =
let genArgs = Array.init ent.GenericParameters.Count (fun _ -> makeIdentUnique com "gen" |> typedIdent com ctx)
let body = transformReflectionInfo com ctx r ent (Array.map (fun x -> x :> _) genArgs)
Expand Down Expand Up @@ -1812,15 +1812,18 @@ module Util =
Identifier "name" |> toPattern
Identifier "fields" |> restElement|]
let body =
[Identifier "tag" :> Expression; Identifier "name" :> _; SpreadElement(Identifier "fields") :> _]
|> callFunctionWithThisContext None baseRef thisExpr |> ExpressionStatement
declareType com ctx r info.IsPublic info.Entity info.EntityName args (BlockStatement [|body|]) (Some baseRef)
[Identifier "tag" :> Expression
Identifier "name" :> Expression
SpreadElement(Identifier "fields") :> Expression]
|> callFunctionWithThisContext None baseRef thisExpr
|> ExpressionStatement :> Statement |> Array.singleton |> BlockStatement
declareType com ctx r info.IsPublic info.Entity info.EntityName args body (Some baseRef)

let transformCompilerGeneratedConstructor (com: IBabelCompiler) ctx r (info: Fable.CompilerGeneratedConstructorInfo) =
let args =
[| for i = 1 to info.Entity.FSharpFields.Count do
yield Identifier("arg" + string i) |]
let setters =
let body =
info.Entity.FSharpFields
|> Seq.mapi (fun i field ->
let left = get None (ThisExpression()) field.Name
Expand All @@ -1830,15 +1833,15 @@ module Util =
then BinaryExpression(BinaryOrBitwise, args.[i], NumericLiteral(0.)) :> Expression
else args.[i] :> _
assign None left right |> ExpressionStatement :> Statement)
|> Seq.toArray
|> Seq.toArray |> BlockStatement
let baseExpr =
if info.Entity.IsFSharpExceptionDeclaration
then coreValue com ctx "Types" "FSharpException" |> Some
elif info.Entity.IsFSharpRecord || info.Entity.IsValueType
then coreValue com ctx "Types" "Record" |> Some
else None
let args = [|for arg in args do yield arg |> toPattern|]
declareType com ctx r info.IsPublic info.Entity info.EntityName args (BlockStatement setters) baseExpr
declareType com ctx r info.IsPublic info.Entity info.EntityName args body baseExpr

let transformImplicitConstructor (com: IBabelCompiler) ctx r (info: Fable.ClassImplicitConstructorInfo) =
let boundThis = Some("this", info.BoundConstructorThis)
Expand Down
2 changes: 1 addition & 1 deletion src/fable-compiler-js/src/app.fs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ let run opts projectFileName outDir =
commonjs = Option.isSome commandToRun || opts |> Array.contains "--commonjs"
optimize = opts |> Array.contains "--optimize-fcs"
sourceMaps = opts |> Array.contains "--sourceMaps"
typeDecls = opts |> Array.contains "--typed"
typeDecls = opts |> Array.contains "--typescript"
watchMode = opts |> Array.contains "--watch"
}
parseFiles projectFileName outDir options
Expand Down
2 changes: 1 addition & 1 deletion src/fable-library/FSharp.Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Operators =
let nullArg x = raise(System.ArgumentNullException(x))

[<CompiledName("Using")>]
let using (resource : 'T when 'T :> System.IDisposable) (action: 'T -> 'a) =
let using (resource: System.IDisposable) action =
try action(resource)
finally match (box resource) with null -> () | _ -> resource.Dispose()

Expand Down
4 changes: 2 additions & 2 deletions src/fable-standalone/src/Worker/Worker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ let rec loop (box: MailboxProcessor<WorkerRequest>) (state: State) = async {
| Some fable, CompileCode(fsharpCode, otherFSharpOptions) ->
try
// detect (and remove) a passed non-F# compiler option to avoid changing msg contract
let useTypeDeclarations = otherFSharpOptions |> Array.contains "--typeDecls"
let otherFSharpOptions = otherFSharpOptions |> Array.filter ((<>) "--typeDecls")
let useTypeDeclarations = otherFSharpOptions |> Array.contains "--typescript"
let otherFSharpOptions = otherFSharpOptions |> Array.filter ((<>) "--typescript")
// Check if we need to recreate the FableState because otherFSharpOptions have changed
let! fable = makeFableState (Initialized fable) otherFSharpOptions
let (parseResults, parsingTime) = measureTime (fun () -> fable.Manager.ParseFSharpScript(fable.Checker, FILE_NAME, fsharpCode, otherFSharpOptions)) ()
Expand Down
2 changes: 1 addition & 1 deletion src/fable-standalone/test/bench-compiler/app.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ let parseArguments (argv: string[]) =
commonjs = opts |> Array.contains "--commonjs"
optimize = opts |> Array.contains "--optimize-fcs"
sourceMaps = opts |> Array.contains "--sourceMaps"
typeDecls = opts |> Array.contains "--typed"
typeDecls = opts |> Array.contains "--typescript"
watchMode = opts |> Array.contains "--watch"
}
parseFiles projectFileName outDir options
Expand Down
16 changes: 8 additions & 8 deletions src/fable-standalone/test/bench-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
"rollup-bundle": "npm run rollup -- -i out-node/app.js -o dist/bundle.js --format esm",
"terser-bundle": "npm run terser -- dist/bundle.js -o dist/bundle.min.js --mangle --compress",
"webpack-bundle": "npm run webpack -- -p --entry ./out-node/app.js --output ./dist/bundle.min.js --target node",
"build-lib-dotnet": "dotnet run -c Release ../../../fable-library/Fable.Library.fsproj out-lib --typed && npm run build-lib-transform",
"build-lib-transform": "node transform ../../../fable-library/Fable.Library.fsproj out-lib ../../../../build/fable-library --typed",
"build-lib-dotnet": "dotnet run -c Release ../../../fable-library/Fable.Library.fsproj out-lib --typescript && npm run build-lib-transform",
"build-lib-transform": "node transform ../../../fable-library/Fable.Library.fsproj out-lib ../../../../build/fable-library --typescript",
"postbuild-lib-transform": "rmdir /s /q out-lib\\fable-library && xcopy /s /y ..\\..\\..\\fable-library\\*.ts out-lib\\ && cd out-lib && npx typescript --init",
"tsc-lib": "npx typescript -p out-lib --outDir out-lib-js",
"build-test-node": "node out-node/app.js ../../../../../fable-test/fable-test.fsproj out-test --typed && npm run build-test-transform",
"build-test-dotnet": "dotnet run -c Release ../../../../../fable-test/fable-test.fsproj out-test --typed && npm run build-test-transform",
"build-test-node": "node out-node/app.js ../../../../../fable-test/fable-test.fsproj out-test --typescript && npm run build-test-transform",
"build-test-dotnet": "dotnet run -c Release ../../../../../fable-test/fable-test.fsproj out-test --typescript && npm run build-test-transform",
"build-test-dotnet-opt": "dotnet run -c Release ../../../../../fable-test/fable-test.fsproj out-test --optimize-fcs && npm run build-test-transform",
"build-test-transform": "node transform ../../../../../fable-test/fable-test.fsproj out-test ../../../../build/fable-library --sourceMaps --typed",
"build-test-transform": "node transform ../../../../../fable-test/fable-test.fsproj out-test ../../../../build/fable-library --sourceMaps --typescript",
"test-node": "node ./out-test/src/test.js",
"build-tests-node": "node out-node/app.js ../../../../tests/Main/Fable.Tests.fsproj out-tests --typed && npm run build-tests-transform",
"build-tests-dotnet": "dotnet run -c Release ../../../../tests/Main/Fable.Tests.fsproj out-tests --typed && npm run build-tests-transform",
"build-tests-node": "node out-node/app.js ../../../../tests/Main/Fable.Tests.fsproj out-tests --typescript && npm run build-tests-transform",
"build-tests-dotnet": "dotnet run -c Release ../../../../tests/Main/Fable.Tests.fsproj out-tests --typescript && npm run build-tests-transform",
"build-tests-dotnet-opt": "dotnet run -c Release ../../../../tests/Main/Fable.Tests.fsproj out-tests --optimize-fcs && npm run build-tests-transform",
"build-tests-transform": "node transform ../../../../tests/Main/Fable.Tests.fsproj out-tests ../../../../build/fable-library --typed",
"build-tests-transform": "node transform ../../../../tests/Main/Fable.Tests.fsproj out-tests ../../../../build/fable-library --typescript",
"tsc": "node ../../../../node_modules/typescript/bin/tsc",
"babel": "node ../../../../node_modules/@babel/cli/bin/babel",
"mocha": "node ../../../../node_modules/mocha/bin/mocha --colors",
Expand Down
2 changes: 1 addition & 1 deletion src/fable-standalone/test/bench-compiler/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function main() {
const libDir = Path.resolve(process.argv[4]);
const commonjs = process.argv.find(v => v === "--commonjs");
const sourceMaps = process.argv.find(v => v === "--sourceMaps");
const typeDecls = process.argv.find(v => v === "--typed");
const typeDecls = process.argv.find(v => v === "--typescript");

const babelOptions = commonjs ?
{ plugins: customPlugins.concat("@babel/plugin-transform-modules-commonjs") } :
Expand Down

0 comments on commit b23f9f4

Please sign in to comment.