Skip to content

Conversation

@paoloricciuti
Copy link
Member

Svelte 5 rewrite

Kinda closes #11316: although the code in their repro will still not work because you can't spread classes into arguments this allow to create properties with literals like

class Toggle{
    "aria-pressed" = $state(true);
}

that get's compiled to

class Toggle {
    #aria_pressed = $.source(true);

    get "aria-pressed"() {
        return $.get(this.#aria_pressed);
    }

    set "aria-pressed"(value) {
        $.set(this.#aria_pressed, $.proxy(value));
    }
}

i've added a single test for this but i'm wondering if i should add a test for each class test that was already there (in theory it should already be covered because they share the same code but you know)

Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (main).

If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is svelte-4 and not main.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@changeset-bot
Copy link

changeset-bot bot commented Apr 24, 2024

🦋 Changeset detected

Latest commit: 99d3a06

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

}
create_state_field(definition, is_private, name);
} else if (definition.type === 'PropertyDefinition' && definition.key.type === 'Literal') {
const name = definition.key.value?.toString().replace('-', '_');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is enough - there could be all sorts of whacky characters in there, better to use a "non-valid ID identifier" regex (I believe there exists one already)

Copy link
Member Author

@paoloricciuti paoloricciuti Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh great, yesterday I started to think of other invalid characters but nothing come to mind...I'll update soon

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just realized I need replaceAll

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dummdidumm fixed it in the new commit...should i add more tests for all the same thing that were tested with normal identifiers?

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dummdidumm dummdidumm merged commit 2d2508a into sveltejs:main Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Svelte 5: $state with quoted properties

3 participants