Skip to content

displayName and componentId not added to withConfig argument object if a function is used to return the object #415

@TH-VF

Description

@TH-VF

When using an object literal the plugin correctly appends the displayName and componentId properties to it.

Example with object literal (works correctly):

Input:

styled.div.withConfig({ shouldForwardProp: () => true })

Output:

styled.div.withConfig({
  shouldForwardProp: () => true,
  displayName: "FooStyled",
  componentId: "sc-1t5leix-0"
})

Example with function call (does not add the properties):

Input:

const getConfig = () => ({ shouldForwardProp: () => true });
styled.div.withConfig(getConfig())

Output:

const getConfig = () => ({ shouldForwardProp: () => true });
styled.div.withConfig(getConfig())

As you can see the displayName and componentId were not added in the last example, because it is using a function call to return the argument value.

It would be good to merge the result of function calls like this:

styled.div.withConfig({
  ...getConfig(),
  displayName: "FooStyled",
  componentId: "sc-1t5leix-0"
});

Or if that is too complex, at least print a warning, that some code could not be transformed.

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