Skip to content
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

Restrict generalization by scoping private keys #147

Open
Ayc0 opened this issue Sep 25, 2023 · 2 comments
Open

Restrict generalization by scoping private keys #147

Ayc0 opened this issue Sep 25, 2023 · 2 comments

Comments

@Ayc0
Copy link

Ayc0 commented Sep 25, 2023

TL;DR

Add scoping mechanism for custom attributes, like:

import foo from 'bar' with { "data-foo": "bar" };
// or
import foo from 'bar' with { "custom": { "foo": "bar" } };
// or similar

Problem

Avoid another possible smoothgate in the future.

Explanation

One of the reasons for the redesign of this proposal with with {…} is to allow tools to add custom fields in them (like bundlers or runtimes for instance).

But if there is another proposal in the future to add another field (like with { type, priority }), this could face the same risks as when we want to add methods in prototypes: aka clashing with potential custom keys already added by frameworks (like what happened for .flat vs .flatten).

What about introducing in the spec the fact that, just like in HTML, certain fields (for instance in data-*) will never be used by the spec.
This would allow libraries / bundlers to introduce their custom behaviors using them (if they want a data-bundlerA-priority, they'll without any risk of conflicts).
And will also allow the TC39 to introduce new keys in the spec later without potential conflicts.

The name data-* is just an idea, but it could be any other form of scoping mechanism, like: with { custom: {…} } etc.

@Josh-Cena
Copy link

Josh-Cena commented Nov 24, 2023

My suggestion is to use naming conventions—for example, prefixes like webpack-*, typescript-*, etc. The language would likely never use a name that's not an identifier, so this would certainly be same. This looks better than requiring all 3rd party attributes to live under the same object, since there aren't many first-party attributes anyways. custom: {...} would also require parsing object attribute values, while currently only string attributes are allowed.

@Ayc0
Copy link
Author

Ayc0 commented Apr 9, 2024

I agree, but if we want to enforce naming conventions, it should be stated in the spec. Enforcing that all variables used by the spec would use pascalCase and that 3rd party ones need to be prefixed by a <key>- (enforcing the - in the key) would work indeed

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

No branches or pull requests

2 participants