props alias

pull/11334/head
Simon Holthausen 2 years ago
parent 58cb0a9b14
commit 9a5088b705

@ -163,6 +163,27 @@ const instance_script = {
Identifier(node, { state }) { Identifier(node, { state }) {
handle_identifier(node, state); handle_identifier(node, state);
}, },
ExportNamedDeclaration(node, { state, next }) {
if (node.declaration) {
next();
return;
}
let count_removed = 0;
for (const specifier of node.specifiers) {
const binding = state.scope.get(specifier.local.name);
if (binding?.kind === 'bindable_prop') {
state.str.remove(
/** @type {number} */ (specifier.start),
/** @type {number} */ (specifier.end)
);
count_removed++;
}
}
if (count_removed === node.specifiers.length) {
state.str.remove(/** @type {number} */ (node.start), /** @type {number} */ (node.end));
}
},
VariableDeclaration(node, { state, path }) { VariableDeclaration(node, { state, path }) {
if (state.scope !== state.analysis.instance.scope) { if (state.scope !== state.analysis.instance.scope) {
return; return;
@ -192,6 +213,9 @@ const instance_script = {
if (declarator.id.type !== 'Identifier') { if (declarator.id.type !== 'Identifier') {
// TODO // TODO
throw new Error(
'Encountered an export declaration pattern that is not supported for automigration.'
);
// Turn export let into props. It's really really weird because export let { x: foo, z: [bar]} = .. // Turn export let into props. It's really really weird because export let { x: foo, z: [bar]} = ..
// means that foo and bar are the props (i.e. the leafs are the prop names), not x and z. // means that foo and bar are the props (i.e. the leafs are the prop names), not x and z.
// const tmp = state.scope.generate('tmp'); // const tmp = state.scope.generate('tmp');

@ -0,0 +1,6 @@
<script lang="ts">
let klass = '';
export { klass as class }
</script>
{klass}

@ -0,0 +1,8 @@
<script lang="ts">
interface Props { class?: string }
let { class: klass = '' }: Props = $props();
</script>
{klass}
Loading…
Cancel
Save