Code Monkey home page Code Monkey logo

Comments (7)

rChaoz avatar rChaoz commented on July 18, 2024 1

Here's a suggestion: warn (not error) on variable/import with name of rune, and disable the rune for the entire file. So you can do import $state from "somewhere" and it gives you a warning:

The import/variable name clashes with a Svelte rune. The $state rune cannot be used in this file unless the import/variable is renamed.

The warning should maybe be able to be suppressed.

This way new runes are not breaking changes. And the existing error for all $-prefixed variables should be removed, or at least changed to warnings (which should definitely be able to be suppressed).

from svelte.

trueadm avatar trueadm commented on July 18, 2024

You can always import the package imports as a namespace. This is something we've been advocating for folks who have this exact problem, for example with Lexical:

import * as Lexical from 'lexical';

// ..

lexical.$insertNodes()

from svelte.

roonie007 avatar roonie007 commented on July 18, 2024

@trueadm I don't think you understood my point, we have internal conventions and rules and all of our projects use $ and in case we WANT to use Svelte 5, we are FORCED to break those rules.

In my opinion, a framework should absolutely not break a company or even a developer code writing rules.

I saw the other issues related to the $ sign, they suggest the removal of the $ sign from the runes, but here I am asking to relax the restriction.

from svelte.

trueadm avatar trueadm commented on July 18, 2024

@roonie007 I know, I was the author of Lexical that also had the convention of using $ prefixes on the APIs. However, like I said above, you're not removing the convention, you're just working around it. In the case of .svelte modules, we enforce that $ prefix isn't allowed as it enables us to use those for runes in the future. It would suck if we couldn't add a $db() or a $session() rune in the future to SvelteKit – for example.

from svelte.

roonie007 avatar roonie007 commented on July 18, 2024

@trueadm That’s precisely my point. While svelte could introduce $db or $session in the future, in our codebase, we have the flexibility to rename variables as needed (e.g., $database, $mongo, $prisma, $userSession, etc...).

Having the choice is always preferable to being restricted. Allowing us to continue using $-prefixes for our internal functions without enforcing a blanket restriction would provide more flexibility and avoid unnecessary workarounds.

from svelte.

paoloricciuti avatar paoloricciuti commented on July 18, 2024

@trueadm That’s precisely my point. While svelte could introduce $db or $session in the future, in our codebase, we have the flexibility to rename variables as needed (e.g., $database, $mongo, $prisma, $userSession, etc...).

Having the choice is always preferable to being restricted. Allowing us to continue using $-prefixes for our internal functions without enforcing a blanket restriction would provide more flexibility and avoid unnecessary workarounds.

The problem is semver: if you don't restrict $ variables whenever you want to add a new rune that's a breaking change. So while you absolutely can rename your variables svelte can't publish a new rune without bumping to svelte 6 (which would be kinda restrictive)

from svelte.

roonie007 avatar roonie007 commented on July 18, 2024

@rChaoz suggestion is also an acceptable solution to relax the restriction.

from svelte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.