Skip to content

Commit

Permalink
Spaces in doc comments (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfhandl authored Jun 2, 2022
1 parent ed14087 commit ffe4f6e
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion tools/rsdl/rsdl-js/lib/parser.js
Original file line number Diff line number Diff line change
@@ -72,7 +72,11 @@ class MyListener extends rsdlListener {
const docComment = ctx.DOC_COMMENT();
if (docComment) {
const name = `${this.annotatable[0].prefix}@Org.OData.Core.V1.Description`;
const newText = docComment.getText().substring(2).trim();
let newText = docComment.getText().substring(2);
// remove trailing \n
newText = newText.substring(0, newText.length - 1);
// ignore one space immediately following ##, preserve text if there is no space
if (newText.startsWith(" ")) newText = newText.substring(1);
const oldText = this.annotatable[0].target[name];
this.annotatable[0].target[name] = oldText
? `${oldText}\n${newText}`
4 changes: 3 additions & 1 deletion tools/rsdl/rsdl-js/test/parser.test.js
Original file line number Diff line number Diff line change
@@ -406,6 +406,8 @@ describe("Parse correct RSDL", () => {
##
# this is ignored and does not add a line break
## has nice properties
## preserves leading and trailing spaces
##doesn't require a space after ##
## and a cool action
type foo {
## nice property
@@ -437,7 +439,7 @@ describe("Parse correct RSDL", () => {
$Kind: "ComplexType",
$OpenType: true,
"@Org.OData.Core.V1.Description":
"good type\n\nhas nice properties\nand a cool action",
"good type\n\nhas nice properties\n preserves leading and trailing spaces \ndoesn't require a space after ##\nand a cool action",
bar: { "@Org.OData.Core.V1.Description": "nice property" },
qux: {},
},

0 comments on commit ffe4f6e

Please sign in to comment.