From 30cb0973c4624874eecbc1d4f48d0ddf4041b2fd Mon Sep 17 00:00:00 2001 From: deefco Date: Sat, 10 Sep 2022 01:32:05 +0200 Subject: [PATCH] Make the jsx parser pass child elements as parameters --- packages/utils.jsx/src/jsx.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/utils.jsx/src/jsx.ts b/packages/utils.jsx/src/jsx.ts index 7836a8e64..b9ab62a61 100644 --- a/packages/utils.jsx/src/jsx.ts +++ b/packages/utils.jsx/src/jsx.ts @@ -1,4 +1,5 @@ +import { attr } from '@tko/binding.core/src/attr' import { isObservable, unwrap } from '@tko/observable' @@ -45,10 +46,21 @@ export function getOriginalJsxForNode (node) { * @param {...string|object} c children of the element */ export function createElement (elementName, attributes, ...children) { + const internalAttributes = attributes || {}; + if(internalAttributes.hasOwnProperty('children')) { + console.error( + "%s: `children` cannot be used as an attribute. It gets automatically bound to the child elements of this component. " + + "If you want to access the same value within the child component, you should pass it as a different attribute.", + elementName + ); + } + + internalAttributes.children = [...children] || [] + return elementName === Fragment ? children : { elementName: elementName, - attributes: attributes || {}, + attributes: internalAttributes, children: [...children] } }