Giter Club home page Giter Club logo

Comments (3)

JoeStanton avatar JoeStanton commented on August 16, 2024

Hey - you're right that A) this isn't supported, and B) it wouldn't be difficult to implement.

See here: https://github.com/JoeStanton/babel-transform-js-to-jsx/blob/master/index.js#L32

We currently visit any CallExpression, i.e. statements looking like div({ prop1: "a" }, "blah") but don't handle the case where the call is actually a MemberExpression eg. React.DOM.div({ prop1: "a" }, "blah").

You can inspect this in more detail here: https://astexplorer.net/#/WgqAsKBUcv

If you can think of a robust way to check for React.DOM.X MemberExpressions (similar to L34), then this can be easily supported 👍

from babel-transform-js-to-jsx.

cdaringe avatar cdaringe commented on August 16, 2024

Hmm, very interesting. I think I somewhat see what's going on here. Perhaps I can fiddle on this sometime soon. I'm assuming that a dirty hack would be to add a MemberExpression key to your existing visitor: { ... } set, and sniff directly for the two identifiers, React & DOM, then call into your existing exit fn? It would be nice to rather detect if React.DOM had been imported/tokenized and just check if the MemberExpression === that reference, and if there is yet another field Identifier tacked onto it.

from babel-transform-js-to-jsx.

JoeStanton avatar JoeStanton commented on August 16, 2024

Yes - the former is simple (in fact even simpler than you state), you'd just modify the conditional to peek inside any MemberExpression contained within the CallExpression and check if it's constituent elements are React and DOM, and if so, continue as normal with the transform.

However - making this work with all of the variations/derivations of React.DOM is non-trivial.
eg. import {DOM} from "react" and then using DOM.div would also prove problematic. Don't have a solution to this off the top of my head.

I'm not really sure if its possible to check the reference equality of a token because it hasn't actually been 'executed' at that point.

from babel-transform-js-to-jsx.

Related Issues (13)

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.