Skip to content

Commit f0533be

Browse files
cqh963852askoufis
andauthored
fix: add Primitive to Serializable (#1596)
Co-authored-by: Adam Skoufis <[email protected]> Co-authored-by: Adam Skoufis <[email protected]>
1 parent 075e9a1 commit f0533be

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

.changeset/gentle-timers-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/css': patch
3+
---
4+
5+
`addFunctionSerializer`: Fix `args` type to support arrays of primitive values

packages/css/src/functionSerializer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type Primitive = string | number | boolean | null | undefined;
22

33
type Serializable =
4+
| Primitive
45
| {
56
[Key in string | number]: Primitive | Serializable;
67
}

packages/integration/src/processVanillaFile.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { addFunctionSerializer } from '../../css/src/functionSerializer';
12
import { serializeVanillaModule } from './processVanillaFile';
23

34
describe('serializeVanillaModule', () => {
@@ -138,6 +139,28 @@ describe('serializeVanillaModule', () => {
138139
`);
139140
});
140141

142+
test('should handle deprecated __recipe__ function serialization', () => {
143+
const sprinkles = () => {};
144+
// Once support for `__recipe__` is removed, this test can be removed,
145+
// and all other tests that use `__function_serializer__` should be updated
146+
// to use `addFunctionSerializer`
147+
addFunctionSerializer(sprinkles, {
148+
importPath: 'my-package',
149+
importName: 'myFunction',
150+
args: ['arg1', 'arg2'],
151+
});
152+
const exports = {
153+
sprinkles,
154+
};
155+
156+
expect(serializeVanillaModule(['import "./styles.css"'], exports, null))
157+
.toMatchInlineSnapshot(`
158+
"import "./styles.css"
159+
import { myFunction as _86bce } from 'my-package';
160+
export var sprinkles = _86bce('arg1','arg2');"
161+
`);
162+
});
163+
141164
test('should re-use exports in handle serialized function args', () => {
142165
const complexExport = {
143166
my: {

0 commit comments

Comments
 (0)