Skip to content

Commit

Permalink
Avoid adding empty trailing comments to oneof unions
Browse files Browse the repository at this point in the history
stephenh/ts-proto#1140

Signed-off-by: Andrew Haines <[email protected]>
  • Loading branch information
haines committed Nov 25, 2024
1 parent b76defd commit aaf3517
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,10 @@
"tsx": "4.19.2",
"typescript": "5.6.3",
"typescript-eslint": "8.15.0"
},
"pnpm": {
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
}
}
}
22 changes: 22 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/build/src/main.js b/build/src/main.js
index 3e03249d11bae4b1ccc9000e0f4e41f1e4393f26..a6e519f26db63304ab4f29781261d2736d986382 100644
--- a/build/src/main.js
+++ b/build/src/main.js
@@ -851,7 +851,7 @@ function generateOneofProperty(ctx, messageDesc, oneofIndex, sourceInfo) {
let fieldComments = [];
(0, utils_1.maybeAddComment)(options, fieldInfo, fieldComments);
const combinedComments = fieldComments.join("\n");
- return (0, ts_poet_1.code) `| // \n ${combinedComments} { ${mbReadonly}$case: '${fieldName}', ${mbReadonly}${valueName}: ${typeName} }`;
+ return (0, ts_poet_1.code) `|${combinedComments ? " // " : ""}\n ${combinedComments} { ${mbReadonly}$case: '${fieldName}', ${mbReadonly}${valueName}: ${typeName} }`;
}));
const name = (0, case_1.maybeSnakeToCamel)(messageDesc.oneofDecl[oneofIndex].name, options);
return (0, ts_poet_1.joinCode)([...outerComments, (0, ts_poet_1.code) `${mbReadonly}${name}?:`, unionType, (0, ts_poet_1.code) `| ${(0, utils_1.nullOrUndefined)(options)},`], {
@@ -1155,7 +1155,7 @@ function generateDecode(ctx, fullName, messageDesc) {
}
chunks.push((0, ts_poet_1.code) `
const buf = reader.skip(tag & 7);
-
+
${unknownFieldsInitializerSnippet}
const list = message._unknownFields${maybeNonNullAssertion}[tag];

9 changes: 7 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aaf3517

Please sign in to comment.