Skip to content

Commit 0dfdf1e

Browse files
committed
restrict further
1 parent d79f145 commit 0dfdf1e

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

packages/svelte/src/compiler/phases/2-analyze/validation.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,11 @@ const validation = {
366366
if (
367367
node.expression.type === 'NewExpression' &&
368368
node.expression.callee.type === 'Identifier' &&
369-
node.expression.arguments.length === 1
369+
node.expression.arguments.length === 1 &&
370+
node.expression.arguments[0].type === 'ObjectExpression' &&
371+
node.expression.arguments[0].properties.some(
372+
(p) => p.type === 'Property' && p.key.type === 'Identifier' && p.key.name === 'target'
373+
)
370374
) {
371375
const binding = state.scope.get(node.expression.callee.name);
372376
if (binding?.kind === 'normal' && binding.declaration_kind === 'import') {

packages/svelte/tests/validator/samples/component-legacy-instantiation/input.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
55
let Buzz;
66
7-
new Foo({});
7+
new Foo({ target: null });
8+
new Foo({}); // also a false negative to be really sure we don't get false positives
9+
new Foo();
810
new Bar();
911
new Baz();
1012
new Buzz();
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[
22
{
33
"code": "legacy_component_creation",
4-
"end": {
5-
"column": 12,
6-
"line": 7
7-
},
84
"message": "Svelte 5 components are no longer classes. Instantiate them using `mount` or `hydrate` (imported from 'svelte') instead.",
95
"start": {
106
"column": 1,
117
"line": 7
8+
},
9+
"end": {
10+
"column": 26,
11+
"line": 7
1212
}
1313
}
1414
]

0 commit comments

Comments
 (0)