Repository navigation
Fix insertImportDeclaration doing nothing on the root collection - #768
olucasleitedev wants to merge 1 commit into
Conversation
insertImportDeclaration only inserted the new import into Program nodes. The collection returned by j(source) holds the File node, so calling it there silently did nothing. Insert into the program of a File as well.
|
@olucasleitedev is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @olucasleitedev! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
🦋 Changeset detectedLatest commit: 0607d7a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Problem
insertImportDeclaration()silently does nothing when called on the collection returned byj(source), which is how it is normally used:Output (unchanged):
The method only inserts into
Programnodes, but the root collection holds theFilenode. The existing tests did not catch this because they build the collection fromrecast.parse(...).program.Fix
When a path is a
File, the import is inserted into itsprogram. Collections ofProgramnodes behave as before. The duplicate check (hasImportDeclaration) already searches descendants, so it works for both.Verification
Same script after the change:
The new test in
ImportDeclaration-test.jsfails onmain(Expected: 1, Received: 0) and passes with this change, and all collection test suites pass. Apatchchangeset is included.