8000 feat: add `$state.opaque` rune by trueadm · Pull Request #14639 · sveltejs/svelte · GitHub
[go: up one dir, main page]

Skip to content

feat: add $state.opaque rune #14639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lint
  • Loading branch information
trueadm committed Dec 9, 2024
commit 409bebc1b5dc4a5864bb48c2bbc89a31409d33b1
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ Cannot export state from a module if it is reassigned. Either export a function
### state_invalid_opaque_declaration

```
`$state.opaque` must be declared with an array destructuring pattern (e.g. `let [state, invalidate] = $state.opaque(data);`)
`%rune%(...)` must be declared with an array destructuring pattern (e.g. `let [state, invalidate] = $state.opaque(data);`)
```

### state_invalid_placement
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/messages/compile-errors/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ It's possible to export a snippet from a `<script module>` block, but only if it

## state_invalid_opaque_declaration

> `$state.opaque` must be declared with an array destructuring pattern (e.g. `let [state, invalidate] = $state.opaque(data);`)
> `%rune%(...)` must be declared with an array destructuring pattern (e.g. `let [state, invalidate] = $state.opaque(data);`)

## state_invalid_placement

Expand Down
7 changes: 4 additions & 3 deletions packages/svelte/src/compiler/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,13 @@ export function state_invalid_export(node) {
}

/**
* `$state.opaque` must be declared with an array destructuring pattern (e.g. `let [state, invalidate] = $state.opaque(data);`)
* `%rune%(...)` must be declared with an array destructuring pattern (e.g. `let [state, invalidate] = $state.opaque(data);`)
* @param {null | number | NodeLike} node
* @param {string} rune
* @returns {never}
*/
export function state_invalid_opaque_declaration(node) {
e(node, "state_invalid_opaque_declaration", "`$state.opaque` must be declared with an array destructuring pattern (e.g. `let [state, invalidate] = $state.opaque(data);`)");
export function state_invalid_opaque_declaration(node, rune) {
e(node, "state_invalid_opaque_declaration", `\`${rune}(...)\` must be declared with an array destructuring pattern (e.g. \`let [state, invalidate] = $state.opaque(data);\`)`);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function CallExpression(node, context) {
parent.id.elements.length !== 2 ||
parent.id.elements[0]?.type !== 'Identifier')
) {
e.state_invalid_opaque_declaration(node);
e.state_invalid_opaque_declaration(node, rune);
}

break;
Expand Down
Loading
0