fix: ignore `as` type expressions on property definitions (#14181)

fixes #14179
warning-message
Simon H 1 week ago committed by GitHub
parent c49949621b
commit 9b2a8f15fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ignore `as` type expressions on property definitions

@ -56,13 +56,14 @@ const visitors = {
if (node.exportKind === 'type') return b.empty; if (node.exportKind === 'type') return b.empty;
return node; return node;
}, },
PropertyDefinition(node) { PropertyDefinition(node, { next }) {
if (node.accessor) { if (node.accessor) {
e.typescript_invalid_feature( e.typescript_invalid_feature(
node, node,
'accessor fields (related TSC proposal is not stage 4 yet)' 'accessor fields (related TSC proposal is not stage 4 yet)'
); );
} }
return next();
}, },
TSAsExpression(node, context) { TSAsExpression(node, context) {
return context.visit(node.expression); return context.visit(node.expression);
@ -97,7 +98,7 @@ const visitors = {
if ((node.readonly || node.accessibility) && context.path.at(-2)?.kind === 'constructor') { if ((node.readonly || node.accessibility) && context.path.at(-2)?.kind === 'constructor') {
e.typescript_invalid_feature(node, 'accessibility modifiers on constructor parameters'); e.typescript_invalid_feature(node, 'accessibility modifiers on constructor parameters');
} }
return node.parameter; return context.visit(node.parameter);
}, },
FunctionExpression: remove_this_param, FunctionExpression: remove_this_param,
FunctionDeclaration: remove_this_param, FunctionDeclaration: remove_this_param,

@ -1,6 +1,7 @@
import { flushSync } from 'svelte'; import { flushSync } from 'svelte';
import { test } from '../../test'; import { test } from '../../test';
// This test mainly checks that all types are properly ignored by the compiler
export default test({ export default test({
html: '<button>clicks: 0</button>', html: '<button>clicks: 0</button>',

@ -10,6 +10,7 @@
class Foo { class Foo {
public name: string; public name: string;
x = 'x' as const;
constructor(name: string) { constructor(name: string) {
this.name = name; this.name = name;
} }

Loading…
Cancel
Save