Coder Social home page Coder Social logo

Comments (13)

flying-sheep avatar flying-sheep commented on June 23, 2024

Huge thanks for you for this plugin!

i’m glad it’s useful for you!

I found just one drawback. Plugin pose all JSX tags just in one line. How can I avoid it?

i don’t know, but maybe we can find out together.

do you know how babel/ESTree represents whitespace?

from babel-plugin-transform-react-createelement-to-jsx.

asiniy avatar asiniy commented on June 23, 2024

Unfortunately, nope.

from babel-plugin-transform-react-createelement-to-jsx.

flying-sheep avatar flying-sheep commented on June 23, 2024

so you say

<ol>
    <li>a</li>
    <li>b</li>
</ol>

gets converted to

<ol><li>a</li><li>b</li></ol>

or what?

from babel-plugin-transform-react-createelement-to-jsx.

asiniy avatar asiniy commented on June 23, 2024

I mean

React.createElement("ul", React.createElement("li"))

converts to

<ul><li></li></ul>

not

<ul>
  <li></li>
</ul>

from babel-plugin-transform-react-createelement-to-jsx.

flying-sheep avatar flying-sheep commented on June 23, 2024

well, that’s correct, no?

React.createElement("ul",
    React.createElement("li")
)

should convert to

<ul>
  <li></li>
</ul>

or similar.

from babel-plugin-transform-react-createelement-to-jsx.

foxyblocks avatar foxyblocks commented on June 23, 2024

It's not just JSX. I noticed that it did this for simple arrays also. I tried with a simple example:

Before:

let my_list = [
  "one",
  "two",
  "three",
  "four"
];

after:

let my_list = ["one", "two", "three", "four"];

from babel-plugin-transform-react-createelement-to-jsx.

flying-sheep avatar flying-sheep commented on June 23, 2024

huh? that’s really weird, as i only replace nodes that pass all the checks (i.e. are React.createElement calls, etc.)

is what you observe inside of such an expression or will a file containing only what you showed me be transformed like that?

from babel-plugin-transform-react-createelement-to-jsx.

foxyblocks avatar foxyblocks commented on June 23, 2024

Only what I showed you. It's a file containing only an array

from babel-plugin-transform-react-createelement-to-jsx.

foxyblocks avatar foxyblocks commented on June 23, 2024

Adding the following to the test file will reproduce this:

it('should ignore regular javascript arrays', () => {
    let source = `
      let list = [
        "one",
        "two",
        "three",
      ]
    `
  expect(source).to.convertTo(source)
})

results in:

  1) createElement-to-JSX should ignore regular javascript arrays:

      Code “
      let list = [
        "one",
        "two",
        "three",
      ]
    ” converts wrongly
      + expected - actual


      -let list = ["one", "two", "three"];
      +      let list = [
      +        "one",
      +        "two",
      +        "three",
      +      ]
      +

      at Assertion.<anonymous> (test/chai-convert-to.js:62:41)
      at Assertion.ctx.(anonymous function) [as convertTo] (node_modules/chai/lib/chai/utils/addMethod.js:41:25)
      at Context.<anonymous> (test/index.js:72:21)

I'll try to debug further, to see if I can't get to the bottom of it.

from babel-plugin-transform-react-createelement-to-jsx.

foxyblocks avatar foxyblocks commented on June 23, 2024

Further investigation shows that this is a problem with babel itself. I can reproduce it by running babel without any plugin options. Using the babel --retain-lines flag can mostly mitigate it, but not perfectly:

before

let foo = [
  'one',
  'two',
  'three'
];

after

let foo = [
'one',
'two',
'three'];

from babel-plugin-transform-react-createelement-to-jsx.

flying-sheep avatar flying-sheep commented on June 23, 2024

OK, so it’s not actually a bug and i can close it, right?

from babel-plugin-transform-react-createelement-to-jsx.

foxyblocks avatar foxyblocks commented on June 23, 2024

I should think so

from babel-plugin-transform-react-createelement-to-jsx.

flying-sheep avatar flying-sheep commented on June 23, 2024

OK, thanks for investigating!

from babel-plugin-transform-react-createelement-to-jsx.

Related Issues (7)

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.