Skip to content

Commit

Permalink
fable-core.js generation from TypeScript (#240)
Browse files Browse the repository at this point in the history
* [WIP: DO NOT MERGE] Adds es2015-mini.ts (es2015.js ported to TypeScript). Initial proof of concept: List and (partial) Seq class only.

* Fix build target 'FableCore' on Windows.

* Adds TypeScript compilation in build target FableCore.

- Renames es2015-mini.ts to fable-core.tsc.ts

* Adds Symbol, Choice, Util, TimeSpan, Date and Timer (not strongly typed) to fable-core.tsc.ts.

* Add remaining classes to fable-core.tsc.ts

* (!) Builds fable-core.js from TypeScript sources. -- Builds are ok. Tests are not.

* Latest fixes to fable-core.tsc.ts. All tests passing now.

* Expands some test cases.

* Adds tests removed from commit ("Expands some test cases." / db0a0e5)
  • Loading branch information
fdcastel authored and alfonsogarciacaro committed Jul 11, 2016
1 parent 372222b commit 42399f8
Show file tree
Hide file tree
Showing 10 changed files with 2,660 additions and 6 deletions.
21 changes: 16 additions & 5 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,27 @@ Target "FableCore" (fun _ ->
| true -> true) false
|> ignore

// Builds fable-core.babel.js from ES2015 sources.
try
sprintf "es2015.js -o fable-core.js --plugins %s-umd" babelPlugin |> run "babel"
sprintf "es2015.js -o fable-core.babel.js --plugins %s-umd --no-babelrc" babelPlugin |> run "babel"
// The commonjs version is for Fuse, which is not compatible with UMD
sprintf "es2015.js -o commonjs.js --plugins %s-commonjs" babelPlugin |> run "babel"
sprintf "es2015.js -o commonjs.babel.js --plugins %s-commonjs --no-babelrc" babelPlugin |> run "babel"
with
| _ -> failwith "Cannot find Babel CLI, please run `npm i -g babel-cli`"
| _ -> failwith "Cannot find Babel CLI. Please run `npm i -g babel-cli`"

// Builds fable-core.js from TypeScript sources.
// FIXME: Requires 'npm install babel-preset-es2015' in src/fable/Fable.Core/npm
try "fable-core.tsc.ts --target ES2015 --declaration" |> run "tsc"
with _ -> failwith "Cannot find TypeScript compiler. Please run `npm i -g typescript`"
setEnvironVar "BABEL_ENV" "target-umd"
"fable-core.tsc.js -o fable-core.js" |> run "babel"
setEnvironVar "BABEL_ENV" "target-commonjs"
"fable-core.tsc.js -o commonjs.js" |> run "babel"
fableCoreNpmDir + "/fable-core.tsc.js" |> FileUtils.rm

if environVar "DEV_MACHINE" = "1" then
try "fable-core.js -c -m -o fable-core.min.js" |> run "uglifyjs"
with _ -> failwith "Cannot find uglify-js, please run `npm i -g uglify-js`"
try "fable-core.babel.js -c -m -o fable-core.min.js" |> run "uglifyjs"
with _ -> failwith "Cannot find uglify-js. Please run `npm i -g uglify-js`"

// Update Fable.Core version
Util.assemblyInfo "src/fable/Fable.Core/" fableCoreVersion []
Expand Down
5 changes: 4 additions & 1 deletion src/fable/Fable.Compiler/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,10 @@ module private AstPass =
| "head" | "tail" | "length" | "count" ->
let meth = if meth = "count" then "length" else meth
match kind with
| Seq -> ccall "Seq" meth (staticArgs c args)
| Seq ->
// A static 'length' method causes problems in JavaScript -- https://github.com/Microsoft/TypeScript/issues/442
let seqMeth = if meth = "length" then "_length" else meth
ccall "Seq" seqMeth (staticArgs c args)
| List -> let c, _ = instanceArgs c args in prop meth c
| Array ->
let c, _ = instanceArgs c args
Expand Down
32 changes: 32 additions & 0 deletions src/fable/Fable.Core/npm/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"env": {
"target-umd": {
"presets": [
"es2015"
],
"plugins": [
"transform-es2015-modules-umd",
[
"transform-es2015-classes",
{
"loose": true
}
]
]
},
"target-commonjs": {
"presets": [
"es2015"
],
"plugins": [
"transform-es2015-modules-commonjs",
[
"transform-es2015-classes",
{
"loose": true
}
]
]
}
}
}

0 comments on commit 42399f8

Please sign in to comment.