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

No dependencies are detected in files using optional chaining #291

Closed
haggholm opened this issue Sep 26, 2018 · 4 comments
Closed

No dependencies are detected in files using optional chaining #291

haggholm opened this issue Sep 26, 2018 · 4 comments

Comments

@haggholm
Copy link
Contributor

Bug Description

If a file contains the optional chaining proposal object?.optionalProperty, parsing appears to fail and no dependencies are detected in the file.

Code snippets

Where the dependency is used:

import _ from 'lodash';

export default function foo(ob) {
    return _.identity(ob?.x);
}

Where the dependency is listed in package.json:

The dependency is not listed in package.json (in my sample scenario, it doesn’t contain any dependencies at all).

Expected outcome:

Missing dependencies
* lodash

Actual outcome: No output/nothing detected.

Versions

  • node -v: v10.4.0
  • npm -v: 6.1.0
  • depcheck -v: No output, it doesn’t seem to recognise the -v flag. However, the version is 0.6.11.

Extra info

depcheck --json

{
  "dependencies": [],
  "devDependencies": [],
  "missing": {},
  "using": {},
  "invalidFiles": {
    "/client/tmp/test.jsx": "SyntaxError: Unexpected token (4:25)\n    at Parser.pp$5.raise (/client/tmp/node_modules/babylon/lib/index.js:4454:13)\n    at Parser.pp.unexpected (/client/tmp/node_modules/babylon/lib/index.js:1761:8)\n    at Parser.pp$3.parseExprAtom (/client/tmp/node_modules/babylon/lib/index.js:3750:12)\n    at Parser.parseExprAtom (/client/tmp/node_modules/babylon/lib/index.js:7238:22)\n    at Parser.pp$3.parseExprSubscripts (/client/tmp/node_modules/babylon/lib/index.js:3494:19)\n    at Parser.pp$3.parseMaybeUnary (/client/tmp/node_modules/babylon/lib/index.js:3474:19)\n    at Parser.pp$3.parseExprOps (/client/tmp/node_modules/babylon/lib/index.js:3404:19)\n    at Parser.pp$3.parseMaybeConditional (/client/tmp/node_modules/babylon/lib/index.js:3381:19)\n    at Parser.pp$3.parseMaybeAssign (/client/tmp/node_modules/babylon/lib/index.js:3344:19)\n    at Parser.parseMaybeAssign (/client/tmp/node_modules/babylon/lib/index.js:6474:20)"
  },
  "invalidDirs": {}
}

I tried to add 'optionalChaining' to the list of plugins in depcheck/dist/jsx.js', but this appeared to have no effect.

@mnkhouri
Copy link
Member

Thanks for the report @haggholm. I did a bit of digging around that plugin:

Our current parser is Babylon@6.1.21, which does not support the 'optionalChaining' plugin per the documentation for 6.26.3 (so it's definitely not in our 6.1.21)

As of Babel@7, Babylon was renamed to @babel/parser, which does support the optionalChaining plugin, according to documention for @babel/parser@7.1.0

So the solution is for us to update babylon to @babel/parser. I'll try to get to this this weekend, but if anyone else feels like tackling it in the meantime, a PR would be greatly appreciated! I would guess it's a drop-in replacement, or minimal changes

@LinusU
Copy link
Member

LinusU commented Sep 27, 2018

So the solution is for us to update babylon to @babel/parser

Would be awesome to get this in 👏

@haggholm
Copy link
Contributor Author

@mnkhouri If there weren’t so many things broken all over the place by the Babel transition—and if the Babel 7 transition weren’t compelled by React Native—I’d at least like to think of myself that I’d whip up a PR. But in actual reality, there’s no realistic chance by the weekend. :P

@rumpl
Copy link
Member

rumpl commented Jan 26, 2019

Fixed by #307

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 a pull request may close this issue.

4 participants