diff --git a/Changes.md b/Changes.md index d1e232d2a9..4e37b3cc5c 100644 --- a/Changes.md +++ b/Changes.md @@ -21,6 +21,8 @@ Unreleased [`NonEscapeCharacter`](https://tc39.es/ecma262/#prod-NonEscapeCharacter) correctly in JS strings (those written using `{js|string here|js}`) ([#469](https://github.com/melange-re/melange/pull/469)) +- [melange]: define `MELANGE` conditional compilation variable + ([#472](https://github.com/melange-re/melange/pull/472)) 0.3.2 2022-11-19 --------------- diff --git a/flake.lock b/flake.lock index ca0a9b54a1..58d0cf09d6 100644 --- a/flake.lock +++ b/flake.lock @@ -91,11 +91,11 @@ "pre-commit-hooks": "pre-commit-hooks" }, "locked": { - "lastModified": 1672661134, - "narHash": "sha256-WqBUyKeiv+jI11ug+qP0OnZ4nngK6eBRVTGHgdzEGvc=", + "lastModified": 1673444666, + "narHash": "sha256-5YE8MyYSRRT1bA78ZCSZCCawch3/nV+WWEddkkN8cbY=", "owner": "nix-community", "repo": "dream2nix", - "rev": "9f6911c78dcb0832f7fcc955e847db1a5a9ce29a", + "rev": "898440d4f576b89018aeeb6b0d8c3dd6baa79917", "type": "github" }, "original": { diff --git a/jscomp/core/bs_conditional_initial.ml b/jscomp/core/bs_conditional_initial.ml index 3c5600f50a..7dab48afe0 100644 --- a/jscomp/core/bs_conditional_initial.ml +++ b/jscomp/core/bs_conditional_initial.ml @@ -66,6 +66,7 @@ let setup_env () = Printexc.record_backtrace true; #endif + Rescript_cpp.replace_directive_bool "MELANGE" true; Rescript_cpp.replace_directive_bool "BS" true; Rescript_cpp.replace_directive_bool "JS" true; Rescript_cpp.replace_directive_string "BS_VERSION" Melange_version.version diff --git a/test/melange-conditional.t b/test/melange-conditional.t new file mode 100644 index 0000000000..3749abe330 --- /dev/null +++ b/test/melange-conditional.t @@ -0,0 +1,21 @@ +Demonstrate the `#if MELANGE` conditional variable + + $ export MELANGELIB="$INSIDE_DUNE/lib/melange" + $ cat > x.ml < let () = + > #if MELANGE then + > Js.log("It's Melange"); + > #else + > Js.log2("Not Melange, type error, not 2 arguments"); + > #end + > EOF + + $ melc x.ml + // Generated by Melange + 'use strict'; + + + console.log("It's Melange"); + + /* Not a pure module */ +