Skip to content

Conversation

elicwhite
Copy link
Contributor

Based on #10

This

React.createElement( 'div', null, a, ' ', a ); 

was getting transformed to

<div>{a}" "{a}</div>; 

Now there are no unnecessary quotes.

However, I'm having a problem.
This

React.createElement( 'div', null, ' lala ' ); 

is being converted to

<div>lala</div>; 

Losing the padding spaces. It seems like j.jsxText(' foo '); gets output as foo. literal has the same issue. So how can I make that case work?

@cpojer
Copy link
Member

cpojer commented Nov 9, 2015

Oh this kinda sucks. It might require you to look back/look ahead?

@elicwhite
Copy link
Contributor Author

I'm not sure what you mean by looking back or looking ahead, but it seems like looking at surrounding nodes wouldn't solve the problem of jsxText / literal trimming their input.

@elicwhite
Copy link
Contributor Author

I just removed the test for the padded string. It was conflating the other fix of <div>{a}" "{a}</div>; getting output. Let's tackle that one separately.

@cpojer
Copy link
Member

cpojer commented Nov 9, 2015

Oh, sorry, I thought fixing the first thing would break the second and vice-versa. So you are saying that j.jsxText(' foo ') always prints as foo instead of <space>foo<space>?

@elicwhite
Copy link
Contributor Author

Yes, that is what I'm saying. :)

@cpojer
Copy link
Member

cpojer commented Nov 9, 2015

You might have to take a look into this: https://github.com/benjamn/recast/blob/master/lib/printer.js#L1089 and how fromString works.

@elicwhite
Copy link
Contributor Author

Let's get this one merged and I'll take a look at that.

@cpojer
Copy link
Member

cpojer commented Nov 9, 2015

sure!

cpojer added a commit that referenced this pull request Nov 9, 2015
create-element-to-jsx-children: Convert mixed strings to JSXText instead of Literal
@cpojer cpojer merged commit f6b11a3 into reactjs:master Nov 9, 2015
@elicwhite elicwhite deleted the child-strings branch November 9, 2015 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants