Skip to content

Commit af1b449

Browse files
fix: allow for an optional semicolon where there is an optional comma in parseOptionValue (#1571)
* allow for an optional semicolon where there is an optional comma in parseOptionValue * set allowShortCircuit to true to prevent no-unused-expressions error * add test for semicolon Co-authored-by: Alexander Fenster <[email protected]>
1 parent 90afe44 commit af1b449

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

config/eslint.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"no-self-compare": 1,
7373
"no-throw-literal": 1,
7474
"no-unmodified-loop-condition": 1,
75-
"no-unused-expressions": 1,
75+
"no-unused-expressions": ["error", { "allowShortCircuit": true }],
7676
"no-useless-call": 1,
7777
"no-useless-concat": 1,
7878
"no-useless-escape": 1,

src/parse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ function parse(source, root, options) {
611611
if (prevValue)
612612
value = [].concat(prevValue).concat(value);
613613
result[propName] = value;
614-
skip(",", true);
614+
skip(",", true) || skip(";", true);
615615
}
616616
return result;
617617
}

tests/comp_options-textformat.js

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ message Test {\
1515
string value = 1 [(my_options) = { a: \"foo\" b: \"bar\" }];\
1616
string value2 = 2 [(my_options) = { a: \"foo\" b { c: \"bar\" } }];\
1717
string value3 = 3 [(my_options) = { a: \"foo\", b: \"bar\" }];\
18+
string value4 = 4 [(my_options) = { a: \"foo\"; b: \"bar\" }];\
1819
}";
1920

2021
tape.test("options in textformat", function(test) {
@@ -23,5 +24,6 @@ tape.test("options in textformat", function(test) {
2324
test.same(Test.fields.value.options, { "(my_options).a": "foo", "(my_options).b": "bar" }, "should parse correctly");
2425
test.same(Test.fields.value2.options, { "(my_options).a": "foo", "(my_options).b.c": "bar" }, "should parse correctly when nested");
2526
test.same(Test.fields.value3.options, { "(my_options).a": "foo", "(my_options).b": "bar" }, "should parse correctly when comma-separated");
27+
test.same(Test.fields.value4.options, { "(my_options).a": "foo", "(my_options).b": "bar" }, "should parse correctly when semicolon-separated");
2628
test.end();
2729
});

0 commit comments

Comments
 (0)