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

[ GENERAL ][ BUGFIX ][ jest/preprocessor.js ] - Invalid use of destructuring #20178

Closed
wants to merge 2 commits into from

Conversation

umairda
Copy link

@umairda umairda commented Jul 12, 2018

Test Plan:

I had the same issues running tests as mentioned in: #19859

I followed the suggestions but ran into another error:

  ● Test suite failed to run

    /Users/umair/projects/my-project/node_modules/react-native/jest/preprocessor.js:49
              {sourceType: 'script', ...nodeOptions, ast: false},
                                     ^^^

    SyntaxError: Unexpected token ...

The preprocessor.js code in question is:

      // node specific transforms only
      return babelTransformSync(
        src,
        Object.assign(
          {filename: file},
          {sourceType: 'script', ...nodeOptions, ast: false},
        ),
      ).code;

Specifically line 46: {sourceType: 'script', ...nodeOptions, ast: false}, is an invalid use of object destructuring and since this object is part of an Object.assign statement I simply broke the constituents up into arguments as follows:

        Object.assign(
          {filename: file},
          {sourceType: 'script'},
          nodeOptions, 
          {ast: false}
        ),

Release Notes:

[GENERAL][BUGFIX][jest/preprocessor.js] - fixes invalid use of object destructuring in preprocessor.js

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 12, 2018
@elicwhite
Copy link
Member

What version of node are you running? My understanding is that the ... there is reasonable.

@umairda
Copy link
Author

umairda commented Jul 13, 2018

v8.0.0

It looks like I have to pass the --harmony flag when running node to enable object destructuring

But the code in general is strange. If destructuring is being used then why is Object.assign also used? It seems like you could write the second argument simply as:

{
   filename:file,
   sourceType:'script',
   ...nodeOptions,
   ast:false
}

@elicwhite
Copy link
Member

It looks like node rest/spread syntax started working without the harmony flag in 8.3.0. This should work if you update to that.

@hramos, we should make sure our minimum supported version is set to 8.3.0.

————
I agree, this function call is strange and is unnecessarily using Object.assign and spread. If you change this PR to just be the spread version, we would merge this in.

@umairda
Copy link
Author

umairda commented Jul 13, 2018

You are right. I updated to node v8.3.0 and it works.

I went ahead and updated the pr so that portion of the code uses destructuring only and got rid of the Object.assign.

I re-ran all my tests and they work fine whereas before they were complaining about the use of the spread operator.

@janicduplessis
Copy link
Contributor

janicduplessis commented Jul 15, 2018

Maybe we should update https://github.com/facebook/react-native/blob/master/local-cli/server/checkNodeVersion.js#L17 to 8.3 then. There might be some other mentions in the doc too.

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Jul 16, 2018
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheSavior is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

hramos pushed a commit to hramos/react-native that referenced this pull request Jul 16, 2018
Summary: Pull Request resolved: facebook#20178

Differential Revision: D8860733

Pulled By: TheSavior

fbshipit-source-id: ec4aa3050755652106dec9ea245394314c862e97
@hramos
Copy link
Contributor

hramos commented Jul 16, 2018

#20236

@elicwhite
Copy link
Member

It looks like the commit didn't auto close this PR: 9d5bd50

@elicwhite elicwhite closed this Jul 16, 2018
facebook-github-bot pushed a commit that referenced this pull request Jul 18, 2018
Summary:
Node rest/spread syntax started working without the harmony flag in 8.3 (#20178 (comment)).

Release Notes:
[GENERAL] [BREAKING] [Node] - Bump minimum req. Node version to 8.3
Pull Request resolved: #20236

Differential Revision: D8876357

Pulled By: hramos

fbshipit-source-id: 1f5f791ef318e70c6be8b23d887a1d650a68e594
facebook-github-bot pushed a commit that referenced this pull request Aug 13, 2018
Summary: Adds missing comma, following up on #20178. Thanks to LinusU for pointing out the error.

Reviewed By: TheSavior

Differential Revision: D9242887

fbshipit-source-id: 4b547396722d0e37dc5c8eb3439b9a441c3c0ac2
kelset pushed a commit that referenced this pull request Aug 13, 2018
Summary: Adds missing comma, following up on #20178. Thanks to LinusU for pointing out the error.

Reviewed By: TheSavior

Differential Revision: D9242887

fbshipit-source-id: 4b547396722d0e37dc5c8eb3439b9a441c3c0ac2
grabbou pushed a commit to react-native-community/cli that referenced this pull request Sep 26, 2018
Summary:
Node rest/spread syntax started working without the harmony flag in 8.3 (facebook/react-native#20178 (comment)).

Release Notes:
[GENERAL] [BREAKING] [Node] - Bump minimum req. Node version to 8.3
Pull Request resolved: facebook/react-native#20236

Differential Revision: D8876357

Pulled By: hramos

fbshipit-source-id: 1f5f791ef318e70c6be8b23d887a1d650a68e594
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants