Skip to content

displayName is added to regular JS objects #19

@iMoses-Apiiro

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'

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