Skip to content
This repository was archived by the owner on Feb 4, 2026. It is now read-only.
This repository was archived by the owner on Feb 4, 2026. It is now read-only.

displayName is added to regular JS objects #19

Description

@iMoses-Apiiro

I have a large map in my code that looks something like this:

export const MANAGE_ACTIONS = {
  actionType: {
    nameFunc: () => {},
    iconFunc: () => {},
  },
 ...
};

which I elsewhere use to fetch the relevant functions per actionType so I'm expecting the values to all be objects,
and now all of a sudden I'm getting:

MANAGE_ACTIONS.displayName === 'MANAGE_ACTIONS' // true

After a short debugging this seems to be the problem:

const parentAncestor = ancestors[ancestors.length - 2]

if (parentAncestor && ['ReturnStatement', 'ArrowFunctionExpression'].includes(parentAncestor.type)) {
  // ArrowFunctionExpression is present when no Babel plugins are used when transforming JSX

  const variableDeclaratorIdx = ancestors.findIndex(ancestor => ancestor.type === 'VariableDeclarator')

  if (variableDeclaratorIdx != -1) {
    const variableDeclarator = ancestors[variableDeclaratorIdx]
    addDisplayName(parser, variableDeclarator)
  }
}

the assumption here about arrow functions is a little too generic :)

Expected
if nameFunc returns JSX then MANAGE_ACTIONS.actionType.nameFunc.displayName === 'nameFunc'

Actual
MANAGE_ACTIONS.displayName === 'MANAGE_ACTIONS'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions