Skip to content

Commit

Permalink
fix: allow for an optional semicolon where there is an optional comma…
Browse files Browse the repository at this point in the history
… 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 <fenster@google.com>
  • Loading branch information
jeffory-orrok and alexander-fenster committed Apr 29, 2021
1 parent 90afe44 commit af1b449
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/eslint.json
Expand Up @@ -72,7 +72,7 @@
"no-self-compare": 1,
"no-throw-literal": 1,
"no-unmodified-loop-condition": 1,
"no-unused-expressions": 1,
"no-unused-expressions": ["error", { "allowShortCircuit": true }],
"no-useless-call": 1,
"no-useless-concat": 1,
"no-useless-escape": 1,
Expand Down
2 changes: 1 addition & 1 deletion src/parse.js
Expand Up @@ -611,7 +611,7 @@ function parse(source, root, options) {
if (prevValue)
value = [].concat(prevValue).concat(value);
result[propName] = value;
skip(",", true);
skip(",", true) || skip(";", true);
}
return result;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/comp_options-textformat.js
Expand Up @@ -15,6 +15,7 @@ message Test {\
string value = 1 [(my_options) = { a: \"foo\" b: \"bar\" }];\
string value2 = 2 [(my_options) = { a: \"foo\" b { c: \"bar\" } }];\
string value3 = 3 [(my_options) = { a: \"foo\", b: \"bar\" }];\
string value4 = 4 [(my_options) = { a: \"foo\"; b: \"bar\" }];\
}";

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

0 comments on commit af1b449

Please sign in to comment.