Skip to content

Commit

Permalink
Fix global and vars interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Nov 24, 2023
1 parent c25fc94 commit 3727be0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 5 additions & 5 deletions packages/solid-styled/compiler/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,7 @@ function processJSXTemplate(
sheet.count = current;

const computedVars = variables.length
? t.callExpression(
generateVars(ctx, path, functionParent),
[t.arrowFunctionExpression([], t.objectExpression(variables))],
)
? t.arrowFunctionExpression([], t.objectExpression(variables))
: undefined;
if (isGlobal) {
const args: t.Expression[] = [
Expand Down Expand Up @@ -293,7 +290,10 @@ function processJSXTemplate(
);
statement.insertBefore(t.expressionStatement(
computedVars
? t.sequenceExpression([setup, computedVars])
? t.sequenceExpression([setup, t.callExpression(
generateVars(ctx, path, functionParent),
[computedVars],
)])
: setup,
));
}
Expand Down
12 changes: 5 additions & 7 deletions packages/solid-styled/test/__snapshots__/jsx.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default function Example() {
`;
exports[`jsx > should transform dynamic templates 1`] = `
"import { useSolidStyled as _useSolidStyled } from \\"solid-styled\\";
import { createCSSVars as _createCSSVars } from \\"solid-styled\\";
"import { createCSSVars as _createCSSVars } from \\"solid-styled\\";
import { useSolidStyled as _useSolidStyled } from \\"solid-styled\\";
const _sheet = \\"c-f0b3b6fa-0\\";
const _css = \\"h1[s\\\\\\\\:c-f0b3b6fa-0]{color:var(--s-v-f0b3b6fa-1)}\\";
export default function Example() {
Expand Down Expand Up @@ -62,17 +62,15 @@ export default function Example() {
exports[`jsx.global > should transform dynamic templates 1`] = `
"import { useSolidStyledGlobal as _useSolidStyledGlobal } from \\"solid-styled\\";
import { createCSSVars as _createCSSVars } from \\"solid-styled\\";
const _sheet = \\"c-f0b3b6fa-0\\";
const _css = \\"h1{color:var(--s-v-f0b3b6fa-1)}\\";
export default function Example() {
const _vars = _createCSSVars();
_useSolidStyledGlobal(_sheet, 1, _css, _vars(() => ({
_useSolidStyledGlobal(_sheet, 1, _css, () => ({
\\"--s-v-f0b3b6fa-1\\": props.color
})));
}));
return <>
<h1 s:c-f0b3b6fa-0 style={_vars()}>Hello World</h1>
<h1 s:c-f0b3b6fa-0>Hello World</h1>
</>;
}"
`;
Expand Down

0 comments on commit 3727be0

Please sign in to comment.