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
Coverage init no longer hoisted to the top in Babel 7.0.0-beta #92
Comments
@loganfsmyth thanks for the heads up; in the short term we'll probably just bump up to Would definitely entertain eliminating the need for |
The blockHoist value has been increased in #135 so this issue could potentially be closed. That said, it might be good to have this or another issue to track removing This means that it is possible for dependency cycles between files to run functions before the file coverage structure has been initialized. My suggestion would still be to use a lazy-initialized function declaration to handle hoisting, e.g.
could instead be
with references being |
I think your suggestion of converting the coverage variable into a function which returns the coverage data is actually a good idea for performance. I just ran a benchmark against the following script: 'use strict';
function a(b) {
return b ? '1' : '2';
}
console.time('bench');
for (let i = 0; i < 1000000000; i++) {
a();
}
console.timeEnd('bench'); I instrumented this script with I executed this using: for i in {1..10}; do node bench.js; node bench-i1.js; node bench-i2.js; done It took an average of 510ms to run bench.js, 3029ms to run bench-i1.js and 2954ms to run bench-i2.js. This is surprising to me but your suggested code change actually makes (this specific) instrumented code run about 1.3% faster. I think this could be due to our currently reference a |
This replaces the coverage variable with a function that returns coverage data. Fixes #92
This replaces the coverage variable with a function that returns coverage data. Fixes istanbuljs#92
Heya, just came across this so I figured I'd pass it along.
https://github.com/istanbuljs/istanbuljs/blob/2ce8974/packages/istanbul-lib-instrument/src/visitor.js#L519
is now breaking on Babel 7.x beta because we added a new blockHoist level
4
to work around some issues.You'll need to bump that up for things to keep working.
That said, we've been really hoping that in the long run we can remove the concept of blockHoist. I don't know if it'll happen, but we'll see.
Have you all considered approaches that avoid the need for it? For instance if you use hoisting to your advantage and made that a function declaration and called it every time you needed the object, you could lazy-init the coverage object on first access and avoid the need got blockHoist.
The text was updated successfully, but these errors were encountered: