Comments (4)
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?
from lwc.
Does it work if you run yarn && yarn test && yarn test:karma && DISABLE_SYNTHETIC=1 yarn test:karma
? Curious whether it actually works across both synthetic and native shadow.
from lwc.
@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.
from lwc.
I looked into this a bit further. What makes this complex is that we have a compile-time check to ensure you don't have duplicate slots in the same template:
<slot name="foo"></slot>
<slot name="foo"></slot> <!-- Duplicate -->
One reason to get rid of this check is that native shadow will happily render duplicate slots. It just ignores the second one.
We'd need to check first how this works with light/synthetic shadow though. And possibly mimic the native shadow behavior (or perhaps throw an error at runtime). This may or may not be backwards compatible, though (due to the lwc:spread
workaround).
from lwc.
Related Issues (20)
- Log warning for host mutation during SSR HOT 1
- Maintaining the Id Attributes after component render. HOT 2
- Remove remaining vestiges of `jest` types
- `lwc:spread` applies props rather than attributes HOT 2
- Migrate from yarn to pnpm HOT 2
- Remove misleading warning when using `@wire` on a getter or a setter HOT 1
- Consider removing `setHooks`
- Light DOM slot forwarding fails to render for duplicated slot names HOT 1
- `@wire` on getter/setter ignores implementation
- Synthetic shadow + duplicate slots + slot forwarding: `Failed to execute 'removeChild' on 'Node'`
- Static-optimize `on` event listener object HOT 2
- lwc:external Expressions inside lit-element render() is not rendered. HOT 1
- Prettier should not mutate `expected.js` files
- Esbuild plugin to build LWC apps HOT 2
- Optimize locally-scoped event listeners HOT 1
- Make duplicate slots in light DOM behave like native shadow DOM slots, or disallow duplicates entirely HOT 2
- Ignore hydration mismatches during SSR rendering as well as `connectedCallback` HOT 3
- Enhance performance timings with the DevTools extensibility API
- Add ability to hide date format and help text element shown inline beneath the lightning-input field HOT 2
- Cater for the omission of if:false when replacing if:true with lwc:true HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lwc.