Skip to content

Commit 5dec4a3

Browse files
HerrCai0907Zhenya.Liu
and
Zhenya.Liu
authoredNov 17, 2023
fix: string field with false value in asconfig.js (#2802)
Co-authored-by: Zhenya.Liu <zhenya.liu@partner.bmw.com>
1 parent 41f395a commit 5dec4a3

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed
 

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@
7777
"build": "node scripts/build",
7878
"watch": "node scripts/build --watch",
7979
"coverage": "npx c8 -- npm test",
80-
"test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:asconfig && npm run test:transform",
80+
"test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:asconfig && npm run test:transform && npm run test:cli",
8181
"test:parser": "node --enable-source-maps tests/parser",
8282
"test:compiler": "node --enable-source-maps --no-warnings tests/compiler",
8383
"test:browser": "node --enable-source-maps tests/browser",
8484
"test:asconfig": "cd tests/asconfig && npm run test",
8585
"test:transform": "npm run test:transform:esm && npm run test:transform:cjs",
8686
"test:transform:esm": "node bin/asc tests/compiler/empty --transform ./tests/transform/index.js --noEmit && node bin/asc tests/compiler/empty --transform ./tests/transform/simple.js --noEmit",
8787
"test:transform:cjs": "node bin/asc tests/compiler/empty --transform ./tests/transform/cjs/index.js --noEmit && node bin/asc tests/compiler/empty --transform ./tests/transform/cjs/simple.js --noEmit",
88+
"test:cli": "node tests/cli/options.js",
8889
"asbuild": "npm run asbuild:debug && npm run asbuild:release",
8990
"asbuild:debug": "node bin/asc --config src/asconfig.json --target debug",
9091
"asbuild:release": "node bin/asc --config src/asconfig.json --target release",

‎tests/cli/options.js

+23-16
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import assert from "assert";
22
import * as optionsUtil from "../../util/options.js";
33

44
const config = {
5-
"enable": {
6-
"type": "S",
7-
"mutuallyExclusive": "disable"
5+
enable: {
6+
type: "S",
7+
mutuallyExclusive: "disable",
88
},
9-
"disable": {
10-
"type": "S",
11-
"mutuallyExclusive": "enable"
9+
disable: {
10+
type: "S",
11+
mutuallyExclusive: "enable",
12+
},
13+
other: {
14+
type: "S",
15+
default: ["x"],
16+
},
17+
bool_input_for_string: {
18+
type: "s",
1219
},
13-
"other": {
14-
"type": "S",
15-
"default": ["x"]
16-
}
1720
};
1821

1922
// Present in both should concat
@@ -33,17 +36,21 @@ assert.deepStrictEqual(merged.enable, ["c"]);
3336
assert.deepStrictEqual(merged.disable, ["a", "b"]);
3437

3538
// Populating defaults should work after the fact
36-
optionsUtil.addDefaults(config, merged = {});
39+
optionsUtil.addDefaults(config, (merged = {}));
3740
assert.deepStrictEqual(merged.other, ["x"]);
3841

39-
optionsUtil.addDefaults(config, merged = { other: ["y"] });
42+
optionsUtil.addDefaults(config, (merged = { other: ["y"] }));
4043
assert.deepStrictEqual(merged.other, ["y"]);
4144

45+
// String test
46+
assert.deepStrictEqual(merged.bool_input_for_string, undefined);
47+
merged = optionsUtil.merge(config, {}, { bool_input_for_string: false });
48+
assert.deepStrictEqual(merged.bool_input_for_string, undefined);
49+
merged = optionsUtil.merge(config, {}, { bool_input_for_string: true });
50+
assert.deepStrictEqual(merged.bool_input_for_string, "");
51+
4252
// Complete usage test
43-
let result = optionsUtil.parse([
44-
"--enable", "a",
45-
"--disable", "b",
46-
], config, false);
53+
let result = optionsUtil.parse(["--enable", "a", "--disable", "b"], config, false);
4754

4855
merged = optionsUtil.merge(config, result.options, { enable: ["b", "c"] });
4956
merged = optionsUtil.merge(config, merged, { disable: ["a", "d"] });

‎util/options.js

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ function sanitizeValue(value, type) {
150150
case "f": return Number(value) || 0;
151151
case "s": {
152152
if (value === true) return "";
153+
if (value === false) return null;
153154
return String(value);
154155
}
155156
case "I": {

0 commit comments

Comments
 (0)
Please sign in to comment.