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:
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) {
|
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);
|
||||||
|
|
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