Skip to content

Commit be9d39e

Browse files
Test compiled by fable-js passing!
1 parent e4a3cab commit be9d39e

File tree

20 files changed

+274
-280
lines changed

20 files changed

+274
-280
lines changed

.vscode/launch.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,14 @@
101101
"cwd": "${workspaceFolder}/src/fable-standalone/test/bench-compiler"
102102
},
103103
{
104+
// src/fable-compiler-js/ tests/Main/Fable.Tests.fsproj build/tests-js
105+
104106
"type": "node",
105107
"request": "launch",
106108
"name": "transform tests to JS",
107-
"program": "${workspaceRoot}/src/fable-standalone/test/bench-compiler/transform.js",
108-
"args": ["${workspaceRoot}/tests/Main/Fable.Tests.fsproj", "out-tests", "${workspaceRoot}/build/fable-library", "--commonjs"],
109-
"cwd": "${workspaceRoot}/src/fable-standalone/test/bench-compiler"
109+
"program": "${workspaceRoot}/build/fable-compiler-js/src/fable-compiler-js/src/app.fs.js",
110+
"args": ["${workspaceRoot}/tests/Main/Fable.Tests.fsproj", "build/tests-js"],
111+
"stopOnEntry": true
110112
},
111113
{
112114
"type": "node",

Fable.sln

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.Tests.Spaces", "tests
1919
EndProject
2020
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.Tests.External", "tests_external\Fable.Tests.External.fsproj", "{F5DEF871-BEEB-40A1-BBF1-7A19BD8B6185}"
2121
EndProject
22-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ASTViewer", "src\tools\ASTViewer\ASTViewer.fsproj", "{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}"
23-
EndProject
2422
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.Library", "src\fable-library\Fable.Library.fsproj", "{C6B876C9-8410-4FFF-AD89-46539E54253C}"
2523
EndProject
2624
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{54BD4E45-0C5B-455A-9C7C-37736B216015}"
@@ -140,18 +138,6 @@ Global
140138
{F5DEF871-BEEB-40A1-BBF1-7A19BD8B6185}.Release|x64.Build.0 = Release|Any CPU
141139
{F5DEF871-BEEB-40A1-BBF1-7A19BD8B6185}.Release|x86.ActiveCfg = Release|Any CPU
142140
{F5DEF871-BEEB-40A1-BBF1-7A19BD8B6185}.Release|x86.Build.0 = Release|Any CPU
143-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
144-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
145-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Debug|x64.ActiveCfg = Debug|Any CPU
146-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Debug|x64.Build.0 = Debug|Any CPU
147-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Debug|x86.ActiveCfg = Debug|Any CPU
148-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Debug|x86.Build.0 = Debug|Any CPU
149-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
150-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Release|Any CPU.Build.0 = Release|Any CPU
151-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Release|x64.ActiveCfg = Release|Any CPU
152-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Release|x64.Build.0 = Release|Any CPU
153-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Release|x86.ActiveCfg = Release|Any CPU
154-
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Release|x86.Build.0 = Release|Any CPU
155141
{C6B876C9-8410-4FFF-AD89-46539E54253C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
156142
{C6B876C9-8410-4FFF-AD89-46539E54253C}.Debug|Any CPU.Build.0 = Debug|Any CPU
157143
{C6B876C9-8410-4FFF-AD89-46539E54253C}.Debug|x64.ActiveCfg = Debug|Any CPU

build.fsx

Lines changed: 82 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,27 @@ let buildLibraryTs() =
111111
runInDir buildDirTs ("npx tsc --outDir ../../" + buildDirJs)
112112

113113
let quicktest () =
114-
runFableWithArgs "src/quicktest" ["--exclude Fable.Core"]
114+
runFableWithArgs "src/quicktest" [
115+
"--force-pkgs"
116+
"--exclude Fable.Core"
117+
]
115118
run "npx tsc src/quicktest/QuickTest.fs.js --allowJs -m commonJs --outDir build/quicktest"
116119
run "node build/quicktest/src/quicktest/QuickTest.fs.js"
117120

118-
let buildCompilerJs() =
119-
let projectDir = "src/fable-compiler-js"
120-
cleanDirs [projectDir </> "dist"]
121-
runFableWithArgs (projectDir </> "src") [
122-
"--exclude Fable.Core"
121+
let compileFcs() =
122+
runFableWithArgs "src/fable-standalone/src" [
123+
"--force-pkgs"
124+
"--typed-arrays"
125+
"--define FX_NO_CORHOST_SIGNER"
126+
"--define FX_NO_LINKEDRESOURCES"
127+
"--define FX_NO_PDB_READER"
128+
"--define FX_NO_PDB_WRITER"
129+
"--define FX_NO_WEAKTABLE"
130+
"--define FX_REDUCED_EXCEPTIONS"
131+
"--define NO_COMPILER_BACKEND"
132+
"--define NO_EXTENSIONTYPING"
133+
"--define NO_INLINE_IL_PARSER"
123134
]
124-
run (sprintf "npx rollup %s/src/app.fs.js --file %s/dist/app.js --format umd --name Fable" projectDir projectDir)
125-
run (sprintf "npx terser %s/dist/app.js -o %s/dist/app.min.js --mangle --compress" projectDir projectDir)
126135

127136
let buildStandalone() =
128137
let buildDir = "build/fable-standalone"
@@ -137,19 +146,10 @@ let buildStandalone() =
137146
makeDirRecursive distDir
138147

139148
// build
140-
runFableWithArgs projectDir [
141-
"--typed-arrays"
142-
"--define FX_NO_CORHOST_SIGNER"
143-
"--define FX_NO_LINKEDRESOURCES"
144-
"--define FX_NO_PDB_READER"
145-
"--define FX_NO_PDB_WRITER"
146-
"--define FX_NO_WEAKTABLE"
147-
"--define FX_REDUCED_EXCEPTIONS"
148-
"--define NO_COMPILER_BACKEND"
149-
"--define NO_EXTENSIONTYPING"
150-
"--define NO_INLINE_IL_PARSER"
149+
compileFcs()
150+
runFableWithArgs (projectDir + "/Worker") [
151+
"--force-pkgs"
151152
]
152-
runFable (projectDir + "/Worker")
153153

154154
// bundle
155155
run (sprintf "npx rollup %s/Main.fs.js --file %s/bundle.js --format umd --name __FABLE_STANDALONE__" projectDir buildDir)
@@ -187,41 +187,74 @@ let buildStandalone() =
187187
// (if comMajor > staMajor || comMinor > staMinor then compilerVersion
188188
// else sprintf "%i.%i.%i%s" staMajor staMinor (staPatch + 1) comPrerelease)
189189

190-
let testJs() =
191-
let projectDir = "src/fable-compiler-js"
192-
let buildDir = "build/tests-js"
193-
if not (pathExists "build/fable-standalone") then
194-
buildStandalone()
195-
if not (pathExists "build/fable-compiler-js") then
196-
buildCompilerJs()
197-
198-
cleanDirs [buildDir]
190+
let buildCompilerJs() =
191+
compileFcs()
199192

200-
// Link fable-compiler-js to local packages
201-
runInDir projectDir "npm link ../fable-metadata"
202-
runInDir projectDir "npm link ../fable-standalone"
193+
let projectDir = "src/fable-compiler-js"
194+
runFableWithArgs (projectDir </> "src") [
195+
"--force-pkgs"
196+
"--exclude Fable.Core"
197+
]
203198

204-
// Test fable-compiler-js locally
205-
run ("node " + projectDir + " tests/Main/Fable.Tests.fsproj " + buildDir + " --commonjs")
206-
run ("npx mocha " + buildDir + " --reporter dot -t 10000")
207-
// and another test
208-
runInDir "src/fable-compiler-js/test" "node .. test_script.fsx --commonjs"
209-
runInDir "src/fable-compiler-js/test" "node bin/test_script.js"
199+
cleanDirs [projectDir </> "dist"]
200+
// run (sprintf "npx rollup %s/src/app.fs.js --file %s/dist/app.js --format umd --name Fable" projectDir projectDir)
201+
// run (sprintf "npx terser %s/dist/app.js -o %s/dist/app.min.js --mangle --compress" projectDir projectDir)
202+
203+
// Compile to commonjs modules
204+
runTypescript "src/fable-compiler-js"
205+
// Copy fable-library
206+
copyDirRecursive ("build/fable-library") (projectDir </> "dist/fable-library")
207+
// Copy fable-metadata
208+
copyDirRecursive ("src/fable-metadata/lib") (projectDir </> "dist/fable-metadata")
209+
210+
let compileAndRunTests(compileTests) =
211+
// TODO: "rm tests/**/*.fs.js"
212+
compileTests()
213+
cleanDirs ["build/tests"]
214+
runTypescript "tests"
215+
run "npx mocha build/tests/tests/Main --reporter dot -t 10000"
210216

211-
// Unlink local packages after test
212-
runInDir projectDir "npm unlink ../fable-metadata && cd ../fable-metadata && npm unlink"
213-
runInDir projectDir "npm unlink ../fable-standalone && cd ../fable-standalone && npm unlink"
217+
let testJs() =
218+
buildCompilerJs()
219+
compileAndRunTests(fun () ->
220+
run "node src/fable-compiler-js tests/Main/Fable.Tests.fsproj")
221+
222+
// let projectDir = "src/fable-compiler-js"
223+
// let buildDir = "build/tests-js"
224+
// if not (pathExists "build/fable-standalone") then
225+
// buildStandalone()
226+
// if not (pathExists "build/fable-compiler-js") then
227+
// buildCompilerJs()
228+
229+
// cleanDirs [buildDir]
230+
231+
// // Link fable-compiler-js to local packages
232+
// runInDir projectDir "npm link ../fable-metadata"
233+
// runInDir projectDir "npm link ../fable-standalone"
234+
235+
// // Test fable-compiler-js locally
236+
// run ("node " + projectDir + " tests/Main/Fable.Tests.fsproj " + buildDir + " --commonjs")
237+
// run ("npx mocha " + buildDir + " --reporter dot -t 10000")
238+
// // and another test
239+
// runInDir "src/fable-compiler-js/test" "node .. test_script.fsx --commonjs"
240+
// runInDir "src/fable-compiler-js/test" "node bin/test_script.js"
241+
242+
// // Unlink local packages after test
243+
// runInDir projectDir "npm unlink ../fable-metadata && cd ../fable-metadata && npm unlink"
244+
// runInDir projectDir "npm unlink ../fable-standalone && cd ../fable-standalone && npm unlink"
214245

215246
let test() =
216-
if pathExists "build/fable-library" |> not then
217-
buildLibrary()
247+
compileAndRunTests(fun () ->
248+
if pathExists "build/fable-library" |> not then
249+
buildLibrary()
218250

219-
runFableWithArgs "tests/Main" ["--exclude Fable.Core"; "--force-pkgs"]
220-
runTypescript "tests"
221-
run "npx mocha build/tests/tests/Main --reporter dot -t 10000"
222-
runInDir "tests/Main" "dotnet run"
251+
runFableWithArgs "tests/Main" [
252+
"--force-pkgs"
253+
"--exclude Fable.Core"
254+
]
255+
)
223256

224-
// TODO: Temporarily deactivated to get green builds
257+
runInDir "tests/Main" "dotnet run"
225258
if envVarOrNone "APPVEYOR" |> Option.isSome then
226259
testJs()
227260

@@ -342,6 +375,7 @@ match argsLower with
342375
| ("fable-library-ts"|"library-ts")::_ -> buildLibraryTs()
343376
| ("fable-compiler-js"|"compiler-js")::_ -> buildCompilerJs()
344377
| ("fable-standalone"|"standalone")::_ -> buildStandalone()
378+
| "fcs"::_ -> compileFcs()
345379
| "download-standalone"::_ -> downloadStandalone()
346380
| "publish"::restArgs -> publishPackages restArgs
347381
| "github-release"::_ ->

package-lock.json

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Fable.Transforms/AST/AST.Babel.fs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,17 @@ module PrinterExtensions =
8484
if i < nodes.Length - 1 then
8585
printSeparator printer
8686

87-
member printer.PrintCommaSeparatedArray(nodes: #Node array) =
88-
printer.PrintArray(nodes, (fun p x -> x.Print(p)), (fun p -> p.Print(", ")))
87+
member printer.PrintCommaSeparatedArray(nodes: ExportSpecifier array) =
88+
printer.PrintArray(nodes, (fun p x -> p.Print(x)), (fun p -> p.Print(", ")))
89+
90+
member printer.PrintCommaSeparatedArray(nodes: #ImportSpecifier array) =
91+
printer.PrintArray(nodes, (fun p x -> p.Print(x)), (fun p -> p.Print(", ")))
92+
93+
member printer.PrintCommaSeparatedArray(nodes: Pattern array) =
94+
printer.PrintArray(nodes, (fun p x -> p.Print(x)), (fun p -> p.Print(", ")))
95+
96+
member printer.PrintCommaSeparatedArray(nodes: Expression array) =
97+
printer.PrintArray(nodes, (fun p x -> p.SequenceExpressionWithParens(x)), (fun p -> p.Print(", ")))
8998

9099
// TODO: (super) type parameters, implements
91100
member printer.PrintClass(id: Identifier option, superClass: Expression option, body: ClassBody, loc) =
@@ -127,15 +136,13 @@ module PrinterExtensions =
127136
| Some e -> e.Print(printer)
128137
| None ->
129138
if isArrow then
130-
// TODO: Remove parens if we only have one argument (and no annotation)
139+
// Remove parens if we only have one argument? (and no annotation)
131140
printer.Print("(")
132141
printer.PrintCommaSeparatedArray(parameters)
133142
printer.Print(") => ")
134143
match body.Body with
135144
| [|:? ReturnStatement as r |] ->
136-
match r.Argument with
137-
| :? ObjectExpression as e -> printer.WithParens(e)
138-
| e -> printer.Print(e)
145+
printer.ComplexExpressionWithParens(r.Argument, objExpr=true)
139146
| _ -> printer.PrintBlock(body.Body, skipNewLineAtEnd=true)
140147
else
141148
printer.Print("function ")
@@ -156,7 +163,7 @@ module PrinterExtensions =
156163
| _ -> printer.Print(expr)
157164

158165
/// Surround with parens anything that can potentially conflict with operator precedence
159-
member printer.ComplexExpressionWithParens(expr: Expression) =
166+
member printer.ComplexExpressionWithParens(expr: Expression, ?objExpr) =
160167
match expr with
161168
| :? Undefined
162169
| :? NullLiteral
@@ -167,9 +174,12 @@ module PrinterExtensions =
167174
| :? MemberExpression
168175
| :? CallExpression
169176
// | :? NewExpression // Safe?
170-
| :? ObjectExpression
171177
| :? ThisExpression
172178
| :? Super -> expr.Print(printer)
179+
| :? ObjectExpression ->
180+
match objExpr with
181+
| Some true -> printer.WithParens(expr)
182+
| _ -> expr.Print(printer)
173183
| _ -> printer.WithParens(expr)
174184

175185
member printer.PrintOperation(left, operator, right, loc) =
@@ -535,31 +545,33 @@ type TryStatement(block, ?handler, ?finalizer, ?loc) =
535545
printer.PrintOptional("finally ", finalizer)
536546

537547
// Declarations
538-
type VariableDeclarator(id, ?init, ?loc) =
548+
type VariableDeclarator(id, ?init) =
539549
member _.Id: Pattern = id
540550
member _.Init: Expression option = init
541-
interface Node with
542-
member _.Print(printer) =
543-
printer.AddLocation(loc)
544-
id.Print(printer)
545-
match init with
546-
| None -> ()
547-
| Some e ->
548-
printer.Print(" = ")
549-
printer.SequenceExpressionWithParens(e)
550551

551552
type VariableDeclarationKind = Var | Let | Const
552553

553554
type VariableDeclaration(kind_, declarations, ?loc) =
554555
let kind = match kind_ with Var -> "var" | Let -> "let" | Const -> "const"
555556
new (var, ?init, ?kind, ?loc) =
556-
VariableDeclaration(defaultArg kind Let, [|VariableDeclarator(var, ?init=init, ?loc=loc)|], ?loc=loc)
557+
VariableDeclaration(defaultArg kind Let, [|VariableDeclarator(var, ?init=init)|], ?loc=loc)
557558
member _.Declarations: VariableDeclarator array = declarations
558559
member _.Kind: string = kind
559560
interface Declaration with
560561
member _.Print(printer) =
561562
printer.Print(kind + " ", ?loc=loc)
562-
printer.PrintCommaSeparatedArray(declarations)
563+
let canConflict = declarations.Length > 1
564+
for i = 0 to declarations.Length - 1 do
565+
let decl = declarations.[i]
566+
printer.Print(decl.Id)
567+
match decl.Init with
568+
| None -> ()
569+
| Some e ->
570+
printer.Print(" = ")
571+
if canConflict then printer.ComplexExpressionWithParens(e)
572+
else printer.SequenceExpressionWithParens(e)
573+
if i < declarations.Length - 1 then
574+
printer.Print(", ")
563575

564576
// Loops
565577
type WhileStatement(test, body, ?loc) =

src/fable-compiler-js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env node
2-
require("./dist/app.js");
2+
require("./dist/src/fable-compiler-js/src/app.fs.js");

src/fable-compiler-js/src/Platform.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module Fable.Compiler.Platform
33
open Fable.Core.JsInterop
44

55
type CmdLineOptions = {
6-
commonjs: bool
76
optimize: bool
87
sourceMaps: bool
98
typescript: bool
@@ -40,6 +39,7 @@ module JS =
4039
abstract transformAndSaveBabelAst: babelAst: obj * outPath: string * projDir: string * outDir: string * libDir: string * options: CmdLineOptions -> unit
4140
abstract runCmdAndExitIfFails: cmd: string -> unit
4241
abstract getDirFiles: dir: string -> string[]
42+
abstract escapeJsStringLiteral: string -> string
4343

4444
let fs: IFileSystem = importAll "fs"
4545
let os: IOperSystem = importAll "os"
@@ -59,12 +59,11 @@ let measureTime (f: 'a -> 'b) x =
5959
res, int64 (elapsed.[0] * 1e3 + elapsed.[1] / 1e6)
6060

6161
let javaScriptStringEncode (str: string) =
62-
Fable.Core.JS.JSON.stringify(str)?slice(1, -1)
62+
JS.util.escapeJsStringLiteral(str)
6363

6464
let getVersion = JS.util.getVersion
6565
let ensureDirExists = JS.util.ensureDirExists
6666
let copyFolder = JS.util.copyFolder
67-
let transformAndSaveBabelAst = JS.util.transformAndSaveBabelAst
6867
let runCmdAndExitIfFails = JS.util.runCmdAndExitIfFails
6968

7069
let normalizeFullPath (path: string) =

0 commit comments

Comments
 (0)