From c924fba182739c1db3b4cf2948c54d60d8dc936c Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:25:04 +0200 Subject: [PATCH] fix: handle boolean css var (#2350) #2324 --- packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts | 2 +- .../test/htmlx2jsx/samples/custom-css-properties/expectedv2.js | 2 +- .../test/htmlx2jsx/samples/custom-css-properties/input.svelte | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts index 12f3396ee..0ef4095cc 100644 --- a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts +++ b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts @@ -94,7 +94,7 @@ export function handleAttribute( element.addAttribute(name, value); } : (name: TransformationArray, value?: TransformationArray) => { - if (attr.name.startsWith('--') && attr.value !== true) { + if (attr.name.startsWith('--')) { // CSS custom properties are not part of the props // definition, so wrap them to not get "--xx is invalid prop" errors name.unshift('...__sveltets_2_cssProp({'); diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/custom-css-properties/expectedv2.js b/packages/svelte2tsx/test/htmlx2jsx/samples/custom-css-properties/expectedv2.js index 1968d107d..481e683cc 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/custom-css-properties/expectedv2.js +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/custom-css-properties/expectedv2.js @@ -1 +1 @@ - { const $$_tnenopmoC0C = __sveltets_2_ensureComponent(Component); new $$_tnenopmoC0C({ target: __sveltets_2_any(), props: { ...__sveltets_2_cssProp({"--custom-css-property1":'hi'}),...__sveltets_2_cssProp({"--custom-css-property2":`hi`}),"betweenprop":true,...__sveltets_2_cssProp({"--custom-css-property3":`hi${jo}hi`}),...__sveltets_2_cssProp({"--custom-css-property4":`hi${jo}hi`}),...__sveltets_2_cssProp({"--custom-css-property5":`hi${jo}hi`}),}});} \ No newline at end of file + { const $$_tnenopmoC0C = __sveltets_2_ensureComponent(Component); new $$_tnenopmoC0C({ target: __sveltets_2_any(), props: { ...__sveltets_2_cssProp({"--custom-css-property1":'hi'}),...__sveltets_2_cssProp({"--custom-css-property2":`hi`}),"betweenprop":true,...__sveltets_2_cssProp({"--custom-css-property3":`hi${jo}hi`}),...__sveltets_2_cssProp({"--custom-css-property4":`hi${jo}hi`}),...__sveltets_2_cssProp({"--custom-css-property5":`hi${jo}hi`}),...__sveltets_2_cssProp({"--custom-css-property6":true}),}});} \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/custom-css-properties/input.svelte b/packages/svelte2tsx/test/htmlx2jsx/samples/custom-css-properties/input.svelte index 22f7f271b..316a0d999 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/custom-css-properties/input.svelte +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/custom-css-properties/input.svelte @@ -4,4 +4,5 @@ betweenprop --custom-css-property3="hi{jo}hi" --custom-css-property4='hi{jo}hi' - --custom-css-property5=hi{jo}hi /> + --custom-css-property5=hi{jo}hi + --custom-css-property6 />