Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ describe('Evaluation of imported values works based on configuration', () => {
});
const styles = {
color: color => [{
"--__hashed_var__1jqb1tb": color != null ? "__hashed_var__1w8wjxo" : color,
"--__hashed_var__1jqb1tb": color != null ? "__hashed_var__1w8wjxo" : "",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small regression because the reason the fallback value was color is to account for the way undefined vs null is handled by stylex. null means intentionally unsetting a value. undefined is to ignored and the previously set value wins. Here all nullish values are represented as "" which behaves like null.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps what we need here is:

color !== undefined && {"--__hashed_var__1jqb1tb": color != null ? "__hashed_var__1w8wjxo" : "", $$css: true}

This way, we can skip the object for undefined entirely.

$$css: true
}, {
"--x---__hashed_var__1jqb1tb": color != null ? color : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('@stylexjs/babel-plugin', () => {
$$css: "components/main.js:71"
},
dynamic: color => [{
"color-kMwMTN": color != null ? "color-x14rh7hd" : color,
"color-kMwMTN": color != null ? "color-x14rh7hd" : "",
$$css: "components/main.js:74"
}, {
"--x-color": color != null ? color : undefined
Expand Down Expand Up @@ -333,7 +333,7 @@ describe('@stylexjs/babel-plugin', () => {
$$css: "main.js:71"
},
dynamic: color => [{
"color-kMwMTN": color != null ? "color-x14rh7hd" : color,
"color-kMwMTN": color != null ? "color-x14rh7hd" : "",
$$css: "main.js:74"
}, {
"--x-color": color != null ? color : undefined
Expand Down Expand Up @@ -781,7 +781,7 @@ describe('@stylexjs/babel-plugin', () => {
$$css: "main.js:71"
},
dynamic: color => [{
"color-kMwMTN": color != null ? "color-x14rh7hd" : color,
"color-kMwMTN": color != null ? "color-x14rh7hd" : "",
$$css: "main.js:74"
}, {
"--x-color": color != null ? color : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3645,7 +3645,7 @@ describe('@stylexjs/babel-plugin', () => {
};
export const styles = {
root: color => [_temp, {
kMwMTN: color != null ? "x14rh7hd" : color,
kMwMTN: color != null ? "x14rh7hd" : "",
$$css: true
}, {
"--x-color": color != null ? color : undefined
Expand Down Expand Up @@ -3700,7 +3700,7 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
one: color => [{
kMwMTN: color != null ? "x14rh7hd" : color,
kMwMTN: color != null ? "x14rh7hd" : "",
$$css: true
}, {
"--x-color": color != null ? color : undefined
Expand Down Expand Up @@ -3758,8 +3758,8 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
root: (bgColor, otherColor) => [{
"--background-color": bgColor != null ? "xwn82o0" : bgColor,
"--otherColor": otherColor != null ? "xp3hsad" : otherColor,
"--background-color": bgColor != null ? "xwn82o0" : "",
"--otherColor": otherColor != null ? "xp3hsad" : "",
$$css: true
}, {
"--x---background-color": bgColor != null ? bgColor : undefined,
Expand Down Expand Up @@ -3822,7 +3822,7 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
root: width => [{
kzqmXN: width != null ? "x5lhr3w" : width,
kzqmXN: width != null ? "x5lhr3w" : "",
$$css: true
}, {
"--x-width": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(width)
Expand Down Expand Up @@ -3874,7 +3874,7 @@ describe('@stylexjs/babel-plugin', () => {
};
export const styles = {
root: width => [_temp, {
kzqmXN: width != null ? "x5lhr3w" : width,
kzqmXN: width != null ? "x5lhr3w" : "",
$$css: true
}, {
"--x-width": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(width),
Expand Down Expand Up @@ -3953,7 +3953,7 @@ describe('@stylexjs/babel-plugin', () => {
import { vars } from 'vars.stylex.js';
export const styles = {
root: width => [{
"--x1anmu0j": width != null ? "x5fq457" : width,
"--x1anmu0j": width != null ? "x5fq457" : "",
$$css: true
}, {
"--x---x1anmu0j": width != null ? width : undefined
Expand Down Expand Up @@ -4407,7 +4407,7 @@ describe('@stylexjs/babel-plugin', () => {
};
export const styles = {
root: (color, isDark) => [_temp, {
kMwMTN: (isDark ? color : 'black') != null ? "x14rh7hd" : isDark ? color : 'black',
kMwMTN: (isDark ? color : 'black') != null ? "x14rh7hd" : "",
$$css: true
}, {
"--x-backgroundColor": (isDark ? 'black' : 'white') != null ? isDark ? 'black' : 'white' : undefined,
Expand Down Expand Up @@ -4577,8 +4577,8 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
root: color => [{
kWkggS: color != null ? "x1j2k28p" : color,
kMwMTN: color != null ? "x1qvlgnj" : color,
kWkggS: color != null ? "x1j2k28p" : "",
kMwMTN: color != null ? "x1qvlgnj" : "",
$$css: true
}, {
"--x-1e2mv7m": color != null ? color : undefined,
Expand Down Expand Up @@ -4644,7 +4644,7 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
root: (hover, active, focus) => [{
kMwMTN: (hover != null ? "x1qvlgnj " : hover) + (active != null ? "xx746rz " : active) + (focus != null ? "x152n5rj " : focus) + "x126ychx",
kMwMTN: (hover != null ? "x1qvlgnj " : "") + (active != null ? "xx746rz " : "") + (focus != null ? "x152n5rj " : "") + "x126ychx",
$$css: true
}, {
"--x-1113oo7": hover != null ? hover : undefined,
Expand Down Expand Up @@ -4737,8 +4737,8 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
foo: (a, b) => [{
kxBb7d: a != null ? "xaigonn" : a,
kB1Fuz: b != null ? "x1p1099i" : b,
kxBb7d: a != null ? "xaigonn" : "",
kB1Fuz: b != null ? "x1p1099i" : "",
$$css: true
}, {
"--x-1g451k2": a != null ? a : undefined,
Expand Down Expand Up @@ -4801,7 +4801,7 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
foo: color => [{
k8Qsv1: color != null ? "x1mzl164" : color,
k8Qsv1: color != null ? "x1mzl164" : "",
$$css: true
}, {
"--x-163tekb": color != null ? color : undefined
Expand Down Expand Up @@ -4847,7 +4847,7 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
foo: width => [{
k8pbKx: width != null ? "x18fgbt0" : width,
k8pbKx: width != null ? "x18fgbt0" : "",
$$css: true
}, {
"--x-msahdu": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(width)
Expand Down Expand Up @@ -4951,7 +4951,7 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
repro: color => [{
kB1Fuz: color != null ? "x1p1099i" : color,
kB1Fuz: color != null ? "x1p1099i" : "",
$$css: true
}, {
"--x-19erzii": color != null ? color : undefined
Expand Down Expand Up @@ -5001,7 +5001,7 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
root: (a, b, c) => [{
kzqmXN: "x11ymkkh " + "x38mdg9 " + (c != null ? "x1bai16n" : c),
kzqmXN: "x11ymkkh " + "x38mdg9 " + (c != null ? "x1bai16n" : ""),
$$css: true
}, {
"--x-1xmrurk": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)('color-mix(' + color + ', blue)'),
Expand Down Expand Up @@ -5083,7 +5083,7 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
root: (a, b, c) => [{
kMwMTN: (a != null ? "x3d248p " : a) + (b != null ? "x1iuwwch " : b) + (c != null ? "x5268pl" : c),
kMwMTN: (a != null ? "x3d248p " : "") + (b != null ? "x1iuwwch " : "") + (c != null ? "x5268pl" : ""),
$$css: true
}, {
"--x-4xs81a": a != null ? a : undefined,
Expand Down Expand Up @@ -5167,7 +5167,7 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
root: (a, b, c) => [{
kGuDYH: (a != null ? "xww4jgc " : a) + (b != null ? "xfqys7t " : b) + (c != null ? "x13w7uki" : c),
kGuDYH: (a != null ? "xww4jgc " : "") + (b != null ? "xfqys7t " : "") + (c != null ? "x13w7uki" : ""),
$$css: true
}, {
"--x-19zvkyr": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(a),
Expand Down Expand Up @@ -5250,7 +5250,7 @@ describe('@stylexjs/babel-plugin', () => {
"import * as stylex from '@stylexjs/stylex';
export const styles = {
root: (a, b, c) => [{
kGuDYH: ((a ? '16px' : undefined) != null ? "xww4jgc " : a ? '16px' : undefined) + ((b ? '18px' : undefined) != null ? "xqdov8i " : b ? '18px' : undefined) + ((c ? '20px' : undefined) != null ? "x1j86d60" : c ? '20px' : undefined),
kGuDYH: ((a ? '16px' : undefined) != null ? "xww4jgc " : "") + ((b ? '18px' : undefined) != null ? "xqdov8i " : "") + ((c ? '20px' : undefined) != null ? "x1j86d60" : ""),
$$css: true
}, {
"--x-19zvkyr": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(a ? '16px' : undefined),
Expand Down Expand Up @@ -6042,9 +6042,9 @@ describe('@stylexjs/babel-plugin', () => {
});
export const styles = {
default: margin => [_temp, {
k71WvV: (margin != null ? "x17e2bsb " : margin) + "xtcj1g9",
k1K539: (margin != null ? "xg6eqc8 " : margin) + "xgrn1a3",
keTefX: (margin != null ? "x19ja4a5 " : margin) + "x2tye95",
k71WvV: (margin != null ? "x17e2bsb " : "") + "xtcj1g9",
k1K539: (margin != null ? "xg6eqc8 " : "") + "xgrn1a3",
keTefX: (margin != null ? "x19ja4a5 " : "") + "x2tye95",
$$css: true
}, {
"--x-14mfytm": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(margin),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ describe('@stylexjs/babel-plugin', () => {
};
export const styles = {
node: padding => [_temp, {
kmVPX3: padding != null ? "x1fozly0" : padding,
kmVPX3: padding != null ? "x1fozly0" : "",
$$css: true
}, {
"--x-padding": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(padding)
Expand Down Expand Up @@ -603,7 +603,7 @@ describe('@stylexjs/babel-plugin', () => {
import { breakpoints } from './constants.stylex';
export const styles = {
node: color => [{
kMwMTN: "xbs0o1n " + (color != null ? "x3d248p" : color),
kMwMTN: "xbs0o1n " + (color != null ? "x3d248p" : ""),
$$css: true
}, {
"--x-4xs81a": color != null ? color : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ describe('@stylexjs/babel-plugin', () => {
$$css: "npm-package:js/node_modules/npm-package/dist/components/Foo.react.js:4"
},
opacity: opacity => [{
"opacity-kSiTet": opacity != null ? "opacity-xb4nw82" : opacity,
"opacity-kSiTet": opacity != null ? "opacity-xb4nw82" : "",
$$css: "npm-package:js/node_modules/npm-package/dist/components/Foo.react.js:7"
}, {
"--x-opacity": opacity != null ? opacity : undefined
Expand Down Expand Up @@ -806,7 +806,7 @@ describe('@stylexjs/babel-plugin', () => {
});
const styles = {
color: c => [{
kMwMTN: c != null ? "x14rh7hd" : c,
kMwMTN: c != null ? "x14rh7hd" : "",
$$css: true
}, {
"--x-color": c != null ? c : undefined
Expand Down Expand Up @@ -902,7 +902,7 @@ describe('@stylexjs/babel-plugin', () => {
});
const styles = {
opacity: o => [{
kSiTet: o != null ? "xb4nw82" : o,
kSiTet: o != null ? "xb4nw82" : "",
$$css: true
}, {
"--x-opacity": o != null ? o : undefined
Expand Down Expand Up @@ -944,7 +944,7 @@ describe('@stylexjs/babel-plugin', () => {
});
const styles = {
opacity: o => [{
kSiTet: o != null ? "xb4nw82" : o,
kSiTet: o != null ? "xb4nw82" : "",
$$css: true
}, {
"--x-opacity": o != null ? o : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export default function transformStyleXCreate(
t.conditionalExpression(
t.binaryExpression('!=', expr, t.nullLiteral()),
t.stringLiteral(clsWithSpace),
expr,
t.stringLiteral(''),
),
);
} else {
Expand Down
Loading