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

Improve support for xml parts of jsx (React) => spaces, spread attributes and nested objects break the process #646

Closed
fabien-h opened this issue Mar 12, 2015 · 7 comments
Milestone

Comments

@fabien-h
Copy link

When working on a .jsx file, we have both javascript and xml in the same file. So when I try to beautify the js, it sometimes break all the xml. Would it be a way to ignore parts of the code ? Or to beautify xml as xml and js as js ?

By the way, why are they not considered as e4x XML literals ? It works for most cases, but not always.

For instance, this code works :

let a = React.createClass( {
    render() {
        return (
            <p className='b'>
                <span>c</span>
            </p>
        );
    }
} );

But if you add a space around the =, like that : <p className = 'b'>, it transforms it a very strange way :

let a = React.createClass( {
    render() {
        return ( < p className = 'b' >
            <span>c</span> < /p>
        );
    }
} );

And it breaks the syntax highlighter and the transpiler (babel).

The spread attribute {...this.something} is not supported => http://facebook.github.io/react/docs/jsx-spread.html#spread-attributes

let CheckLink = React.createClass({
    render() {
        return <a {...this.props}>{'√ '}{this.props.children}</a>;
    }
});

Is transformed into :

let CheckLink = React.createClass( {
    render() {
        return <a {...this.props
        } > {
            '√ '
        } {
            this.props.children
        } < /a>;
    }
} );

The nested objects are not supported

let CheckLink = React.createClass({
    render() {
        return <a style={{display: 'block'}}>{'√ '}{this.props.children}</a>;
    }
});

It transformed into :

let CheckLink = React.createClass( {
    render() {
        return <a style = {
            {
                display: 'block'
            }
        } > {
            '√ '
        } {
            this.props.children
        } < /a>;
    }
} );

They both should keep their initial form

@fabien-h
Copy link
Author

(oh, there is something to enable it in the configuration file :x )

=> "e4x": true,

@bitwiseman
Copy link
Member

As you say works in many cases, but not all. Feel free to file specific bugs as you see them.

@fabien-h
Copy link
Author

For instance, this code works :

let a = React.createClass( {
    render() {
        return (
            <p className='b'>
                <span>c</span>
            </p>
        );
    }
} );

But if you add a space around the =, like that : <p className = 'b'>, it tranfsforms it a very strange way :

let a = React.createClass( {
    render() {
        return ( < p className = 'b' >
            <span>c</span> < /p>
        );
    }
} );

And it breaks the syntax highlighter and the transpiler (babel).

@bitwiseman
Copy link
Member

Please file this a s new issue. That looks like something easily solvable.

@fabien-h fabien-h reopened this Mar 12, 2015
@fabien-h fabien-h changed the title special support for jsx (React) Improve support for xml parts of jsx (React) => spaces break the process Mar 12, 2015
@fabien-h
Copy link
Author

Ok, I reopened the issue and changed the title and description a little bit.

@bitwiseman
Copy link
Member

Cool, that works.

@fabien-h fabien-h changed the title Improve support for xml parts of jsx (React) => spaces break the process Improve support for xml parts of jsx (React) => spaces, spread attributes and nested objects break the process Mar 12, 2015
@bitwiseman bitwiseman added this to the v1.6.0 milestone Mar 12, 2015
@fabien-h
Copy link
Author

Quick an clean fix ! Thanks a lot :)

@bitwiseman bitwiseman modified the milestones: v1.6.0, v1.5.6 May 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants