Skip to content

Commit c4f0d8c

Browse files
authored
Revert "fix: stricter validation for component exports (#10430)"
This reverts commit dab0a43.
1 parent ce8495c commit c4f0d8c

File tree

11 files changed

+8
-75
lines changed

11 files changed

+8
-75
lines changed

.changeset/odd-taxis-retire.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/svelte/src/compiler/errors.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,8 @@ const runes = {
170170
'invalid-legacy-export': () => `Cannot use \`export let\` in runes mode — use $props instead`,
171171
/** @param {string} rune */
172172
'invalid-rune-usage': (rune) => `Cannot use ${rune} rune in non-runes mode`,
173-
'invalid-state-export': () =>
174-
`Cannot export state if it is reassigned. Either export a function returning the state value or only mutate the state value's properties`,
175-
'invalid-derived-export': () =>
176-
`Cannot export derived state. To expose the current derived value, export a function returning its value`,
177-
'invalid-prop-export': () =>
178-
`Cannot export properties. To expose the current value of a property, export a function returning its value`,
173+
'invalid-state-export': () => `Cannot export state if it is reassigned`,
174+
'invalid-derived-export': () => `Cannot export derived state`,
179175
'invalid-props-id': () => `$props() can only be used with an object destructuring pattern`,
180176
'invalid-props-pattern': () =>
181177
`$props() assignment must not contain nested properties or computed keys`,

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,6 @@ function validate_export(node, scope, name) {
733733
const binding = scope.get(name);
734734
if (!binding) return;
735735

736-
if (binding.kind === 'prop') {
737-
error(node, 'invalid-prop-export');
738-
}
739-
740736
if (binding.kind === 'derived') {
741737
error(node, 'invalid-derived-export');
742738
}
@@ -964,20 +960,10 @@ export const validation_runes = merge(validation, a11y_validators, {
964960
if (node.label.name !== '$' || path.at(-1)?.type !== 'Program') return;
965961
error(node, 'invalid-legacy-reactive-statement');
966962
},
967-
ExportNamedDeclaration(node, { state, next }) {
963+
ExportNamedDeclaration(node, { state }) {
968964
if (node.declaration?.type !== 'VariableDeclaration') return;
969-
970-
// visit children, so bindings are correctly initialised
971-
next();
972-
973-
for (const declarator of node.declaration.declarations) {
974-
for (const id of extract_identifiers(declarator.id)) {
975-
validate_export(node, state.scope, id.name);
976-
}
977-
}
978-
979-
if (state.analysis.instance.scope !== state.scope) return;
980965
if (node.declaration.kind !== 'let') return;
966+
if (state.analysis.instance.scope !== state.scope) return;
981967
error(node, 'invalid-legacy-export');
982968
},
983969
ExportSpecifier(node, { state }) {

packages/svelte/tests/compiler-errors/samples/export-derived-state/_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { test } from '../../test';
33
export default test({
44
error: {
55
code: 'invalid-derived-export',
6-
message:
7-
'Cannot export derived state. To expose the current derived value, export a function returning its value'
6+
message: 'Cannot export derived state',
7+
position: [24, 66]
88
}
99
});

packages/svelte/tests/compiler-errors/samples/export-derived-state/main.svelte

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/svelte/tests/compiler-errors/samples/export-state-2/_config.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/svelte/tests/compiler-errors/samples/export-state-2/main.svelte

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/svelte/tests/compiler-errors/samples/export-state/_config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { test } from '../../test';
33
export default test({
44
error: {
55
code: 'invalid-state-export',
6-
message:
7-
"Cannot export state if it is reassigned. Either export a function returning the state value or only mutate the state value's properties",
6+
message: 'Cannot export state if it is reassigned',
87
position: [46, 86]
98
}
109
});

packages/svelte/tests/compiler-errors/samples/runes-export-named-state/_config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { test } from '../../test';
33
export default test({
44
error: {
55
code: 'invalid-state-export',
6-
message:
7-
"Cannot export state if it is reassigned. Either export a function returning the state value or only mutate the state value's properties",
6+
message: 'Cannot export state if it is reassigned',
87
position: [28, 53]
98
}
109
});

packages/svelte/tests/compiler-errors/samples/runes-export-prop/_config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/svelte/tests/compiler-errors/samples/runes-export-prop/main.svelte

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)