Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize whitespace for transformed JSX code #970

Merged
merged 1 commit into from
Apr 4, 2014
Merged

Normalize whitespace for transformed JSX code #970

merged 1 commit into from
Apr 4, 2014

Conversation

syranide
Copy link
Contributor

It currently generates "pretty output" as we agreed upon, it respects original indenting all that, newlines are kept as-is. It also puts {} at just after/before the outer ().

There is only one case that I know of currently that produces incorrect output and that is when the attribute name and value are on different lines (see below), I could fix it, but I don't think it's worth the code complexity for something you really shouldn't do, but I could fix it.

I back-tracked on removing trailing spaces after commas, it's not super hard to do, but it's a bit of messy to sort out and I don't find it worthwhile right now. I'll leave it for another PR for now.

I haven't had time to test it extensively yet.

PS. There's a also a bunch of source code lines that got trimmed now that I'm using a better editor (I unintentionally added them with my previous whitespace PR). So that's why there's a bunch of weird "empty" changes below.

<div>
  <div    >  </   div   ><div></div>
  <    div>{0}    A    B    {1}    {2}</div>
  <div>    A    </div>
  <div>
      A
  </div>
  <div

    a

    =

    "a"

    b =
    "b"

    c
    = "c"
  />
  <div a="A" b="B" />
  <div a="A"/>
  <div   a  =     "b"   c = "d"    />
  <div
    a="A"
    b="B"

    c="C"

  />
  <div id="test"
    >


    {0}A{1}B{2}C {    D
  }E


    A


    B


    {1}


    {2}

    awdawdawd
    awdawdawd

  </div>

Produces:

React.DOM.div(null,
  React.DOM.div(null, "  "), React.DOM.div(null),
  React.DOM.div(null, 0, "    A    B    ", 1, "    ", 2),
  React.DOM.div(null, "    A    "),
  React.DOM.div(null,
      "A"
  ),
  React.DOM.div({

    a:



"a",

    b:
"b",

    c:
"c"
  }),
  React.DOM.div({a: "A", b: "B"}),
  React.DOM.div({a: "A"}),
  React.DOM.div({a: "b", c: "d"}),
  React.DOM.div({
    a: "A",
    b: "B",

    c: "C"

  }),
  React.DOM.div({id: "test"
    },


    0, "A", 1, "B", 2, "C ", D,
  "E" + ' ' +


    "A" + ' ' +


    "B",


    1,


    2,

    "awdawdawd" + ' ' +
    "awdawdawd"

  )
)

@zpao
Copy link
Member

zpao commented Mar 7, 2014

Now that our transforms are all synced, want to rebase this? I assume @jeffmo has no qualms with it.

@syranide
Copy link
Contributor Author

syranide commented Mar 7, 2014

@zpao For sure! Rebased.

I discussed quite a bit with @jeffmo before doing this, so he should be fine with the output. But best check to see if he has any feedback.

@jeffmo
Copy link
Contributor

jeffmo commented Mar 11, 2014

Can you rebase this on top of your other two commits that just landed?

@syranide
Copy link
Contributor Author

@jeffmo Rebased, no conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants