diff --git a/src/generators/template/builder.js b/src/generators/template/builder.js index e6ca259..50743b1 100644 --- a/src/generators/template/builder.js +++ b/src/generators/template/builder.js @@ -153,7 +153,8 @@ export function createNestedBindings( const mightBeARiotComponent = isCustomNode(sourceNode) const node = cloneNodeWithoutSelectorAttribute(sourceNode, selector) - return mightBeARiotComponent + // slot nodes and riot components do not need to build html + return mightBeARiotComponent || isSlotNode(sourceNode) ? [null, [tagBinding(node, null, sourceFile, sourceCode)]] : build(createNestedRootNode(node), sourceFile, sourceCode) } diff --git a/src/generators/template/utils.js b/src/generators/template/utils.js index 14584ad..a9132a0 100644 --- a/src/generators/template/utils.js +++ b/src/generators/template/utils.js @@ -435,6 +435,7 @@ export function createNestedRootNode(node) { return { ...rootNodeFactory(node), isNestedRoot: true, + name: node.name, attributes: cleanAttributes(node), } } diff --git a/test/generators/template.spec.js b/test/generators/template.spec.js index 5e14f70..5f51f3f 100644 --- a/test/generators/template.spec.js +++ b/test/generators/template.spec.js @@ -856,6 +856,39 @@ describe('Generators - Template', () => { ).to.be.equal('my-id') }) + it('Inputs with conditional handle the value expression properly (https://github.com/riot/riot/issues/3076)', () => { + const source = '
' + const { template } = parse(source) + const bindings = evaluateOutput( + builders.arrayExpression(builder(template, FAKE_SRC_FILE, source)[1]), + ) + const tagBinding = bindings[0] + const { expressions } = tagBinding.template.bindingsData[0] + + expect(tagBinding[BINDING_SELECTOR_KEY]).to.be.ok + expect(tagBinding[BINDING_TYPE_KEY]).to.be.equal(bindingTypes.IF) + + expect( + expressions[0][BINDING_EVALUATE_KEY]({ + foo: 'foo', + }), + ).to.be.equal('foo') + + expect(expressions[0][BINDING_TYPE_KEY]).to.be.equal( + expressionTypes.VALUE, + ) + + expect( + expressions[1][BINDING_EVALUATE_KEY]({ + bar: 'bar', + }), + ).to.be.equal('bar') + + expect(expressions[1][BINDING_TYPE_KEY]).to.be.equal( + expressionTypes.ATTRIBUTE, + ) + }) + it('Tag bindings can be computed', () => { const source = '