Skip to content

[jss-to-styled] codemod fails when an export type, export class, or export function statement is present #28317

@jedwards1211

Description

@jedwards1211
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

It would be better to write the codemods in TS

The TS types would have caught this issue before it happened.

Current Behavior 😯

If I run npx @mui/codemod v5.0.0/jss-to-styled on the following code, it errors out with

Transformation error (Cannot read property '0' of undefined)
TypeError: Cannot read property '0' of undefined
    at NodePath.<anonymous> (/Users/andy/github/clarity/node_modules/@mui/codemod/node/v5.0.0/jss-to-styled.js:51:22)
import * as React from 'react'
import {makeStyles} from '@material-ui/core/styles'

export function test() {}

const useStyles = makeStyles((theme) => ({
  root: {
    position: 'relative',
    width: '100%',
    height: '100%',
    display: 'flex',
  },
}))

export default function MyComp(props): React.Node {
  const classes = useStyles(props)
  return <div className={classes.root} />
}

Expected Behavior 🤔

Codemod succeeds

Steps to Reproduce 🕹

Steps:

  1. Save the above code to temp.js
  2. Run npx @mui/codemod v5.0.0/jss-to-styled temp.js

Context 🔦

Your Environment 🌎

`npx @mui/envinfo`
  System:
    OS: macOS 11.5.2
  Binaries:
    Node: 12.16.0 - ~/.nvm/versions/node/v12.16.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.11 - ~/github/clarity/node_modules/.bin/npm
  Browsers:
    Chrome: 93.0.4577.63
    Edge: Not Found
    Firefox: 82.0.3
    Safari: 14.1.2
  npmPackages:
    @mui/codemod: ^5.0.0-rc.0 => 5.0.0-rc.0 
    @types/react:  17.0.3 
    react: ^17.0.0 => 17.0.2 
    react-dom: ^17.0.0 => 17.0.2 
    typescript: ^3.9.6 => 3.9.9 

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: codemodSpecific to codemod.type: bugIt doesn't behave as expected.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions