Giter Site home page Giter Site logo

Comments (6)

vutran avatar vutran commented on June 15, 2024

@developit Thanks for feedback. I started this as an experiment to learn more about AST/codemods and glad that you found it.

Your ES class transforms looks a lot cleaner than what I had. I actually just pushed up an update which also preserved the JSX in the render() call and converted the createClass to a pure function. Your ES classes look a lot better. Did you want to submit a PR for this?

from preact-codemod.

developit avatar developit commented on June 15, 2024

Could do, though I think the pure function is a nicer approach. I was thinking maybe the codemod could check if a createClass() component was pure or impure and choose the output type (pure function vs class) appropriately... should be as simple as checking for the existence of properties other than render(), defaultProps and displayName.

from preact-codemod.

vutran avatar vutran commented on June 15, 2024

@developit I've just merged in this functionality based on your example with some minor adjustments which is moving the literals inside the ES6 constructor where necessary.

See here: https://astexplorer.net/#/M4CGKhVyp0

from preact-codemod.

developit avatar developit commented on June 15, 2024

@vutran looks good! How come you moved the literals into the constructor? That's already how they work in ES6: https://goo.gl/imGiI5

Work either way though! One thing to watch out for: it might be worth passing (props, context) to super() so that this.props and this.context are defined in case they are referenced prior to the constructor being finished evaluation. (example: http://astexplorer.net/#/Pcp2Q5NFLq/11)

from preact-codemod.

vutran avatar vutran commented on June 15, 2024

@developit Apologies been really busy at work and another app at the moment. I've just deployed the updated constructor() and super() calls.

from preact-codemod.

developit avatar developit commented on June 15, 2024

Awesome!

from preact-codemod.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.