Skip to content

Script to Prune .d.ts files (with tests) #4091

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

Merged
merged 12 commits into from
Nov 25, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Nov 19, 2020

It's HACKWEEK... so it's time to pick up #3790 again. This time it is a standalone script with tests.

Almost all of the code in this PR are test cases (under /test) with BEFORE and AFTER files. The bulk of the change lines in the firestore example. The best way to review this PR might be to only look at the non d.ts files.

@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2020

⚠️ No Changeset found

Latest commit: df0e502

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/standalonescript branch from d9ca6a4 to 7f6a4ac Compare November 19, 2020 04:22
@schmidt-sebastian schmidt-sebastian changed the title Script to Prune .dts files (with tests) Script to Prune .d.ts files (with tests) Nov 19, 2020
@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/standalonescript branch from 7f6a4ac to 73f2c9a Compare November 19, 2020 04:30
@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/standalonescript branch from 73f2c9a to 1e359b5 Compare November 19, 2020 04:32
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 19, 2020

Size Analysis Report

Affected Products

No changes between base commit (6358fd0) and head commit (77f8cc3).

Test Logs

} else {
// Hide the type we are inheriting from and merge its declarations
// into the current class.
const privateType = typeChecker.getTypeAtLocation(type);
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to handle extends, and implements differently? For example, implements can be just safely removed without merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered this, but for this to work properly I would have to extract an extra symbol and then parse the declarations to determine whether whether the referenced type is a class or an interface. Not too bad... but it complicates this logic and doesn't actually change the result. I have added a TODO and a test that verifies the current behavior.

if (ts.isIdentifier(type.expression)) {
const subclassName = type.expression.escapedText;
if (subclassName === localSymbolName) {
return symbol;
Copy link
Member

Choose a reason for hiding this comment

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

Just want to note that this is not always safe to replace a class with an inheriting class. Copied my comment from the previous PR:

In case of multiple public classes extending PrivateFoo, we use the first one which seems arbitrary and is probably wrong - considering PublicFoo1 and PublicFoo2, both of which extends PrivateFoo. doFoo should accept either of them, but after this change, it will only accept PublicFoo1.

Our API typings probably don't have the case I described, so the code works, but we should be aware that this transformation can't be generalized to work for any d.ts files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we probably need to return a Union type in this case. I added a TODO, and I can fix this in a follow-up PR. I do think that this scripts needs a few iterations before it works for all d.ts file.

@@ -0,0 +1,39 @@
{
"name": "firebase-repo-scripts-prune-dts",
"version": "2.0.2",
Copy link
Member

Choose a reason for hiding this comment

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

Nit: 0.1.0 maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@schmidt-sebastian schmidt-sebastian merged commit ddb7993 into master Nov 25, 2020
@firebase firebase locked and limited conversation to collaborators Dec 25, 2020
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.

3 participants