Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt3): generate imports for components with named exports correctly #3288

Merged
merged 2 commits into from
Feb 17, 2022

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Feb 17, 2022

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Previously we would always generate default imports for components, even though addComponent supports adding named imports. This PR adds support for that with genImport.

The change: (check review comments. Behavior change to be fixed for default export importing)

-  import __nuxt_component_23 from '/my/file/default.ts'
+  import { default as __nuxt_component_23 } from '/my/file/default.ts'
-  import __nuxt_component_24 from '/my/file/named.ts'
+  import { namedExport as __nuxt_component_24 } from '/my/file/named.ts'

Notes

  • I've added an example in with-components but it may be better in a unit test - let me know if so and I can extract...

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe danielroe added bug Something isn't working nuxt3 πŸ”¨ p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage labels Feb 17, 2022
@danielroe danielroe requested a review from pi0 February 17, 2022 10:35
@danielroe danielroe self-assigned this Feb 17, 2022
@netlify
Copy link

netlify bot commented Feb 17, 2022

βœ”οΈ Deploy Preview for nuxt3-docs canceled.

πŸ”¨ Explore the source changes: bfc4daf

πŸ” Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/620e589d5beebf0007fafba8

@danielroe danielroe changed the title fix(nuxt3): generate imports for named exports correctly fix(nuxt3): generate imports for components with named exports correctly Feb 17, 2022
@@ -13,5 +14,14 @@ export default defineNuxtConfig({
prefix: 'nuxt'
}
]
},
hooks: {
Copy link
Member

Choose a reason for hiding this comment

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

It is probably not a generic use case to add in example. Let's have it in test/fixture/basic which can be used for actually testing behavior too.

@@ -37,7 +37,7 @@ function transform (content: string, components: Component[]) {
if (component) {
const identifier = map.get(component) || `__nuxt_component_${num++}`
map.set(component, identifier)
imports += genImport(component.filePath, identifier)
imports += genImport(component.filePath, [{ name: component.export, as: identifier }])
Copy link
Member

Choose a reason for hiding this comment

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

Note: I guess we could improve genImport to avoid generating default as x when there is only one default import...

@pi0 pi0 merged commit 8adff2e into main Feb 17, 2022
@pi0 pi0 deleted the fix/named-component-imports branch February 17, 2022 14:23
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x bug Something isn't working nuxt3 πŸ”¨ p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants