Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle this parameter in TypeScript-annotated functions #11795

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fresh-walls-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: handle `this` parameter in TypeScript-annotated functions
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { walk } from 'zimmerframe';
import * as b from '../../utils/builders.js';

/**
* @param {import('estree').FunctionExpression | import('estree').FunctionDeclaration} node
* @param {import('zimmerframe').Context<any, any>} context
*/
function remove_this_param(node, context) {
if (node.params[0]?.type === 'Identifier' && node.params[0].name === 'this') {
node.params.shift();
}
return context.next();
}

/** @type {import('zimmerframe').Visitors<any, null>} */
const visitors = {
ImportDeclaration(node) {
Expand Down Expand Up @@ -71,7 +82,9 @@ const visitors = {
};
}
return node;
}
},
FunctionExpression: remove_this_param,
FunctionDeclaration: remove_this_param
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
interface Hello { message: 'hello' }
type Goodbye = { message: 'goodbye' };

function this_fn(this: any) {
console.log(this);
}

export type { Hello };
</script>

Expand Down
Loading