Skip to content

Commit

Permalink
fix(babel-plugin): dynamic generate
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Apr 18, 2024
1 parent 1ef9f09 commit 6243710
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"keywords": [],
"author": "kanno",
"license": "MIT",
"packageManager": "[email protected]",
"devDependencies": {
"@stylex-extend/babel-plugin": "workspace:*",
"@stylex-extend/core": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export function Component(props) {
const size = '16px'
return (
<div stylex={{
'--font-size-unit': size,
color: {
default: null,
'@media (max-width: 600px)': size ? props.read : props.purple
}
}}
>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { create as _create, props as _props } from "@stylexjs/stylex";
const _styles = _create({
"--font-size-unit": (_$size) => ({
"--font-size-unit": _$size,
}),
color: (_$1c2mtth) => ({
color: {
default: null,
"@media (max-width: 600px)": _$1c2mtth,
},
}),
});
export function Component(props) {
const size = "16px";
return (
<div
{..._props(
_styles["--font-size-unit"](size),
_styles["color"](size ? props.read : props.purple)
)}
></div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const _styles = _create({
fontSize: {
fontSize: "20px",
},
display: (_$display) => ({
display: _$display,
display: (_$mashst) => ({
display: _$mashst,
}),
padding: (_$padding) => ({
padding: _$padding,
padding: (_$omo79q) => ({
padding: _$omo79q,
}),
});
export function Component(props) {
Expand Down
11 changes: 7 additions & 4 deletions packages/babel-plugin/src/visitor/jsx-attribute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-labels */
import { NodePath, types } from '@babel/core'
import { utils } from '@stylexjs/shared'
import { Context } from '../state-context'
import type { CSSObjectValue } from '../interface'

Expand Down Expand Up @@ -142,8 +143,9 @@ function scanExpressionProperty(path: NodePath<types.ObjectProperty>, ctx: CSSCo
if (value.type === 'TemplateLiteral' && !value.expressions.length) {
CSSObject[attr] = value.quasis[0].value.raw
} else {
CSSObject[attr] = l(attr)
ctx.recordVars('prop', types.identifier(l(attr)), path.get('value') as NodePath<types.Expression>)
const value = l(utils.hash(attr))
CSSObject[attr] = value
ctx.recordVars('prop', types.identifier(value), path.get('value') as NodePath<types.Expression>)
}
break
}
Expand All @@ -155,8 +157,9 @@ function scanExpressionProperty(path: NodePath<types.ObjectProperty>, ctx: CSSCo
break
}
case 'CallExpression': {
CSSObject[attr] = l(attr)
ctx.recordVars('prop', types.identifier(l(attr)), path.get('value') as NodePath<types.Expression>)
const value = l(utils.hash(attr))
CSSObject[attr] = value
ctx.recordVars('prop', types.identifier(value), path.get('value') as NodePath<types.Expression>)
break
}
case 'ObjectExpression': {
Expand Down

0 comments on commit 6243710

Please sign in to comment.