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

Space added to "from++" due to ES6 keyword #858

Closed
lzilioli opened this issue Jan 29, 2016 · 5 comments
Closed

Space added to "from++" due to ES6 keyword #858

lzilioli opened this issue Jan 29, 2016 · 5 comments
Milestone

Comments

@lzilioli
Copy link

After the 1.6.0 update, jsbeautifier wants to make the following change to my code. It wants to change i++ to i ++. Is there a way to prevent this?

@bitwiseman
Copy link
Member

Could you provide an example with more context? I have tests for i++ (https://github.com/beautify-web/js-beautify/blob/master/test/data/javascript/tests.js#L1726), so it is isn't as simple as that.

@lzilioli
Copy link
Author

This is our .jsbeautifyrc, if that helps. We are using grunt-jsbeautifier

{
    "js": {
        "jslint_happy": true,
        "indent_with_tabs": true,
        "space_in_paren": true
    }
}

Our package.json:

$ cat package.json | grep beaut
45:    "grunt-jsbeautifier": "^0.2.8",
58:    "js-beautify": "^1.5.7",

npm install output:

example.js

function resizeWindow( from, to ) {
    while ( from !== to ) {
        getWidthStub.returns( from );
        $( window ).trigger( 'resize' );

        if ( from < to ) {
            from++;
        } else {
            from--;
        }
    }
}

after running grunt jsbeautifier:

function resizeWindow( from, to ) {
    while ( from !== to ) {
        getWidthStub.returns( from );
        $( window ).trigger( 'resize' );

        if ( from < to ) {
            from ++;
        } else {
            from --;
        }
    }
}

Curiously, I do not see the same behavior if example.js contains

var i = 0;
i++;

@lzilioli
Copy link
Author

After further testing, the following reduced example.js also exhibits the same issue:

if ( from < to ) {
    from++;
} else {
    from--;
}

@lzilioli
Copy link
Author

After further digging, we have determined that this is happening likely because from is a reserved word es6, which it looks like the release aims to support. If I rename the i variable in the small test case from i to from, I see the same issue. I think we can resolve this issue on our end by renaming our variable to something else, however this may still be something you want to address in the package, as it seems from, even under the es6 spec is still a valid variable name.

@bitwiseman bitwiseman changed the title v1.6.0 Adding Space after Variable Incrementation Space added to "from++" due to ES6 keyword in v1.6.0 Jan 29, 2016
@bitwiseman
Copy link
Member

Yes, thank you for drilling in on this. Yes, from should only be treated as a keyword inside an import statement.

@bitwiseman bitwiseman modified the milestones: 2.0.0, 1.6.1 Jan 29, 2016
@bitwiseman bitwiseman changed the title Space added to "from++" due to ES6 keyword in v1.6.0 Space added to "from++" due to ES6 keyword Jan 30, 2016
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