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

fixes #11731
pull/11767/head
Simon H 1 year ago committed by GitHub
parent 5fb017df92
commit 7a1326be06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: handle `this` parameter in TypeScript-annotated functions

@ -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) {
@ -71,7 +82,9 @@ const visitors = {
};
}
return node;
}
},
FunctionExpression: remove_this_param,
FunctionDeclaration: remove_this_param
};
/**

@ -2,6 +2,10 @@
interface Hello { message: 'hello' }
type Goodbye = { message: 'goodbye' };
function this_fn(this: any) {
console.log(this);
}
export type { Hello };
</script>

Loading…
Cancel
Save