Skip to content

Commit f76fa96

Browse files
committed
fix: validation should not fail on anonymous declarations
1 parent 3d8f987 commit f76fa96

File tree

7 files changed

+21
-2
lines changed

7 files changed

+21
-2
lines changed

.changeset/twelve-bears-worry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: validation should not fail on anonymous declarations

packages/svelte/src/compiler/phases/2-analyze/visitors/ClassDeclaration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { validate_identifier_name } from './shared/utils.js';
88
* @param {Context} context
99
*/
1010
export function ClassDeclaration(node, context) {
11-
if (context.state.analysis.runes) {
11+
if (context.state.analysis.runes && node.id !== null) {
1212
validate_identifier_name(context.state.scope.get(node.id.name));
1313
}
1414

packages/svelte/src/compiler/phases/2-analyze/visitors/FunctionDeclaration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { validate_identifier_name } from './shared/utils.js';
88
* @param {Context} context
99
*/
1010
export function FunctionDeclaration(node, context) {
11-
if (context.state.analysis.runes) {
11+
if (context.state.analysis.runes && node.id !== null) {
1212
validate_identifier_name(context.state.scope.get(node.id.name));
1313
}
1414

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from '../../test';
2+
3+
// Ensures there is no compiler error
4+
export default test({
5+
test() {
6+
// NOOP
7+
}
8+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default class {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function () {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
import broken from './function.svelte.js';
3+
import broken2 from './class.svelte.js';
4+
</script>

0 commit comments

Comments
 (0)