Skip to content

Commit

Permalink
[feature] rename -js-options into -bs-options and add -bs-diagnose
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongbo Zhang committed May 27, 2016
1 parent ed7facd commit 49e9f02
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 35 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ See http://bloomberg.github.io/bucklescript/, if you want to contribute document


```sh
MODULE_FLAGS='-js-module amdjs' make world
MODULE_FLAGS='-js-module commonjs' make world
MODULE_FLAGS='-js-module goog:buckle' make world
MODULE_FLAGS='-bs-module amdjs' make world
MODULE_FLAGS='-bs-module commonjs' make world
MODULE_FLAGS='-bs-module goog:buckle' make world
```

4. Test
Expand Down
10 changes: 5 additions & 5 deletions docs/Compiler-options.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
BuckleScript inherits the command line arguments of the [OCaml compiler](http://caml.inria.fr/pub/docs/manual-ocaml/comp.html). It also adds several flags:

* -js-module
* -bs-module

Specify the JavaScript module system to use in the generated JavaScript code. Supported values are `commonjs`, `amdjs` and `goog:<namespace>`

When you want to use `goog` module system, you can do things like this:

```bash
bsc -js-module goog xx.ml
bsc -bs-module goog xx.ml
# no namespace

bsc -js-module goog:bloomberg.buckle.test xx.ml
bsc -bs-module goog:bloomberg.buckle.test xx.ml
# namespace is bloomberg.buckle.test
```

You would then need a bundler for different the different module systems: `webpack` supports `commonjs` and `amdjs` while `google closure compiler` supports all.

* -js-gen-tds
* -bs-gen-tds

Trigger the generation of TypeScript `.d.ts` files.

Expand All @@ -39,4 +39,4 @@ If everything goes well, you should have `hello.js`

```
console.log('hello world')
```
```
6 changes: 3 additions & 3 deletions docs/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ Note that by default, `bsc` will generate `commonjs` modules, you can
override such behavior by picking up your own module system:

```sh
MODULE_FLAGS='-js-module amdjs' make world
MODULE_FLAGS='-js-module commonjs' make world
MODULE_FLAGS='-js-module goog:buckle' make world
MODULE_FLAGS='-bs-module amdjs' make world
MODULE_FLAGS='-bs-module commonjs' make world
MODULE_FLAGS='-bs-module goog:buckle' make world
```

Also see [Create a simple example with npm](./Create-a-simple-example-with-NPM.md)
8 changes: 4 additions & 4 deletions docs/NPM-Support.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Since CommonJS has no namespaces, to allow JS files live in different
directories, we have a flag

```sh
bsc -js-npm-output-path $npm_package_name:path/to/your/js/dir -c a.ml
bsc -bs-npm-output-path $npm_package_name:path/to/your/js/dir -c a.ml
```

By passing this flag, `bsc` will store your `package_name` and
Expand All @@ -37,7 +37,7 @@ If you follow the layout convention above, use ocaml package is pretty
straightforward

```
bsc -js-npm-package-include ocaml-library -c a.ml
bsc -bs-npm-package-include ocaml-library -c a.ml
```


Expand All @@ -47,6 +47,6 @@ bsc -js-npm-package-include ocaml-library -c a.ml
Your command line would be like this

```
bsc -js-npm-package-include ocaml-library1 -js-npm-package-include
ocaml-library2 -js-npm-output-path $npm_package_name:lib/js/ -c a.ml
bsc -bs-npm-package-include ocaml-library1 -bs-npm-package-include
ocaml-library2 -bs-npm-output-path $npm_package_name:lib/js/ -c a.ml
```
6 changes: 3 additions & 3 deletions jscomp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ stdlib:


# Example:
# MODULE_FLAGS='-js-module amdjs' make world
# MODULE_FLAGS='-js-module commonjs' make world
# MODULE_FLAGS='-js-module goog:buckle' make world
# MODULE_FLAGS='-bs-module amdjs' make world
# MODULE_FLAGS='-bs-module commonjs' make world
# MODULE_FLAGS='-bs-module goog:buckle' make world

world:
@echo "Making compiler"
Expand Down
12 changes: 6 additions & 6 deletions jscomp/bin/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26668,18 +26668,18 @@ let add_include_path s =


let buckle_script_flags =
("-js-npm-output-path", Arg.String Js_config.set_npm_package_path,
("-bs-npm-output-path", Arg.String Js_config.set_npm_package_path,
" set npm-output-path: package-name:path, for example `bs-platform:lib/js`")
::
("-js-npm-package-include", Arg.String add_include_path,
("-bs-npm-package-include", Arg.String add_include_path,
" set package names, for example bs-platform " )
:: ("-js-module", Arg.String Js_config.cmd_set_module,
:: ("-bs-module", Arg.String Js_config.cmd_set_module,
" set module system: commonjs (default), amdjs, google:package_name")
:: ("-js-no-builtin-ppx-ml", Arg.Set Js_config.no_builtin_ppx_ml,
:: ("-bs-no-builtin-ppx-ml", Arg.Set Js_config.no_builtin_ppx_ml,
"disable built-in ppx for ml files (internal use)")
:: ("-js-no-builtin-ppx-mli", Arg.Set Js_config.no_builtin_ppx_mli,
:: ("-bs-no-builtin-ppx-mli", Arg.Set Js_config.no_builtin_ppx_mli,
"disable built-in ppx for mli files (internal use)")
:: ("-js-gen-tds", Arg.Set Js_config.default_gen_tds,
:: ("-bs-gen-tds", Arg.Set Js_config.default_gen_tds,
" set will generate `.d.ts` file for typescript (experimental)")
:: (
let module F = struct
Expand Down
5 changes: 5 additions & 0 deletions jscomp/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ let get_cross_module_inline () = !cross_module_inline
let set_cross_module_inline b =
cross_module_inline := b


let diagnose = ref false
let get_diagnose () = !diagnose
let set_diagnose b = diagnose := b

let (//) = Filename.concat
(* for a single pass compilation, [output_dir]
can be cached
Expand Down
4 changes: 4 additions & 0 deletions jscomp/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ val cross_module_inline : bool ref
val set_cross_module_inline : bool -> unit
val get_cross_module_inline : unit -> bool

val diagnose : bool ref
val get_diagnose : unit -> bool
val set_diagnose : bool -> unit

val set_env : env -> unit
val cmd_set_module : string -> unit
val default_gen_tds : bool ref
Expand Down
18 changes: 10 additions & 8 deletions jscomp/js_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,23 @@ let add_include_path s =


let buckle_script_flags =
("-js-npm-output-path", Arg.String Js_config.set_npm_package_path,
("-bs-npm-output-path", Arg.String Js_config.set_npm_package_path,
" set npm-output-path: package-name:path, for example `bs-platform:lib/js`")
::
("-js-npm-package-include", Arg.String add_include_path,
("-bs-npm-package-include", Arg.String add_include_path,
" set package names, for example bs-platform " )
:: ("-js-module", Arg.String Js_config.cmd_set_module,
:: ("-bs-module", Arg.String Js_config.cmd_set_module,
" set module system: commonjs (default), amdjs, google:package_name")
:: ("-js-no-builtin-ppx-ml", Arg.Set Js_config.no_builtin_ppx_ml,
:: ("-bs-no-builtin-ppx-ml", Arg.Set Js_config.no_builtin_ppx_ml,
"disable built-in ppx for ml files (internal use)")
:: ("-js-no-builtin-ppx-mli", Arg.Set Js_config.no_builtin_ppx_mli,
:: ("-bs-no-builtin-ppx-mli", Arg.Set Js_config.no_builtin_ppx_mli,
"disable built-in ppx for mli files (internal use)")
:: ("-js-cross-module-opt", Arg.Set Js_config.cross_module_inline,
"enable cross module inlining, default(false)")
:: ("-js-gen-tds", Arg.Set Js_config.default_gen_tds,
:: ("-bs-cross-module-opt", Arg.Set Js_config.cross_module_inline,
"enable cross module inlining(experimental), default(false)")
:: ("-bs-gen-tds", Arg.Set Js_config.default_gen_tds,
" set will generate `.d.ts` file for typescript (experimental)")
:: ("-bs-diagnose", Arg.Set Js_config.diagnose,
" More verbose output")
:: (
let module F = struct
let set r () = r := true
Expand Down
1 change: 1 addition & 0 deletions jscomp/js_pass_flatten_and_mark_dead.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ let mark_dead = object (self)
(** check [camlinternlFormat,box_type] inlined twice
FIXME: seems we have redeclared identifiers
*)
if Js_config.get_diagnose () then
Ext_log.warn __LOC__ "@[%s$%d in %s@]" ident.name ident.stamp name
(* assert false *)
| exception Not_found -> (* First time *)
Expand Down
2 changes: 1 addition & 1 deletion jscomp/runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $(addsuffix .cmj, $(OTHERS)): caml_builtin_exceptions.cmj block.cmj js.cmj
RUNTIME := $(addsuffix .cmj, $(SOURCE_LIST))


COMPFLAGS += $(MODULE_FLAGS) -I ../stdlib -nostdlib -nopervasives -open Pervasives -w -40 -js-npm-output-path $(npm_package_name):lib/js -js-cross-module-opt
COMPFLAGS += $(MODULE_FLAGS) -I ../stdlib -nostdlib -nopervasives -open Pervasives -w -40 -bs-npm-output-path $(npm_package_name):lib/js -bs-cross-module-opt -bs-diagnose



Expand Down
2 changes: 1 addition & 1 deletion jscomp/stdlib/Makefile.shared
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CAMLC=$(CAMLRUN) $(COMPILER)
#COMPFLAGS=-strict-sequence -w +33..39 -g -warn-error A -bin-annot -nostdlib \
# -safe-string
COMPFLAGS= $(MODULE_FLAGS) -strict-sequence -w +33..39 -g -warn-error A -nostdlib \
-safe-string -I ../runtime -js-npm-output-path $(npm_package_name):lib/js -js-no-builtin-ppx-ml -js-no-builtin-ppx-mli -js-cross-module-opt
-safe-string -I ../runtime -bs-npm-output-path $(npm_package_name):lib/js -bs-no-builtin-ppx-ml -bs-no-builtin-ppx-mli -bs-cross-module-opt -bs-diagnose


# OPTCOMPILER=ocamlopt.opt
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SOURCE_LIST := $(shell cat test.mllib)
TESTS := $(addsuffix .cmj, $(SOURCE_LIST) )

COMPFLAGS+= $(MODULE_FLAGS) -w -40
COMPFLAGS+= -js-cross-module-opt -js-npm-output-path $(npm_package_name):lib/js/test/
COMPFLAGS+= -bs-diagnose -bs-cross-module-opt -bs-npm-output-path $(npm_package_name):lib/js/test/


$(TESTS): $(CAMLC)
Expand Down

0 comments on commit 49e9f02

Please sign in to comment.