From 1fc88f626fb0fa7fc1ac78c8c8cce7cfa643a677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 6 Jun 2022 08:17:51 +0200 Subject: [PATCH] [IMP] slots: add support for t-props on slots props --- doc/reference/slots.md | 6 + src/compiler/code_generator.ts | 41 ++-- .../compiler/__snapshots__/misc.test.ts.snap | 6 +- .../__snapshots__/basics.test.ts.snap | 2 +- .../__snapshots__/concurrency.test.ts.snap | 18 +- .../__snapshots__/error_handling.test.ts.snap | 24 +-- .../__snapshots__/props.test.ts.snap | 2 +- .../props_validation.test.ts.snap | 4 +- .../__snapshots__/reactivity.test.ts.snap | 2 +- .../__snapshots__/refs.test.ts.snap | 2 +- .../__snapshots__/slots.test.ts.snap | 192 +++++++++++------- .../__snapshots__/style_class.test.ts.snap | 2 +- .../__snapshots__/t_foreach.test.ts.snap | 2 +- .../__snapshots__/t_on.test.ts.snap | 6 +- .../__snapshots__/t_props.test.ts.snap | 2 +- .../__snapshots__/t_set.test.ts.snap | 6 +- tests/components/slots.test.ts | 22 ++ tests/misc/__snapshots__/portal.test.ts.snap | 2 +- 18 files changed, 202 insertions(+), 139 deletions(-) diff --git a/doc/reference/slots.md b/doc/reference/slots.md index 4e6e1872..7c9637ec 100644 --- a/doc/reference/slots.md +++ b/doc/reference/slots.md @@ -239,6 +239,12 @@ And the child component that includes the slot can provide values like this: ``` +or this: + +```xml + +``` + In the case of the default slot, you may declare the slot scope directly on the component itself: diff --git a/src/compiler/code_generator.ts b/src/compiler/code_generator.ts index 958ef0e4..766b4d06 100644 --- a/src/compiler/code_generator.ts +++ b/src/compiler/code_generator.ts @@ -1083,23 +1083,25 @@ export class CodeGenerator { return `${name}: ${value || undefined}`; } - formatPropObject(obj: { [prop: string]: any }): string { - const params = []; - for (const [n, v] of Object.entries(obj)) { - params.push(this.formatProp(n, v)); + formatPropObject(obj: { [prop: string]: any }): string[] { + return Object.entries(obj).map(([k, v]) => this.formatProp(k, v)); + } + + getPropString(props: string[], dynProps: string | null): string { + let propString = `{${props.join(",")}}`; + if (dynProps) { + propString = `Object.assign({}, ${compileExpr(dynProps)}${ + props.length ? ", " + propString : "" + })`; } - return params.join(", "); + return propString; } compileComponent(ast: ASTComponent, ctx: Context) { let { block } = ctx; // props const hasSlotsProp = "slots" in (ast.props || {}); - const props: string[] = []; - const propExpr = this.formatPropObject(ast.props || {}); - if (propExpr) { - props.push(propExpr); - } + const props: string[] = ast.props ? this.formatPropObject(ast.props) : []; // slots let slotDef: string = ""; @@ -1123,7 +1125,7 @@ export class CodeGenerator { params.push(`__scope: "${scope}"`); } if (ast.slots[slotName].attrs) { - params.push(this.formatPropObject(ast.slots[slotName].attrs!)); + params.push(...this.formatPropObject(ast.slots[slotName].attrs!)); } const slotInfo = `{${params.join(", ")}}`; slotStr.push(`'${slotName}': ${slotInfo}`); @@ -1136,14 +1138,7 @@ export class CodeGenerator { props.push(`slots: markRaw(${slotDef})`); } - const propStr = `{${props.join(",")}}`; - - let propString = propStr; - if (ast.dynamicProps) { - propString = `Object.assign({}, ${compileExpr(ast.dynamicProps)}${ - props.length ? ", " + propStr : "" - })`; - } + let propString = this.getPropString(props, ast.dynamicProps); let propVar: string; if ((slotDef && (ast.dynamicProps || hasSlotsProp)) || this.dev) { @@ -1223,8 +1218,12 @@ export class CodeGenerator { } else { slotName = "'" + ast.name + "'"; } - - const scope = ast.attrs ? `{${this.formatPropObject(ast.attrs)}}` : null; + const dynProps = ast.attrs ? ast.attrs["t-props"] : null; + if (ast.attrs) { + delete ast.attrs["t-props"]; + } + const props = ast.attrs ? this.formatPropObject(ast.attrs) : []; + const scope = this.getPropString(props, dynProps); if (ast.defaultContent) { const name = this.compileInNewTarget("defaultContent", ast.defaultContent, ctx); blockString = `callSlot(ctx, node, key, ${slotName}, ${dynamic}, ${scope}, ${name})`; diff --git a/tests/compiler/__snapshots__/misc.test.ts.snap b/tests/compiler/__snapshots__/misc.test.ts.snap index cfe471f0..5400c594 100644 --- a/tests/compiler/__snapshots__/misc.test.ts.snap +++ b/tests/compiler/__snapshots__/misc.test.ts.snap @@ -34,7 +34,7 @@ exports[`misc complex template 1`] = ` for (let i1 = 0; i1 < l_block4; i1++) { ctx[\`slot\`] = v_block4[i1]; const key1 = ctx['slot'].id; - c_block4[i1] = withKey(component(\`SlotButton\`, {class: ctx['slot_container'], slot: ctx['slot']}, key + \`__1__\${key1}\`, node, ctx), key1); + c_block4[i1] = withKey(component(\`SlotButton\`, {class: ctx['slot_container'],slot: ctx['slot']}, key + \`__1__\${key1}\`, node, ctx), key1); } ctx = ctx.__proto__; b4 = list(c_block4); @@ -316,8 +316,8 @@ exports[`misc other complex template 1`] = ` if (!ctx['project']) { b24 = block24(); } else { - const b26 = component(\`BundlesList\`, {bundles: ctx['bundles'].sticky, category_custom_views: ctx['category_custom_views'], search: ctx['search']}, key + \`__2\`, node, ctx); - const b27 = component(\`BundlesList\`, {bundles: ctx['bundles'].dev, search: ctx['search']}, key + \`__3\`, node, ctx); + const b26 = component(\`BundlesList\`, {bundles: ctx['bundles'].sticky,category_custom_views: ctx['category_custom_views'],search: ctx['search']}, key + \`__2\`, node, ctx); + const b27 = component(\`BundlesList\`, {bundles: ctx['bundles'].dev,search: ctx['search']}, key + \`__3\`, node, ctx); b25 = block25([], [b26, b27]); } return block1([attr1, txt1, hdlr2, hdlr3, attr8, hdlr4, hdlr5, ref1, hdlr6, ref2], [b2, b4, b14, b17, b22, b23, b24, b25]); diff --git a/tests/components/__snapshots__/basics.test.ts.snap b/tests/components/__snapshots__/basics.test.ts.snap index cd49f832..b4ab84b9 100644 --- a/tests/components/__snapshots__/basics.test.ts.snap +++ b/tests/components/__snapshots__/basics.test.ts.snap @@ -1019,7 +1019,7 @@ exports[`basics update props of component without concrete own node 2`] = ` return function template(ctx, node, key = \\"\\") { const tKey_1 = ctx['props'].subKey; - return toggler(tKey_1, component(\`Custom\`, {key: ctx['props'].key, subKey: ctx['props'].subKey}, tKey_1 + key + \`__1\`, node, ctx)); + return toggler(tKey_1, component(\`Custom\`, {key: ctx['props'].key,subKey: ctx['props'].subKey}, tKey_1 + key + \`__1\`, node, ctx)); } }" `; diff --git a/tests/components/__snapshots__/concurrency.test.ts.snap b/tests/components/__snapshots__/concurrency.test.ts.snap index 6a03dd9e..bd200559 100644 --- a/tests/components/__snapshots__/concurrency.test.ts.snap +++ b/tests/components/__snapshots__/concurrency.test.ts.snap @@ -227,7 +227,7 @@ exports[`concurrent renderings scenario 1 2`] = ` let block1 = createBlock(\`

\`); return function template(ctx, node, key = \\"\\") { - const b2 = component(\`ComponentC\`, {fromA: ctx['props'].fromA, fromB: ctx['state'].fromB}, key + \`__1\`, node, ctx); + const b2 = component(\`ComponentC\`, {fromA: ctx['props'].fromA,fromB: ctx['state'].fromB}, key + \`__1\`, node, ctx); return block1([], [b2]); } }" @@ -271,7 +271,7 @@ exports[`concurrent renderings scenario 2 2`] = ` let block1 = createBlock(\`

\`); return function template(ctx, node, key = \\"\\") { - const b2 = component(\`ComponentC\`, {fromA: ctx['props'].fromA, fromB: ctx['state'].fromB}, key + \`__1\`, node, ctx); + const b2 = component(\`ComponentC\`, {fromA: ctx['props'].fromA,fromB: ctx['state'].fromB}, key + \`__1\`, node, ctx); return block1([], [b2]); } }" @@ -314,7 +314,7 @@ exports[`concurrent renderings scenario 2bis 2`] = ` let block1 = createBlock(\`

\`); return function template(ctx, node, key = \\"\\") { - const b2 = component(\`ComponentC\`, {fromA: ctx['props'].fromA, fromB: ctx['state'].fromB}, key + \`__1\`, node, ctx); + const b2 = component(\`ComponentC\`, {fromA: ctx['props'].fromA,fromB: ctx['state'].fromB}, key + \`__1\`, node, ctx); return block1([], [b2]); } }" @@ -371,7 +371,7 @@ exports[`concurrent renderings scenario 3 3`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = component(\`ComponentD\`, {fromA: ctx['props'].fromA, fromC: ctx['state'].fromC}, key + \`__1\`, node, ctx); + const b2 = component(\`ComponentD\`, {fromA: ctx['props'].fromA,fromC: ctx['state'].fromC}, key + \`__1\`, node, ctx); return block1([], [b2]); } }" @@ -428,7 +428,7 @@ exports[`concurrent renderings scenario 4 3`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = component(\`ComponentD\`, {fromA: ctx['props'].fromA, fromC: ctx['state'].fromC}, key + \`__1\`, node, ctx); + const b2 = component(\`ComponentD\`, {fromA: ctx['props'].fromA,fromC: ctx['state'].fromC}, key + \`__1\`, node, ctx); return block1([], [b2]); } }" @@ -601,7 +601,7 @@ exports[`concurrent renderings scenario 9 3`] = ` let block1 = createBlock(\`

\`); return function template(ctx, node, key = \\"\\") { - const b2 = component(\`ComponentD\`, {fromA: ctx['props'].fromA, fromC: ctx['state'].fromC}, key + \`__1\`, node, ctx); + const b2 = component(\`ComponentD\`, {fromA: ctx['props'].fromA,fromC: ctx['state'].fromC}, key + \`__1\`, node, ctx); return block1([], [b2]); } }" @@ -778,7 +778,7 @@ exports[`concurrent renderings scenario 14 2`] = ` let block1 = createBlock(\`

\`); return function template(ctx, node, key = \\"\\") { - const b2 = component(\`C\`, {fromB: ctx['state'].fromB, fromA: ctx['props'].fromA}, key + \`__1\`, node, ctx); + const b2 = component(\`C\`, {fromB: ctx['state'].fromB,fromA: ctx['props'].fromA}, key + \`__1\`, node, ctx); return block1([], [b2]); } }" @@ -822,7 +822,7 @@ exports[`concurrent renderings scenario 15 2`] = ` let block1 = createBlock(\`

\`); return function template(ctx, node, key = \\"\\") { - const b2 = component(\`C\`, {fromB: ctx['state'].fromB, fromA: ctx['props'].fromA}, key + \`__1\`, node, ctx); + const b2 = component(\`C\`, {fromB: ctx['state'].fromB,fromA: ctx['props'].fromA}, key + \`__1\`, node, ctx); return block1([], [b2]); } }" @@ -861,7 +861,7 @@ exports[`concurrent renderings scenario 16 2`] = ` let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; return function template(ctx, node, key = \\"\\") { - return component(\`C\`, {fromB: ctx['state'].fromB, fromA: ctx['props'].fromA}, key + \`__1\`, node, ctx); + return component(\`C\`, {fromB: ctx['state'].fromB,fromA: ctx['props'].fromA}, key + \`__1\`, node, ctx); } }" `; diff --git a/tests/components/__snapshots__/error_handling.test.ts.snap b/tests/components/__snapshots__/error_handling.test.ts.snap index 37efac99..d2651558 100644 --- a/tests/components/__snapshots__/error_handling.test.ts.snap +++ b/tests/components/__snapshots__/error_handling.test.ts.snap @@ -197,7 +197,7 @@ exports[`can catch errors can catch an error in a component render function 2`] if (ctx['state'].error) { b2 = text(\`Error handled\`); } else { - b3 = callSlot(ctx, node, key, 'default', false, null); + b3 = callSlot(ctx, node, key, 'default', false, {}); } return block1([], [b2, b3]); } @@ -250,7 +250,7 @@ exports[`can catch errors can catch an error in the constructor call of a compon if (ctx['state'].error) { b2 = text(\`Error handled\`); } else { - b3 = callSlot(ctx, node, key, 'default', false, null); + b3 = callSlot(ctx, node, key, 'default', false, {}); } return block1([], [b2, b3]); } @@ -291,7 +291,7 @@ exports[`can catch errors can catch an error in the constructor call of a compon if (ctx['state'].error) { b2 = text(\`Error handled\`); } else { - b3 = callSlot(ctx, node, key, 'default', false, null); + b3 = callSlot(ctx, node, key, 'default', false, {}); } return block1([], [b2, b3]); } @@ -369,7 +369,7 @@ exports[`can catch errors can catch an error in the initial call of a component if (ctx['state'].error) { b2 = text(\`Error handled\`); } else { - b3 = callSlot(ctx, node, key, 'default', false, null); + b3 = callSlot(ctx, node, key, 'default', false, {}); } return block1([], [b2, b3]); } @@ -425,7 +425,7 @@ exports[`can catch errors can catch an error in the initial call of a component if (ctx['state'].error) { b2 = text(\`Error handled\`); } else { - b3 = callSlot(ctx, node, key, 'default', false, null); + b3 = callSlot(ctx, node, key, 'default', false, {}); } return block1([], [b2, b3]); } @@ -567,7 +567,7 @@ exports[`can catch errors can catch an error in the mounted call 2`] = ` if (ctx['state'].error) { b2 = text(\`Error handled\`); } else { - b3 = callSlot(ctx, node, key, 'default', false, null); + b3 = callSlot(ctx, node, key, 'default', false, {}); } return block1([], [b2, b3]); } @@ -620,7 +620,7 @@ exports[`can catch errors can catch an error in the willPatch call 2`] = ` if (ctx['state'].error) { b2 = text(\`Error handled\`); } else { - b3 = callSlot(ctx, node, key, 'default', false, null); + b3 = callSlot(ctx, node, key, 'default', false, {}); } return block1([], [b2, b3]); } @@ -673,7 +673,7 @@ exports[`can catch errors can catch an error in the willStart call 2`] = ` if (ctx['state'].error) { b2 = text(\`Error handled\`); } else { - b3 = callSlot(ctx, node, key, 'default', false, null); + b3 = callSlot(ctx, node, key, 'default', false, {}); } return block1([], [b2, b3]); } @@ -727,7 +727,7 @@ exports[`can catch errors can catch an error origination from a child's willStar if (ctx['state'].error) { b2 = text(\`Error handled\`); } else { - b3 = callSlot(ctx, node, key, 'default', false, null); + b3 = callSlot(ctx, node, key, 'default', false, {}); } return block1([], [b2, b3]); } @@ -840,7 +840,7 @@ exports[`can catch errors catching error, rethrow, render parent -- a main comp let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } }" `; @@ -915,7 +915,7 @@ exports[`can catch errors catching in child makes parent render 2`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } }" `; @@ -991,7 +991,7 @@ exports[`can catch errors error in mounted on a component with a sibling (proper if (ctx['state'].error) { b2 = text(\`Error handled\`); } else { - b3 = callSlot(ctx, node, key, 'default', false, null); + b3 = callSlot(ctx, node, key, 'default', false, {}); } return block1([], [b2, b3]); } diff --git a/tests/components/__snapshots__/props.test.ts.snap b/tests/components/__snapshots__/props.test.ts.snap index f49c4214..628aa107 100644 --- a/tests/components/__snapshots__/props.test.ts.snap +++ b/tests/components/__snapshots__/props.test.ts.snap @@ -273,7 +273,7 @@ exports[`bound functions is referentially equal after update 1`] = ` let { bind } = helpers; return function template(ctx, node, key = \\"\\") { - return component(\`Child\`, {val: ctx['state'].val, fn: bind(ctx, ctx['someFunction'])}, key + \`__1\`, node, ctx); + return component(\`Child\`, {val: ctx['state'].val,fn: bind(ctx, ctx['someFunction'])}, key + \`__1\`, node, ctx); } }" `; diff --git a/tests/components/__snapshots__/props_validation.test.ts.snap b/tests/components/__snapshots__/props_validation.test.ts.snap index f2075064..17745bac 100644 --- a/tests/components/__snapshots__/props_validation.test.ts.snap +++ b/tests/components/__snapshots__/props_validation.test.ts.snap @@ -115,7 +115,7 @@ exports[`props validation can specify that additional props are allowed (array) let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; return function template(ctx, node, key = \\"\\") { - const props1 = {message: 'm', otherProp: 'o'}; + const props1 = {message: 'm',otherProp: 'o'}; helpers.validateProps(\`Child\`, props1, ctx); return component(\`Child\`, props1, key + \`__1\`, node, ctx); } @@ -141,7 +141,7 @@ exports[`props validation can specify that additional props are allowed (object) let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; return function template(ctx, node, key = \\"\\") { - const props1 = {message: 'm', otherProp: 'o'}; + const props1 = {message: 'm',otherProp: 'o'}; helpers.validateProps(\`Child\`, props1, ctx); return component(\`Child\`, props1, key + \`__1\`, node, ctx); } diff --git a/tests/components/__snapshots__/reactivity.test.ts.snap b/tests/components/__snapshots__/reactivity.test.ts.snap index c60380e9..1bef1298 100644 --- a/tests/components/__snapshots__/reactivity.test.ts.snap +++ b/tests/components/__snapshots__/reactivity.test.ts.snap @@ -32,7 +32,7 @@ exports[`reactivity in lifecycle Component is automatically subscribed to reacti let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; return function template(ctx, node, key = \\"\\") { - return component(\`Child\`, {obj: ctx['obj'], reactiveObj: ctx['reactiveObj']}, key + \`__1\`, node, ctx); + return component(\`Child\`, {obj: ctx['obj'],reactiveObj: ctx['reactiveObj']}, key + \`__1\`, node, ctx); } }" `; diff --git a/tests/components/__snapshots__/refs.test.ts.snap b/tests/components/__snapshots__/refs.test.ts.snap index b458061d..fec35e93 100644 --- a/tests/components/__snapshots__/refs.test.ts.snap +++ b/tests/components/__snapshots__/refs.test.ts.snap @@ -92,7 +92,7 @@ exports[`refs refs are properly bound in slots 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'footer', false, null); + const b2 = callSlot(ctx, node, key, 'footer', false, {}); return block1([], [b2]); } }" diff --git a/tests/components/__snapshots__/slots.test.ts.snap b/tests/components/__snapshots__/slots.test.ts.snap index 7cac48a8..e3ebe243 100644 --- a/tests/components/__snapshots__/slots.test.ts.snap +++ b/tests/components/__snapshots__/slots.test.ts.snap @@ -27,7 +27,7 @@ exports[`slots can define a default content 2`] = ` } return function template(ctx, node, key = \\"\\") { - const b3 = callSlot(ctx, node, key, 'default', false, null, defaultContent1); + const b3 = callSlot(ctx, node, key, 'default', false, {}, defaultContent1); return block1([], [b3]); } }" @@ -68,8 +68,8 @@ exports[`slots can define and call slots 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'header', false, null); - const b3 = callSlot(ctx, node, key, 'footer', false, null); + const b2 = callSlot(ctx, node, key, 'header', false, {}); + const b3 = callSlot(ctx, node, key, 'footer', false, {}); return block1([], [b2, b3]); } }" @@ -99,7 +99,7 @@ exports[`slots can define and call slots with bound params 2`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'abc', false, null); + const b2 = callSlot(ctx, node, key, 'abc', false, {}); const b3 = text(ctx['props'].slots['abc'].getValue()); return multi([b2, b3]); } @@ -142,9 +142,9 @@ exports[`slots can define and call slots with params 2`] = ` return function template(ctx, node, key = \\"\\") { let txt1 = ctx['props'].slots['header'].param; - const b2 = callSlot(ctx, node, key, 'header', false, null); + const b2 = callSlot(ctx, node, key, 'header', false, {}); let txt2 = ctx['props'].slots['footer'].param; - const b3 = callSlot(ctx, node, key, 'footer', false, null); + const b3 = callSlot(ctx, node, key, 'footer', false, {}); return block1([txt1, txt2], [b2, b3]); } }" @@ -179,7 +179,7 @@ exports[`slots can render node with t-ref and Component in same slot 2`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } }" `; @@ -191,7 +191,7 @@ exports[`slots can render only empty slot 1`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } }" `; @@ -218,7 +218,7 @@ exports[`slots can use component in default-content of t-slot 2`] = ` } return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null, defaultContent1); + return callSlot(ctx, node, key, 'default', false, {}, defaultContent1); } }" `; @@ -257,7 +257,7 @@ exports[`slots can use t-call in default-content of t-slot 2`] = ` } return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null, defaultContent1); + return callSlot(ctx, node, key, 'default', false, {}, defaultContent1); } }" `; @@ -298,7 +298,7 @@ exports[`slots content is the default slot (variation) 2`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } }" `; @@ -332,7 +332,7 @@ exports[`slots content is the default slot 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -371,7 +371,7 @@ exports[`slots default content is not rendered if named slot is provided 2`] = ` } return function template(ctx, node, key = \\"\\") { - const b3 = callSlot(ctx, node, key, 'header', false, null, defaultContent1); + const b3 = callSlot(ctx, node, key, 'header', false, {}, defaultContent1); return block1([], [b3]); } }" @@ -409,7 +409,7 @@ exports[`slots default content is not rendered if slot is provided 2`] = ` } return function template(ctx, node, key = \\"\\") { - const b3 = callSlot(ctx, node, key, 'default', false, null, defaultContent1); + const b3 = callSlot(ctx, node, key, 'default', false, {}, defaultContent1); return block1([], [b3]); } }" @@ -452,8 +452,8 @@ exports[`slots default slot next to named slot, with default content 2`] = ` } return function template(ctx, node, key = \\"\\") { - const b3 = callSlot(ctx, node, key, 'default', false, null, defaultContent1); - const b5 = callSlot(ctx, node, key, 'footer', false, null, defaultContent2); + const b3 = callSlot(ctx, node, key, 'default', false, {}, defaultContent1); + const b5 = callSlot(ctx, node, key, 'footer', false, {}, defaultContent2); return block1([], [b3, b5]); } }" @@ -547,7 +547,7 @@ exports[`slots default slot work with text nodes (variation) 2`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } }" `; @@ -580,7 +580,7 @@ exports[`slots default slot work with text nodes 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -626,7 +626,7 @@ exports[`slots dynamic t-slot call 2`] = ` return function template(ctx, node, key = \\"\\") { let hdlr1 = [ctx['toggle'], ctx]; const slot1 = (ctx['current'].slot); - const b2 = toggler(slot1, callSlot(ctx, node, key, slot1, true, null)); + const b2 = toggler(slot1, callSlot(ctx, node, key, slot1, true, {})); return block1([hdlr1], [b2]); } }" @@ -675,7 +675,7 @@ exports[`slots dynamic t-slot call with default 2`] = ` return function template(ctx, node, key = \\"\\") { let hdlr1 = [ctx['toggle'], ctx]; - const b3 = callSlot(ctx, node, key, (ctx['current'].slot), true, null, defaultContent1); + const b3 = callSlot(ctx, node, key, (ctx['current'].slot), true, {}, defaultContent1); return block1([hdlr1], [b3]); } }" @@ -704,8 +704,8 @@ exports[`slots fun: two calls to the same slot 2`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); - const b3 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); + const b3 = callSlot(ctx, node, key, 'default', false, {}); return multi([b2, b3]); } }" @@ -734,8 +734,8 @@ exports[`slots missing slots are ignored 2`] = ` let block1 = createBlock(\`some content\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); - const b3 = callSlot(ctx, node, key, 'footer', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); + const b3 = callSlot(ctx, node, key, 'footer', false, {}); return block1([], [b2, b3]); } }" @@ -844,7 +844,7 @@ exports[`slots mix of slots, t-call, t-call with body, and giving own props chil return function template(ctx, node, key = \\"\\") { const b2 = text(\`[C]\`); - const b3 = callSlot(ctx, node, key, 'default', false, null); + const b3 = callSlot(ctx, node, key, 'default', false, {}); return multi([b2, b3]); } }" @@ -882,7 +882,7 @@ exports[`slots multiple roots are allowed in a default slot 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -921,7 +921,7 @@ exports[`slots multiple roots are allowed in a named slot 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'content', false, null); + const b2 = callSlot(ctx, node, key, 'content', false, {}); return block1([], [b2]); } }" @@ -957,8 +957,8 @@ exports[`slots multiple slots containing components 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 's1', false, null); - const b3 = callSlot(ctx, node, key, 's2', false, null); + const b2 = callSlot(ctx, node, key, 's1', false, {}); + const b3 = callSlot(ctx, node, key, 's2', false, {}); return block1([], [b2, b3]); } }" @@ -1020,8 +1020,8 @@ exports[`slots named slot inside slot 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'brol', false, null); - const b3 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'brol', false, {}); + const b3 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2, b3]); } }" @@ -1069,8 +1069,8 @@ exports[`slots named slot inside slot, part 3 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'brol', false, null); - const b3 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'brol', false, {}); + const b3 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2, b3]); } }" @@ -1103,7 +1103,7 @@ exports[`slots named slots can define a default content 2`] = ` } return function template(ctx, node, key = \\"\\") { - const b3 = callSlot(ctx, node, key, 'header', false, null, defaultContent1); + const b3 = callSlot(ctx, node, key, 'header', false, {}, defaultContent1); return block1([], [b3]); } }" @@ -1159,9 +1159,9 @@ exports[`slots named slots inside slot, again 2`] = ` } return function template(ctx, node, key = \\"\\") { - const b3 = callSlot(ctx, node, key, 'brol1', false, null, defaultContent1); - const b5 = callSlot(ctx, node, key, 'brol2', false, null, defaultContent2); - const b6 = callSlot(ctx, node, key, 'default', false, null); + const b3 = callSlot(ctx, node, key, 'brol1', false, {}, defaultContent1); + const b5 = callSlot(ctx, node, key, 'brol2', false, {}, defaultContent2); + const b6 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b3, b5, b6]); } }" @@ -1199,7 +1199,7 @@ exports[`slots nested slots in same template 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -1214,7 +1214,7 @@ exports[`slots nested slots in same template 3`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -1256,7 +1256,7 @@ exports[`slots nested slots: evaluation context and parented relationship 2`] = let { callSlot, markRaw } = helpers; function slot1(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } return function template(ctx, node, key = \\"\\") { @@ -1274,7 +1274,7 @@ exports[`slots nested slots: evaluation context and parented relationship 3`] = let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -1314,7 +1314,7 @@ exports[`slots no named slot content => just no children 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'header', false, null); + const b2 = callSlot(ctx, node, key, 'header', false, {}); return block1([], [b2]); } }" @@ -1345,7 +1345,7 @@ exports[`slots simple default slot 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -1439,7 +1439,7 @@ exports[`slots simple default slot, variation 2`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } }" `; @@ -1509,7 +1509,7 @@ exports[`slots simple named and empty slot -- 2 2`] = ` } return function template(ctx, node, key = \\"\\") { - const b3 = callSlot(ctx, node, key, 'myEmptySlot', false, null, defaultContent1); + const b3 = callSlot(ctx, node, key, 'myEmptySlot', false, {}, defaultContent1); return block1([], [b3]); } }" @@ -1541,8 +1541,8 @@ exports[`slots simple named and empty slot 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); - const b3 = callSlot(ctx, node, key, 'myEmptySlot', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); + const b3 = callSlot(ctx, node, key, 'myEmptySlot', false, {}); return block1([], [b2, b3]); } }" @@ -1629,7 +1629,7 @@ exports[`slots slot and (inline) t-call 3`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -1678,7 +1678,7 @@ exports[`slots slot and t-call 3`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -1712,7 +1712,7 @@ exports[`slots slot and t-esc 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -1748,7 +1748,7 @@ exports[`slots slot are properly rendered if inner props are changed 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -1793,7 +1793,7 @@ exports[`slots slot content has different key from other content -- dynamic slot return function template(ctx, node, key = \\"\\") { const b2 = component(\`Child\`, {parent: 'SlotDisplay'}, key + \`__1\`, node, ctx); const slot1 = (ctx['slotName']); - const b3 = toggler(slot1, callSlot(ctx, node, key, slot1, true, null)); + const b3 = toggler(slot1, callSlot(ctx, node, key, slot1, true, {})); return multi([b2, b3]); } }" @@ -1837,7 +1837,7 @@ exports[`slots slot content has different key from other content -- static slot return function template(ctx, node, key = \\"\\") { const b2 = component(\`Child\`, {parent: 'SlotDisplay'}, key + \`__1\`, node, ctx); - const b3 = callSlot(ctx, node, key, 'default', false, null); + const b3 = callSlot(ctx, node, key, 'default', false, {}); return multi([b2, b3]); } }" @@ -1889,7 +1889,7 @@ exports[`slots slot content is bound to caller (variation) 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -1923,7 +1923,7 @@ exports[`slots slot content is bound to caller 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -1955,7 +1955,7 @@ exports[`slots slot preserves properly parented relationship 2`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } }" `; @@ -2010,7 +2010,7 @@ exports[`slots slot preserves properly parented relationship, even through t-cal let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } }" `; @@ -2026,6 +2026,42 @@ exports[`slots slot preserves properly parented relationship, even through t-cal }" `; +exports[`slots slot with slot scope and t-props 1`] = ` +"function anonymous(app, bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + let { capture, markRaw } = helpers; + + let block2 = createBlock(\`

\`); + let block3 = createBlock(\`

\`); + + function slot1(ctx, node, key = \\"\\") { + let txt1 = ctx['info'].a; + const b2 = block2([txt1]); + let txt2 = ctx['info'].b; + const b3 = block3([txt2]); + return multi([b2, b3]); + } + + return function template(ctx, node, key = \\"\\") { + const ctx1 = capture(ctx); + return component(\`Child\`, {slots: markRaw({'slotName': {__render: slot1, __ctx: ctx1, __scope: \\"info\\"}})}, key + \`__1\`, node, ctx); + } +}" +`; + +exports[`slots slot with slot scope and t-props 2`] = ` +"function anonymous(app, bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + let { callSlot } = helpers; + + return function template(ctx, node, key = \\"\\") { + return callSlot(ctx, node, key, 'slotName', false, Object.assign({}, ctx['info'])); + } +}" +`; + exports[`slots slots and wrapper components 1`] = ` "function anonymous(app, bdom, helpers ) { @@ -2051,7 +2087,7 @@ exports[`slots slots and wrapper components 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -2086,7 +2122,7 @@ exports[`slots slots are properly bound to correct component 2`] = ` } return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null, defaultContent1); + return callSlot(ctx, node, key, 'default', false, {}, defaultContent1); } }" `; @@ -2123,7 +2159,7 @@ exports[`slots slots are rendered with proper context 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'footer', false, null); + const b2 = callSlot(ctx, node, key, 'footer', false, {}); return block1([], [b2]); } }" @@ -2170,7 +2206,7 @@ exports[`slots slots are rendered with proper context, part 2 2`] = ` return function template(ctx, node, key = \\"\\") { let attr1 = ctx['props'].to; - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([attr1], [b2]); } }" @@ -2218,7 +2254,7 @@ exports[`slots slots are rendered with proper context, part 3 2`] = ` return function template(ctx, node, key = \\"\\") { let attr1 = ctx['props'].to; - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([attr1], [b2]); } }" @@ -2257,7 +2293,7 @@ exports[`slots slots are rendered with proper context, part 4 2`] = ` return function template(ctx, node, key = \\"\\") { let attr1 = ctx['props'].to; - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([attr1], [b2]); } }" @@ -2297,7 +2333,7 @@ exports[`slots slots in slots, with vars 2`] = ` let block1 = createBlock(\`
\`); function slot1(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } return function template(ctx, node, key = \\"\\") { @@ -2316,7 +2352,7 @@ exports[`slots slots in slots, with vars 3`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -2360,7 +2396,7 @@ exports[`slots slots in t-foreach and re-rendering 2`] = ` return function template(ctx, node, key = \\"\\") { let txt1 = ctx['state'].val; - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([txt1], [b2]); } }" @@ -2418,7 +2454,7 @@ exports[`slots slots in t-foreach in t-foreach 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -2465,7 +2501,7 @@ exports[`slots slots in t-foreach with t-set and re-rendering 2`] = ` return function template(ctx, node, key = \\"\\") { let txt1 = ctx['state'].val; - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([txt1], [b2]); } }" @@ -2501,7 +2537,7 @@ exports[`slots t-debug on a t-set-slot (defining a slot) 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'content', false, null); + const b2 = callSlot(ctx, node, key, 'content', false, {}); return block1([], [b2]); } }" @@ -2539,7 +2575,7 @@ exports[`slots t-set t-value in a slot 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -2599,7 +2635,7 @@ exports[`slots t-slot in recursive templates 2`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -2637,7 +2673,7 @@ exports[`slots t-slot nested within another slot 2`] = ` } function slot2(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } return function template(ctx, node, key = \\"\\") { @@ -2656,7 +2692,7 @@ exports[`slots t-slot nested within another slot 3`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -2671,7 +2707,7 @@ exports[`slots t-slot nested within another slot 4`] = ` let block1 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -2718,7 +2754,7 @@ exports[`slots t-slot scope context 2`] = ` function slot1(ctx, node, key = \\"\\") { let hdlr1 = [ctx['onClick'], ctx]; - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([hdlr1], [b2]); } @@ -2735,7 +2771,7 @@ exports[`slots t-slot scope context 3`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } }" `; @@ -2771,7 +2807,7 @@ exports[`slots t-slot within dynamic t-call 2`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = callSlot(ctx, node, key, 'default', false, null); + const b2 = callSlot(ctx, node, key, 'default', false, {}); return block1([], [b2]); } }" @@ -2830,7 +2866,7 @@ exports[`slots template can just return a slot 2`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } }" `; diff --git a/tests/components/__snapshots__/style_class.test.ts.snap b/tests/components/__snapshots__/style_class.test.ts.snap index cf3b1253..7f426477 100644 --- a/tests/components/__snapshots__/style_class.test.ts.snap +++ b/tests/components/__snapshots__/style_class.test.ts.snap @@ -147,7 +147,7 @@ exports[`style and class handling class on sub component, which is switched to a let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; return function template(ctx, node, key = \\"\\") { - return component(\`Child\`, {class: 'someclass', child: ctx['state'].child}, key + \`__1\`, node, ctx); + return component(\`Child\`, {class: 'someclass',child: ctx['state'].child}, key + \`__1\`, node, ctx); } }" `; diff --git a/tests/components/__snapshots__/t_foreach.test.ts.snap b/tests/components/__snapshots__/t_foreach.test.ts.snap index a1d847ab..02eb86f1 100644 --- a/tests/components/__snapshots__/t_foreach.test.ts.snap +++ b/tests/components/__snapshots__/t_foreach.test.ts.snap @@ -177,7 +177,7 @@ exports[`list of components reconciliation alg works for t-foreach in t-foreach, for (let i2 = 0; i2 < l_block4; i2++) { ctx[\`col\`] = v_block4[i2]; const key2 = ctx['col']; - const b6 = component(\`Child\`, {row: ctx['row'], col: ctx['col']}, key + \`__1__\${key1}__\${key2}\`, node, ctx); + const b6 = component(\`Child\`, {row: ctx['row'],col: ctx['col']}, key + \`__1__\${key1}__\${key2}\`, node, ctx); c_block4[i2] = withKey(block5([], [b6]), key2); } ctx = ctx.__proto__; diff --git a/tests/components/__snapshots__/t_on.test.ts.snap b/tests/components/__snapshots__/t_on.test.ts.snap index d89228d3..a04f55c2 100644 --- a/tests/components/__snapshots__/t_on.test.ts.snap +++ b/tests/components/__snapshots__/t_on.test.ts.snap @@ -366,7 +366,7 @@ exports[`t-on t-on on slot, with 'prevent' modifier 2`] = ` return function template(ctx, node, key = \\"\\") { const hdlr1 = [\\"prevent\\", ctx['doSomething'], ctx]; - return catcher1(callSlot(ctx, node, key, 'default', false, null), [hdlr1]); + return catcher1(callSlot(ctx, node, key, 'default', false, {}), [hdlr1]); } }" `; @@ -406,7 +406,7 @@ exports[`t-on t-on on t-set-slots 2`] = ` let { callSlot } = helpers; return function template(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'myslot', false, null); + return callSlot(ctx, node, key, 'myslot', false, {}); } }" `; @@ -441,7 +441,7 @@ exports[`t-on t-on on t-slots 2`] = ` const b3 = text(ctx['state'].count); const b4 = text(\`] \`); const hdlr1 = [()=>this.state.count++, ctx]; - const b5 = catcher1(callSlot(ctx, node, key, 'default', false, null), [hdlr1]); + const b5 = catcher1(callSlot(ctx, node, key, 'default', false, {}), [hdlr1]); return multi([b2, b3, b4, b5]); } }" diff --git a/tests/components/__snapshots__/t_props.test.ts.snap b/tests/components/__snapshots__/t_props.test.ts.snap index b0b044ef..0fb53589 100644 --- a/tests/components/__snapshots__/t_props.test.ts.snap +++ b/tests/components/__snapshots__/t_props.test.ts.snap @@ -117,7 +117,7 @@ exports[`t-props t-props with props 1`] = ` let block1 = createBlock(\`
\`); return function template(ctx, node, key = \\"\\") { - const b2 = component(\`Child\`, Object.assign({}, ctx['childProps'], {a: 1, b: 2}), key + \`__1\`, node, ctx); + const b2 = component(\`Child\`, Object.assign({}, ctx['childProps'], {a: 1,b: 2}), key + \`__1\`, node, ctx); return block1([], [b2]); } }" diff --git a/tests/components/__snapshots__/t_set.test.ts.snap b/tests/components/__snapshots__/t_set.test.ts.snap index e273da0d..fe765c84 100644 --- a/tests/components/__snapshots__/t_set.test.ts.snap +++ b/tests/components/__snapshots__/t_set.test.ts.snap @@ -81,7 +81,7 @@ exports[`t-set slots with a t-set with a component in body 2`] = ` return function template(ctx, node, key = \\"\\") { const b2 = text(\`Child \`); - const b3 = callSlot(ctx, node, key, 'default', false, null); + const b3 = callSlot(ctx, node, key, 'default', false, {}); return multi([b2, b3]); } }" @@ -136,7 +136,7 @@ exports[`t-set slots with an t-set with a component in body 2`] = ` return function template(ctx, node, key = \\"\\") { const b2 = text(\`Blorg \`); - const b3 = callSlot(ctx, node, key, 'default', false, null); + const b3 = callSlot(ctx, node, key, 'default', false, {}); return multi([b2, b3]); } }" @@ -185,7 +185,7 @@ exports[`t-set slots with an unused t-set with a component in body 2`] = ` return function template(ctx, node, key = \\"\\") { const b2 = text(\`Child \`); - const b3 = callSlot(ctx, node, key, 'default', false, null); + const b3 = callSlot(ctx, node, key, 'default', false, {}); return multi([b2, b3]); } }" diff --git a/tests/components/slots.test.ts b/tests/components/slots.test.ts index 26e20600..370be644 100644 --- a/tests/components/slots.test.ts +++ b/tests/components/slots.test.ts @@ -74,6 +74,28 @@ describe("slots", () => { expect(fixture.innerHTML).toBe("other text"); }); + test("slot with slot scope and t-props", async () => { + class Child extends Component { + static template = xml` + `; + info = { a: 1, b: 2 }; + } + + class Parent extends Component { + static template = xml` + + +

+

+ + `; + static components = { Child }; + } + + await mount(Parent, fixture); + expect(fixture.innerHTML).toBe("

1

2

"); + }); + test("simple dynamic slot with slot scope", async () => { let child: any; class Child extends Component { diff --git a/tests/misc/__snapshots__/portal.test.ts.snap b/tests/misc/__snapshots__/portal.test.ts.snap index 18193e46..026d62b1 100644 --- a/tests/misc/__snapshots__/portal.test.ts.snap +++ b/tests/misc/__snapshots__/portal.test.ts.snap @@ -177,7 +177,7 @@ exports[`Portal Portal composed with t-slot 2`] = ` const Portal = app.Portal; function slot1(ctx, node, key = \\"\\") { - return callSlot(ctx, node, key, 'default', false, null); + return callSlot(ctx, node, key, 'default', false, {}); } return function template(ctx, node, key = \\"\\") {