-
Notifications
You must be signed in to change notification settings - Fork 382
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
Add support for dynamic <slot>
names
#4207
Comments
I tried implementing this and to my surprise it seems to work by simply removing the check: if (ast.isExpression(nameAttribute.value)) {
ctx.throwOnNode(ParserDiagnostics.NAME_ON_SLOT_CANNOT_BE_EXPRESSION, nameAttribute);
} Am I missing something as I suspect? Should I submit a PR? |
Does it work if you run |
@nolanlawson yes, it only fails the test for the NAME_ON_SLOT_CANNOT_BE_EXPRESSION error, which I believe would be updated / removed. packages/@lwc/template-compiler/src/tests/fixtures/slots/error-definition-dynamic-name/expected.js - Expected
+ Received
+ import { registerTemplate } from "lwc";
+ const stc0 = [];
+ function tmpl($api, $cmp, $slotset, $ctx) {
+ const { s: api_slot } = $api;
+ return [
+ api_slot(
+ "",
+ {
+ attrs: {
+ name: $cmp.slotName,
+ },
+ key: 0,
+ },
+ stc0,
+ $slotset
+ ),
+ ];
+ /*LWC compiler vX.X.X*/
+ }
+ export default registerTemplate(tmpl);
+ tmpl.slots = [""];
+ tmpl.stylesheets = []; I'm guessing we would need a test for the actual feature and perhaps that would fail for non-native dom. |
Developers would like to be able to have dynamic
<slot>
names:This is currently disallowed by our compiler (
Error: LWC1076: Name attribute on slot tag can't be an expression.
). But there's nothing in native shadow DOM that inherently disallows this; we could trivially require it there.In fact, you can already achieve this in native shadow DOM by doing manual DOM manipulation, or cheating by using
lwc:spread
.One question is whether we'd want to support this in synthetic shadow DOM (probably not) or light DOM (maybe).
The text was updated successfully, but these errors were encountered: