Skip to content

Commit 1664dd9

Browse files
committed
implement block scoped eval ($macaron)
1 parent 1a4dfc4 commit 1664dd9

11 files changed

Lines changed: 510 additions & 6 deletions

File tree

examples/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"dependencies": {
1111
"react": "^18.2.0",
1212
"react-dom": "^18.2.0",
13-
"@macaron-css/core": "0.1.8",
13+
"@macaron-css/core": "0.1.9",
1414
"@macaron-css/vite": "0.1.12",
1515
"@macaron-css/react": "0.1.10"
1616
},

examples/solid-start/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"node": ">=14"
2222
},
2323
"dependencies": {
24-
"@macaron-css/core": "0.1.8",
24+
"@macaron-css/core": "0.1.9",
2525
"@macaron-css/vite": "0.1.12",
2626
"@macaron-css/solid": "0.1.9"
2727
}

examples/solid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@macaron-css/esbuild": "0.1.8",
1212
"@macaron-css/solid": "0.1.9",
1313
"babel-preset-solid": "^1.4.2",
14-
"@macaron-css/core": "0.1.8",
14+
"@macaron-css/core": "0.1.9",
1515
"esbuild": "^0.14.42",
1616
"solid-js": "^1.4.3"
1717
}

examples/vanilla/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"dependencies": {
77
"@macaron-css/esbuild": "0.1.8",
8-
"@macaron-css/core": "0.1.8",
8+
"@macaron-css/core": "0.1.9",
99
"esbuild": "^0.14.42"
1010
}
1111
}

examples/vite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"dependencies": {
1111
"@vanilla-extract/css": "^1.7.1",
12-
"@macaron-css/core": "0.1.8",
12+
"@macaron-css/core": "0.1.9",
1313
"@macaron-css/vite": "0.1.12"
1414
},
1515
"devDependencies": {

packages/babel/src/index.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ test('extracts style function', () => {
9595
expect(code).toMatchSnapshot();
9696
});
9797

98+
test('extracts $macaron function', () => {
99+
const { result, code } = babelTransform(`
100+
import { style, $macaron } from '@macaron-css/core';
101+
102+
const red = $macaron(() => {
103+
return style({ color: 'red' })
104+
});
105+
console.log(red);
106+
`);
107+
108+
expect(result).toMatchSnapshot();
109+
expect(code).toMatchSnapshot();
110+
});
111+
98112
test('multiple variable declarators in one declaration', () => {
99113
const { result, code } = babelTransform(`
100114
import { style } from '@macaron-css/core';

packages/babel/src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export function getNearestIdentifier(path: NodePath<t.Node>) {
6161
}
6262

6363
export const extractionAPIs = [
64+
// @macaron-css/core
65+
'$macaron',
6466
// @vanilla-extract/css
6567
'style',
6668
'styleVariants',

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@macaron-css/core",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"main": "dist/index.js",
55
"module": "dist/index.mjs",
66
"types": "dist/index.d.ts",

packages/core/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,7 @@ export function recipe<Variants extends VariantGroups>(
8080
args: [config],
8181
});
8282
}
83+
84+
export const $macaron = <T>(block: () => T) => {
85+
return block();
86+
};

packages/solid/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ export function styled<
3737
): StyledComponent<TProps, Variants>;
3838

3939
export function styled(component: any, options: any): (props: any) => any {
40+
// the following doesn't work because vanilla-extract's function serializer
41+
// cannot serialize complex functions like `$$styled`
42+
4043
// const runtimeFn = recipe(options);
4144

4245
// return addFunctionSerializer($$styled(component, runtimeFn as any), {
4346
// importPath: '@macaron-css/solid/runtime',
4447
// args: [component, runtimeFn],
4548
// importName: '$$styled',
4649
// });
50+
4751
throw new Error(
4852
"This function shouldn't be there in your final code. If you're seeing this, there is probably some issue with your build config. If you think everything looks fine, then file an issue at https://github.com/mokshit06/macaron/issues"
4953
);

0 commit comments

Comments
 (0)