Skip to content

Commit

Permalink
fix: ignore as type expressions on property definitions (#14181)
Browse files Browse the repository at this point in the history
fixes #14179
  • Loading branch information
dummdidumm authored Nov 6, 2024
1 parent c499496 commit 9b2a8f1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-laws-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ignore `as` type expressions on property definitions
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ const visitors = {
if (node.exportKind === 'type') return b.empty;
return node;
},
PropertyDefinition(node) {
PropertyDefinition(node, { next }) {
if (node.accessor) {
e.typescript_invalid_feature(
node,
'accessor fields (related TSC proposal is not stage 4 yet)'
);
}
return next();
},
TSAsExpression(node, context) {
return context.visit(node.expression);
Expand Down Expand Up @@ -97,7 +98,7 @@ const visitors = {
if ((node.readonly || node.accessibility) && context.path.at(-2)?.kind === 'constructor') {
e.typescript_invalid_feature(node, 'accessibility modifiers on constructor parameters');
}
return node.parameter;
return context.visit(node.parameter);
},
FunctionExpression: remove_this_param,
FunctionDeclaration: remove_this_param,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

// This test mainly checks that all types are properly ignored by the compiler
export default test({
html: '<button>clicks: 0</button>',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class Foo {
public name: string;
x = 'x' as const;
constructor(name: string) {
this.name = name;
}
Expand Down

0 comments on commit 9b2a8f1

Please sign in to comment.