0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

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:
Kevin (Kun) "Kassimo" Qian 2021-05-10 09:00:05 -07:00 committed by GitHub
parent 42ec961eec
commit e0a4f5fbc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 8 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Allow renaming for default import components

View file

@ -222,14 +222,19 @@ async function gatherRuntimes({ astroConfig, buildState, filepath, logging, reso
for (const componentImport of componentImports) { for (const componentImport of componentImports) {
const importUrl = componentImport.source.value; const importUrl = componentImport.source.value;
const componentType = path.posix.extname(importUrl); const componentType = path.posix.extname(importUrl);
const componentName = path.posix.basename(importUrl, componentType); for (const specifier of componentImport.specifiers) {
const plugin = extensions[componentType] || defaultExtensions[componentType]; if (specifier.type === 'ImportDefaultSpecifier') {
plugins.add(plugin); const componentName = specifier.local.name;
components[componentName] = { const plugin = extensions[componentType] || defaultExtensions[componentType];
plugin, plugins.add(plugin);
type: componentType, components[componentName] = {
specifier: importUrl, plugin,
}; type: componentType,
specifier: importUrl,
};
break;
}
}
} }
const dynamic = await acquireDynamicComponentImports(plugins, resolvePackageUrl); const dynamic = await acquireDynamicComponentImports(plugins, resolvePackageUrl);

View 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>