官术网_书友最值得收藏!

The bsconfig.json file

The bsconfig.json file is a required file for all BuckleScript projects. Let's explore it:

// This is the configuration file used by BuckleScript's build system bsb. Its documentation lives here: http://bucklescript.github.io/bucklescript/docson/#build-schema.json
// BuckleScript comes with its own parser for bsconfig.json, which is normal JSON, with the extra support of comments and trailing commas.
{
"name": "my-first-app",
"version": "0.1.0",
"sources": {
"dir" : "src",
"subdirs" : true
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
// add your dependencies here. You'd usually install them normally through `npm install my-dependency`. If my-dependency has a bsconfig.json too, then everything will work seamlessly.
],
"warnings": {
"error" : "+101"
},
"namespace": true,
"refmt": 3
}

We'll soon be changing some of these defaults to get more comfortable with BuckleScript's configuration file. Let's first add the following code to Demo.re:

type decision =
| Yes
| No
| Maybe;

let decision = Maybe;

let response =
switch (decision) {
| Yes => "Yes!"
| No => "I'm afraid not."
};

Js.log(response);

As you can see, the switch expression isn't handling all possible cases of decisionRunning npm run build results in the following output:

ninja: Entering directory `lib/bs'
[3/3] Building src/Demo.mlast.d
[1/1] Building src/Demo-MyFirstApp.cmj

Warning number 8
.../Demo.re 9:3-12:3

7 │
8 │ let response =
9 │ switch (decision) {
10 │ | Yes => "Yes!"
11 │ | No => "I'm afraid not."
12 │ };
13 │
14 │ Js.log(response);

You forgot to handle a possible value here, for example:
Maybe
主站蜘蛛池模板: 喀什市| 乐业县| 体育| 邵阳市| 曲松县| 通海县| 纳雍县| 华宁县| 谷城县| 兖州市| 大邑县| 海盐县| 武邑县| 兰州市| 库车县| 咸丰县| 富锦市| 贵德县| 阿坝县| 玉山县| 兰坪| 汝阳县| 沈丘县| 凉山| 五大连池市| 扎赉特旗| 浦东新区| 肇庆市| 工布江达县| 嘉鱼县| 延长县| 子洲县| 江华| 唐河县| 贵港市| 玉龙| 柯坪县| 北京市| 苗栗市| 嘉兴市| 榆树市|