Allow default import component to be renamed based on import statement default specifier (#193)
* Allow renaming for default import components * Changeset
This commit is contained in:
parent
42ec961eec
commit
e0a4f5fbc0
3 changed files with 30 additions and 8 deletions
5
.changeset/many-turtles-move.md
Normal file
5
.changeset/many-turtles-move.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Allow renaming for default import components
|
|
@ -222,14 +222,19 @@ async function gatherRuntimes({ astroConfig, buildState, filepath, logging, reso
|
|||
for (const componentImport of componentImports) {
|
||||
const importUrl = componentImport.source.value;
|
||||
const componentType = path.posix.extname(importUrl);
|
||||
const componentName = path.posix.basename(importUrl, componentType);
|
||||
const plugin = extensions[componentType] || defaultExtensions[componentType];
|
||||
plugins.add(plugin);
|
||||
components[componentName] = {
|
||||
plugin,
|
||||
type: componentType,
|
||||
specifier: importUrl,
|
||||
};
|
||||
for (const specifier of componentImport.specifiers) {
|
||||
if (specifier.type === 'ImportDefaultSpecifier') {
|
||||
const componentName = specifier.local.name;
|
||||
const plugin = extensions[componentType] || defaultExtensions[componentType];
|
||||
plugins.add(plugin);
|
||||
components[componentName] = {
|
||||
plugin,
|
||||
type: componentType,
|
||||
specifier: importUrl,
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const dynamic = await acquireDynamicComponentImports(plugins, resolvePackageUrl);
|
||||
|
|
12
packages/astro/test/fixtures/astro-dynamic/src/pages/default-rename.astro
vendored
Normal file
12
packages/astro/test/fixtures/astro-dynamic/src/pages/default-rename.astro
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
import CounterRenamed from '../components/Counter.jsx';
|
||||
import SvelteCounterRenamed from '../components/SvelteCounter.svelte';
|
||||
---
|
||||
<html>
|
||||
<head><title>Dynamic pages</title></head>
|
||||
<body>
|
||||
<CounterRenamed:load />
|
||||
|
||||
<SvelteCounterRenamed:load />
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue