Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

addImportSpecifier() prevent duplicates #2081

Merged
merged 3 commits into from
Nov 23, 2021

Conversation

cartogram
Copy link
Contributor

Description

This PR prevents duplicate specifiers from being added when using the addImportSpecifier transform. If duplicates end up in the source, they cause a syntax error for transforms down the line.

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above (Documentation fix and Test update does not need a changelog as we do not publish new version)

@cartogram cartogram requested a review from a team November 22, 2021 13:22
@cartogram cartogram changed the title Add import specifier prevent duplicates addImportSpecifier() prevent duplicates Nov 22, 2021
@cartogram
Copy link
Contributor Author

@Shopify/web-foundations do you know what the ruby-tests failures in CI are about?

@atesgoral
Copy link
Contributor

@cartogram Short answer: No :(

I poked around a bit last week (so did @bradsokol), but no resolution yet.

@atesgoral
Copy link
Contributor

@cartogram The build issue on main is fixed.

@cartogram
Copy link
Contributor Author

@atesgoral Thanks for following up!

Would I also be able to get a review 🍏 from you or someone on the web-foundations team?

@@ -19,5 +19,19 @@ export default function addImportStatement(statement: string | string[]) {
path.node.body.unshift(ast);
});
},
File(path: traverse.NodePath<t.Program>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a test for this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I can't with my current test utilities because the File node is not part of the fixture (they start at Program because they are coming from strings not files). I tried to get around this without any luck.

I suggest we merge without a test for this and I'll come back to it. These utilities are already well tested given how experimental they are, and this particular logic exists to catch the rare edge case that they run this transform on an empty file.

What do you think?

@cartogram cartogram merged commit d67a9f7 into main Nov 23, 2021
@cartogram cartogram deleted the @cartogram/no-duplicate-import-specifier branch November 23, 2021 15:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants