fix(javascript): honor computed keys when naming callables, exports, requests and options (#536)

This commit is contained in:
morluto
2026-10-05 15:52:06 +08:00
committed by GitHub
parent d40502aa3b
commit 4c8dc39f43
6 changed files with 84 additions and 9 deletions
+13 -1
View File
@@ -296,12 +296,24 @@ const calleeNameAt = (node: t.Node): string => {
if (t.isImport(node)) return "import";
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
const object = t.isNode(node.object) ? calleeNameAt(node.object) : "";
const property = propertyName(node.property);
// A dynamic key commits no name: `target[method]()` must not be reported as
// `target.method`, which would fabricate a runtime call shape.
const property = memberPropertyName(node);
return object === "" ? property : `${object}.${property}`;
}
return "";
};
/** Read a member property only when its syntax commits an exact name. */
const memberPropertyName = (
node: t.MemberExpression | t.OptionalMemberExpression,
): string =>
node.computed &&
!t.isStringLiteral(node.property) &&
!t.isNumericLiteral(node.property)
? `[computed@${String(node.property.start ?? -1)}]`
: propertyName(node.property);
/** Return a string literal value without evaluating an expression. */
export const stringValue = (
node: t.Node | null | undefined,