-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
using javascript keyword as component property #2729
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
Comments
This is already supported, via export-as, and was recently documented here. Maybe this should be called out in the tutorial as well? |
Ah, I missed that. I read through the api but only glanced through the accompanying code examples. The feature in question is a displayed as a comment in the code example. I do think it would be beneficial to add it to the tutorial. I would think many users would want to use As another note, |
Yeah there's an issue #2528 about documenting |
Back in the days, people tended to pick „klass” instead. I'm sure you'll find articles out there ;-) |
I'm going to copy and paste the answer from the docs so it's easier to find: let clazz;
export { clazz as class }; |
My wish would be that svelte adds the For the moment that can be accomplished via a simple pre-processor: function classProcessor() {
function process(content) {
return (
content
.replace(
/export let className([;\n= ]{1})/g,
'export { className as class }; let className$1'
)
);
}
return function(options) {
const {
content
} = options;
const code = process(content);
return {
code
};
}
}; Essentially transforms
to
Not very convenient though. |
I often find myself wanting a property on my components called
class
. I can't useexport let class
asclass
is a javascript keyword. I'm left with either calling it something else or using$$props
directly like so<label class={$$props['class']}>
. I don't know if using$$props
directly has any downsides. The tutorial warns that "it's not generally recommended, as it's difficult for Svelte to optimise". Either way, I don't know how plausible it would be, but it would be nice to have some mechanism to allow keywords to be used as component properties.The text was updated successfully, but these errors were encountered: