Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fable-core.js generation from TypeScript #240

Merged
merged 13 commits into from
Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,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`"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh oh... lines 274-278 shouldn't be here 😭

// Update Fable.Core version
Util.assemblyInfo "src/fable/Fable.Core/" fableCoreVersion []
Expand Down
5 changes: 4 additions & 1 deletion src/fable/Fable.Core/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
}
]
]
}
}
}