Skip to content

Commit

Permalink
updated: avoid adding a template fallback for empty slots
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Nov 22, 2024
1 parent fbcc4ac commit fd1b5cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/generators/template/bindings/slot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
BINDING_ATTRIBUTES_KEY,
BINDING_NAME_KEY,
BINDING_TEMPLATE_KEY,
BINDING_TYPES,
BINDING_TYPE_KEY,
DEFAULT_SLOT_NAME,
Expand All @@ -11,6 +12,7 @@ import {
createBindingAttributes,
createSelectorProperties,
createTemplateProperty,
getChildrenNodes,
getName,
getNodeAttributes,
} from '../utils.js'
Expand Down Expand Up @@ -63,14 +65,16 @@ export default function createSlotBinding(
),
),
simplePropertyNode(BINDING_NAME_KEY, builders.literal(slotName)),
createTemplateProperty(
createNestedBindings(
sourceNode,
sourceFile,
sourceCode,
selectorAttribute,
),
),
getChildrenNodes(sourceNode).length
? createTemplateProperty(
createNestedBindings(
sourceNode,
sourceFile,
sourceCode,
selectorAttribute,
),
)
: simplePropertyNode(BINDING_TEMPLATE_KEY, builders.nullLiteral()),
...createSelectorProperties(selectorAttribute),
])
}
9 changes: 9 additions & 0 deletions test/generators/template.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,15 @@ describe('Generators - Template', () => {
expect(output[NAME_ATTRIBUTE]).to.be.equal('default')
})

it('Slot without fallback', () => {
const source = '<slot message={ message } />'
const { template } = parse(source)
const input = slotBinding(template, 'expr0', FAKE_SRC_FILE, source)
const output = evaluateOutput(input)

expect(output[BINDING_TEMPLATE_KEY]).to.be.not.ok
})

it('Slot fallback html', () => {
const source =
'<div><slot><ul><li each={item in items}>{item}</li></ul></slot></div>'
Expand Down

0 comments on commit fd1b5cf

Please sign in to comment.