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 dependency extractor #7385

Merged
merged 6 commits into from Nov 19, 2018

Conversation

rubennorte
Copy link
Contributor

Summary

This refactors the default dependency extractor to make regular expressions less error-prone (building them with a custom DSL) and fixes some bugs:

  1. require("foo",) (notice the trailing comma), which is completely valid, wasn't detected.
  2. import typeof {foo} from 'foo' was detected as a dependency, when it should've been ignored like import type {foo} from 'foo';.

It also uses negative lookbehind when it's supported.

Performance-wise, it's faster than the previous version as it removes unnecessary capture groups (tested internally at Facebook).

Test plan

Updated unit tests.

@SimenB
Copy link
Member

SimenB commented Nov 19, 2018

Tests seems to be failing on Node 6?

@rubennorte
Copy link
Contributor Author

Tests seems to be failing on Node 6?

There's a case that was failing before:

foo.require.requireActual('foo');

I used a negative lookbehind to fix it, but they're only supported in Node 9+. I disabled the test cases that don't work with Node 6 to make CI pass. Once we drop support for Node <10 we can re-enable them.

@SimenB
Copy link
Member

SimenB commented Nov 19, 2018

Once we drop support for Node <10 we can re-enable them.

Heh, so in like 3 years :P (EDIT: node 8 is EOL Dec 2019, so 3 was a bit of an exaggeration)

Would it be possible to detect support and activate if it's available? Or would that give us different behaviors on different nodes which might be confusing to the user?

@rubennorte
Copy link
Contributor Author

@SimenB what I disabled was the test, not the support for the feature. I still use feature detection and enable it if it's available.

@SimenB
Copy link
Member

SimenB commented Nov 19, 2018

Ah, cool! Could we conditionally disable the test/assertions as well, then? To make sure we don't break it 🙂

@codecov-io
Copy link

Codecov Report

Merging #7385 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7385      +/-   ##
==========================================
+ Coverage   66.72%   66.78%   +0.05%     
==========================================
  Files         241      242       +1     
  Lines        9356     9372      +16     
  Branches        6        6              
==========================================
+ Hits         6243     6259      +16     
  Misses       3110     3110              
  Partials        3        3
Impacted Files Coverage Δ
...ckages/jest-haste-map/src/lib/isRegExpSupported.js 100% <100%> (ø)
...ages/jest-haste-map/src/lib/dependencyExtractor.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b62b08...512b0e2. Read the comment docs.

@rubennorte rubennorte merged commit 819cae5 into jestjs:master Nov 19, 2018
@rubennorte rubennorte deleted the improve-dependency-extractor branch November 19, 2018 18:03
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants