From 73d67677d1b4274da1532c53067e198aab307b88 Mon Sep 17 00:00:00 2001 From: gianlucaguarini Date: Mon, 31 Aug 2020 21:20:49 +0200 Subject: [PATCH] fixed: evaluate expressions in custom native web components --- src/bindings/slot.js | 4 +--- src/bindings/tag.js | 2 +- test/bindings/tag.spec.js | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/bindings/slot.js b/src/bindings/slot.js index 83f6d0b..8c4b8b6 100644 --- a/src/bindings/slot.js +++ b/src/bindings/slot.js @@ -19,9 +19,7 @@ function extendParentScope(attributes, scope, parentScope) { // this function is only meant to fix an edge case // https://github.com/riot/riot/issues/2842 -const getRealParent = (scope, parentScope) => parentScope ? - parentScope === scope ? scope[PARENT_KEY_SYMBOL] : parentScope - : undefined +const getRealParent = (scope, parentScope) => scope[PARENT_KEY_SYMBOL] || parentScope export const SlotBinding = Object.seal({ // dynamic binding properties diff --git a/src/bindings/tag.js b/src/bindings/tag.js index 5de6129..4e5b71e 100644 --- a/src/bindings/tag.js +++ b/src/bindings/tag.js @@ -47,7 +47,7 @@ function slotBindings(slots) { */ function slotsToMarkup(slots) { return slots.reduce((acc, slot) => { - return `${acc}${slot.html}` + return acc + slot.html }, '') } diff --git a/test/bindings/tag.spec.js b/test/bindings/tag.spec.js index 9abfc71..f8ec50f 100644 --- a/test/bindings/tag.spec.js +++ b/test/bindings/tag.spec.js @@ -47,8 +47,15 @@ describe('tag bindings', () => { }, slots: [{ 'id': 'main', - 'html': '

hello

', - 'bindings': [] + 'html': '

', + 'bindings': [{ + selector: '[expr2]', + expressions: [{ + type: expressionTypes.TEXT, + childNodeIndex: 0, + evaluate: scope => scope.text + }] + }] }], attributes: [{ evaluate: scope => scope.class, @@ -60,16 +67,16 @@ describe('tag bindings', () => { 'name': 'main', 'redundantAttribute': 'expr1', 'selector': '[expr1]' - }]).mount(target, {class: 'hello'}) + }]).mount(target, {class: 'hello', text: 'hello'}) const b = target.querySelector('b') - const slot = target.querySelector('slot') + const p = target.querySelector('p') - expect(slot).to.be.ok expect(b).to.be.ok + expect(p).to.be.ok expect(b.getAttribute('class')).to.be.equal('hello') - expect(slot.getAttribute('name')).to.be.equal('main') + expect(p.innerHTML).to.be.equal('hello') el.unmount() })