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

[DO NOT MERGE] Trigger CI for #4976: fix(template-compiler): dynamic components with scoped slots #4979

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
LWC1178: <template> tag with lwc:slot-data directive must be the direct child of a custom element.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<x-dynamic-component>
<template shadowrootmode="open">
<x-test>
a
<!---->
<!---->
<span>
a - b
</span>
<!---->
<!---->
b
</x-test>
</template>
</x-dynamic-component>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ import { LightningElement } from 'lwc';

export default class Test extends LightningElement {
static renderMode = 'light';

item = {
id: 'a',
name: 'b',
};
}
7 changes: 6 additions & 1 deletion packages/@lwc/template-compiler/src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import type {
ScopedSlotFragment,
LwcComponent,
Element,
Component,
} from '../shared/types';
import type State from '../state';
import type { Token as parse5Token } from 'parse5';
Expand Down Expand Up @@ -1282,10 +1283,14 @@ function parseScopedSlotFragment(
);
}

function isComponentOrLwcComponent(node: ParentNode): node is Component | LwcComponent {
return ast.isComponent(node) || ast.isLwcComponent(node);
}

// <template lwc:slot-data> element should always be the direct child of a custom element
// The only exception is, a conditional block as parent
const parentCmp = ctx.findAncestor(
ast.isComponent,
isComponentOrLwcComponent,
({ current }) => current && ast.isConditionalBlock(current)
);

Expand Down