-
Notifications
You must be signed in to change notification settings - Fork 945
Remove unused code #2817
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
Remove unused code #2817
Conversation
Binary Size ReportAffected SDKs
Test Logs |
a125161
to
fa16463
Compare
// Escape the promise chain and throw the error globally so that | ||
// e.g. any global crash reporting library detects and reports it. | ||
// (but not for simulated errors in our tests since this breaks mocha) | ||
if (message.indexOf('Firestore Test Simulated Error') < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still used, isn't it?
const expected = new Error('Firestore Test Simulated Error'); |
You mentioned in the PR description that you ran the integration tests... did you run the unit tests also? Because it seems like the unit tests should fail with this line removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is special handling of test code that is no longer needed, since we are not using mocha
anymore (karma
runs our browser tests). So the same test passes now without this special handling.
As for running the unit tests - all tests run as part of CI, and I usually run them locally as well. There are some tests that are "harder" to run locally, such as the minified integration tests (see /integration/firestore), but even those are run in CI.
* always terminated with a separator, and so a successor can always be | ||
* cheaply computed by incrementing the last character of the path. | ||
*/ | ||
export function prefixSuccessor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my own information, is it acceptable to delete exported functions as long as they are not "publicly exported" in https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore-types/index.d.ts? Otherwise, wouldn't this be a backwards-incompatible change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, if code is not in the api/ folder, it can't be used by our users.
In more technical terms, only code that is exported from our index.ts files is considered part of the public API:
https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/register-module.ts
Furthermore, the files under /api should match our types (https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore-types/index.d.ts). All code in the exported classes above should either be part of the public API or prefixed with an underscore. We don't always get this right though - see https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/api/database.ts#L653. logLevel
is not in our types, but can be accessed since it is exported as part of Firestore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does removing this actually help? It seems like this should have been tree-shaken out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Tree-Shaking in the browser builds doesn't actually work very well. I am trying to fix that (currently not working though - #2829), but for the "older builds" only excludes code that in modules that aren't loaded at all. Only the ESM2017 build will not include functions, but also only if they are deemed "side-effect free".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your review!
// Escape the promise chain and throw the error globally so that | ||
// e.g. any global crash reporting library detects and reports it. | ||
// (but not for simulated errors in our tests since this breaks mocha) | ||
if (message.indexOf('Firestore Test Simulated Error') < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is special handling of test code that is no longer needed, since we are not using mocha
anymore (karma
runs our browser tests). So the same test passes now without this special handling.
As for running the unit tests - all tests run as part of CI, and I usually run them locally as well. There are some tests that are "harder" to run locally, such as the minified integration tests (see /integration/firestore), but even those are run in CI.
* always terminated with a separator, and so a successor can always be | ||
* cheaply computed by incrementing the last character of the path. | ||
*/ | ||
export function prefixSuccessor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, if code is not in the api/ folder, it can't be used by our users.
In more technical terms, only code that is exported from our index.ts files is considered part of the public API:
https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/register-module.ts
Furthermore, the files under /api should match our types (https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore-types/index.d.ts). All code in the exported classes above should either be part of the public API or prefixed with an underscore. We don't always get this right though - see https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/api/database.ts#L653. logLevel
is not in our types, but can be accessed since it is exported as part of Firestore.
@wilhuff for approval. |
* always terminated with a separator, and so a successor can always be | ||
* cheaply computed by incrementing the last character of the path. | ||
*/ | ||
export function prefixSuccessor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does removing this actually help? It seems like this should have been tree-shaken out?
@@ -118,18 +118,4 @@ export class TargetData { | |||
this.resumeToken | |||
); | |||
} | |||
|
|||
isEqual(other: TargetData): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't isEqual
used indirectly by our custom deep equal mechanism?
I worry that we may have tests that are checking that something is not equal that are now accidentally passing while checking reference equality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TargetData was never passed to our custom "equals" implementation. I actually looked back at the usage and since there is only one call, I decided to inline it. So now we have no code that treats objects with isEqual and without in the same codepath.
e39d46f
to
c99dba1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR removes unused code from the SDK (as shown by running the integration tests with coverage). It's only a small improvement, but it should not be harmful.