From 53c14952baca9d1f20455c4552732dcfed58a60a Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 23 Dec 2024 16:11:52 +0000 Subject: [PATCH] docs: properly parse enum values For enum values that are constructed, not literal integers, we need to parse the inner / implicit expression. For example: ``` GIT_DIFF_REVERSE = (1u << 0) ``` --- script/api-docs/api-generator.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/script/api-docs/api-generator.js b/script/api-docs/api-generator.js index 5204f491f..47c928acf 100755 --- a/script/api-docs/api-generator.js +++ b/script/api-docs/api-generator.js @@ -652,12 +652,23 @@ function parseEnum(location, decl, options) { ensure('enum constant has a name', member.name); const explicitValue = single(member.inner, (attr => attr.kind === 'ConstantExpr')); + const implicitValue = single(member.inner, (attr => attr.kind === 'ImplicitCastExpr')); const commentText = single(member.inner, (attr => attr.kind === 'FullComment')); const commentData = commentText ? parseComment(`enum:${decl.name}:member:${member.name}`, location, commentText, options) : undefined; + let value = undefined; + + if (explicitValue && explicitValue.value) { + value = explicitValue.value; + } else if (implicitValue) { + const innerExplicit = single(implicitValue.inner, (attr => attr.kind === 'ConstantExpr')); + + value = innerExplicit?.value; + } + result.members.push({ name: member.name, - value: explicitValue ? explicitValue.value : undefined, + value: value, ...commentData }); }