@stylexjs/babel-plugin 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1128,8 +1128,8 @@ Object.defineProperty(splitCssValue, "__esModule", {
1128
1128
  value: true
1129
1129
  });
1130
1130
  splitCssValue.default = splitValue;
1131
- var _postcssValueParser$5 = _interopRequireDefault$g(require$$0);
1132
- function _interopRequireDefault$g(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1131
+ var _postcssValueParser$6 = _interopRequireDefault$h(require$$0);
1132
+ function _interopRequireDefault$h(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1133
1133
  function printNode(node) {
1134
1134
  switch (node.type) {
1135
1135
  case 'word':
@@ -1148,7 +1148,7 @@ function splitValue(str) {
1148
1148
  if (Array.isArray(str)) {
1149
1149
  return str;
1150
1150
  }
1151
- const parsed = (0, _postcssValueParser$5.default)(str.trim());
1151
+ const parsed = (0, _postcssValueParser$6.default)(str.trim());
1152
1152
  const nodes = parsed.nodes.filter(node => node.type !== 'space' && node.type !== 'div').map(printNode);
1153
1153
  if (nodes.length > 1 && nodes[nodes.length - 1].toLowerCase() === '!important') {
1154
1154
  return nodes.slice(0, nodes.length - 1).map(node => node + ' !important');
@@ -1160,8 +1160,8 @@ Object.defineProperty(legacyExpandShorthands, "__esModule", {
1160
1160
  value: true
1161
1161
  });
1162
1162
  legacyExpandShorthands.default = void 0;
1163
- var _splitCssValue = _interopRequireDefault$f(splitCssValue);
1164
- function _interopRequireDefault$f(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1163
+ var _splitCssValue = _interopRequireDefault$g(splitCssValue);
1164
+ function _interopRequireDefault$g(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1165
1165
  const shorthands$1 = {
1166
1166
  border: rawValue => {
1167
1167
  return [['borderTop', rawValue], ['borderEnd', rawValue], ['borderBottom', rawValue], ['borderStart', rawValue]];
@@ -1404,10 +1404,10 @@ Object.defineProperty(preprocessRules, "__esModule", {
1404
1404
  });
1405
1405
  preprocessRules.default = flatMapExpandedShorthands;
1406
1406
  preprocessRules.getExpandedKeys = getExpandedKeys;
1407
- var _applicationOrder = _interopRequireDefault$e(applicationOrder);
1408
- var _legacyExpandShorthands = _interopRequireDefault$e(legacyExpandShorthands);
1409
- var _propertySpecificity = _interopRequireDefault$e(propertySpecificity);
1410
- function _interopRequireDefault$e(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1407
+ var _applicationOrder = _interopRequireDefault$f(applicationOrder);
1408
+ var _legacyExpandShorthands = _interopRequireDefault$f(legacyExpandShorthands);
1409
+ var _propertySpecificity = _interopRequireDefault$f(propertySpecificity);
1410
+ function _interopRequireDefault$f(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1411
1411
  const expansions = {
1412
1412
  'application-order': _applicationOrder.default,
1413
1413
  'property-specificity': _propertySpecificity.default,
@@ -1493,8 +1493,8 @@ Object.defineProperty(fontSizePxToRem, "__esModule", {
1493
1493
  value: true
1494
1494
  });
1495
1495
  fontSizePxToRem.default = convertFontSizeToRem;
1496
- var _postcssValueParser$4 = _interopRequireDefault$d(require$$0);
1497
- function _interopRequireDefault$d(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1496
+ var _postcssValueParser$5 = _interopRequireDefault$e(require$$0);
1497
+ function _interopRequireDefault$e(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1498
1498
  const ROOT_FONT_SIZE = 16;
1499
1499
  function convertFontSizeToRem(ast, key) {
1500
1500
  if (key !== 'fontSize') {
@@ -1504,7 +1504,7 @@ function convertFontSizeToRem(ast, key) {
1504
1504
  if (node.type !== 'word') {
1505
1505
  return;
1506
1506
  }
1507
- const dimension = _postcssValueParser$4.default.unit(node.value);
1507
+ const dimension = _postcssValueParser$5.default.unit(node.value);
1508
1508
  if (dimension && dimension.unit === 'px') {
1509
1509
  node.value = `${parseFloat(dimension.number) / ROOT_FONT_SIZE}rem`;
1510
1510
  }
@@ -1518,8 +1518,8 @@ Object.defineProperty(leadingZero, "__esModule", {
1518
1518
  value: true
1519
1519
  });
1520
1520
  leadingZero.default = normalizeLeadingZero;
1521
- var _postcssValueParser$3 = _interopRequireDefault$c(require$$0);
1522
- function _interopRequireDefault$c(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1521
+ var _postcssValueParser$4 = _interopRequireDefault$d(require$$0);
1522
+ function _interopRequireDefault$d(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1523
1523
  function normalizeLeadingZero(ast, _) {
1524
1524
  ast.walk(node => {
1525
1525
  if (node.type !== 'word') {
@@ -1529,7 +1529,7 @@ function normalizeLeadingZero(ast, _) {
1529
1529
  if (Number.isNaN(value)) {
1530
1530
  return;
1531
1531
  }
1532
- const dimension = _postcssValueParser$3.default.unit(node.value);
1532
+ const dimension = _postcssValueParser$4.default.unit(node.value);
1533
1533
  if (value < 1 && value >= 0) {
1534
1534
  node.value = value.toString().replace('0.', '.') + (dimension ? dimension.unit : '');
1535
1535
  }
@@ -1555,14 +1555,14 @@ function normalizeQuotes(ast, _) {
1555
1555
  return ast;
1556
1556
  }
1557
1557
 
1558
- var timings = {};
1558
+ var timings$1 = {};
1559
1559
 
1560
- Object.defineProperty(timings, "__esModule", {
1560
+ Object.defineProperty(timings$1, "__esModule", {
1561
1561
  value: true
1562
1562
  });
1563
- timings.default = normalizeTimings;
1564
- var _postcssValueParser$2 = _interopRequireDefault$b(require$$0);
1565
- function _interopRequireDefault$b(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1563
+ timings$1.default = normalizeTimings;
1564
+ var _postcssValueParser$3 = _interopRequireDefault$c(require$$0);
1565
+ function _interopRequireDefault$c(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1566
1566
  function normalizeTimings(ast, _) {
1567
1567
  ast.walk(node => {
1568
1568
  if (node.type !== 'word') {
@@ -1572,7 +1572,7 @@ function normalizeTimings(ast, _) {
1572
1572
  if (Number.isNaN(value)) {
1573
1573
  return;
1574
1574
  }
1575
- const dimension = _postcssValueParser$2.default.unit(node.value);
1575
+ const dimension = _postcssValueParser$3.default.unit(node.value);
1576
1576
  if (!dimension || dimension.unit !== 'ms' || value < 10) {
1577
1577
  return;
1578
1578
  }
@@ -1632,6 +1632,49 @@ function normalizeWhitespace(ast, _) {
1632
1632
  return ast;
1633
1633
  }
1634
1634
 
1635
+ var zeroDimensions = {};
1636
+
1637
+ Object.defineProperty(zeroDimensions, "__esModule", {
1638
+ value: true
1639
+ });
1640
+ zeroDimensions.default = normalizeZeroDimensions;
1641
+ var _postcssValueParser$2 = _interopRequireDefault$b(require$$0);
1642
+ function _interopRequireDefault$b(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1643
+ const angles = ['deg', 'grad', 'turn', 'rad'];
1644
+ const timings = ['ms', 's'];
1645
+ const fraction = 'fr';
1646
+ const percentage = '%';
1647
+ function normalizeZeroDimensions(ast, _) {
1648
+ let endFunction = 0;
1649
+ ast.walk(node => {
1650
+ if (node.type === 'function' && !endFunction) {
1651
+ endFunction = node.sourceEndIndex ?? 0;
1652
+ }
1653
+ if (endFunction > 0 && node.sourceIndex > endFunction) {
1654
+ endFunction = 0;
1655
+ }
1656
+ if (node.type !== 'word') {
1657
+ return;
1658
+ }
1659
+ const dimension = _postcssValueParser$2.default.unit(node.value);
1660
+ if (!dimension || dimension.number !== '0') {
1661
+ return;
1662
+ }
1663
+ if (angles.indexOf(dimension.unit) !== -1) {
1664
+ node.value = '0deg';
1665
+ } else if (timings.indexOf(dimension.unit) !== -1) {
1666
+ node.value = '0s';
1667
+ } else if (dimension.unit === fraction) {
1668
+ node.value = '0fr';
1669
+ } else if (dimension.unit === percentage) {
1670
+ node.value = '0%';
1671
+ } else if (!endFunction) {
1672
+ node.value = '0';
1673
+ }
1674
+ });
1675
+ return ast;
1676
+ }
1677
+
1635
1678
  var detectUnclosedFns$1 = {};
1636
1679
 
1637
1680
  Object.defineProperty(detectUnclosedFns$1, "__esModule", {
@@ -1681,13 +1724,14 @@ normalizeValue$1.default = normalizeValue;
1681
1724
  var _fontSizePxToRem = _interopRequireDefault$9(fontSizePxToRem);
1682
1725
  var _leadingZero = _interopRequireDefault$9(leadingZero);
1683
1726
  var _quotes = _interopRequireDefault$9(quotes);
1684
- var _timings = _interopRequireDefault$9(timings);
1727
+ var _timings = _interopRequireDefault$9(timings$1);
1685
1728
  var _whitespace = _interopRequireDefault$9(whitespace);
1729
+ var _zeroDimensions = _interopRequireDefault$9(zeroDimensions);
1686
1730
  var _detectUnclosedFns = _interopRequireDefault$9(detectUnclosedFns$1);
1687
1731
  var _postcssValueParser$1 = _interopRequireDefault$9(require$$0);
1688
1732
  var _convertCamelCaseValues = _interopRequireDefault$9(convertCamelCaseValues);
1689
1733
  function _interopRequireDefault$9(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1690
- const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default, _leadingZero.default, _quotes.default, _convertCamelCaseValues.default];
1734
+ const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default, _zeroDimensions.default, _leadingZero.default, _quotes.default, _convertCamelCaseValues.default];
1691
1735
  function normalizeValue(value, key, _ref) {
1692
1736
  let {
1693
1737
  useRemForFontSize
@@ -3091,12 +3135,12 @@ function getDefaultValue(value) {
3091
3135
  throw new Error('Invalid value in stylex.defineVars');
3092
3136
  }
3093
3137
 
3094
- var types$1 = {};
3138
+ var types$2 = {};
3095
3139
 
3096
- Object.defineProperty(types$1, "__esModule", {
3140
+ Object.defineProperty(types$2, "__esModule", {
3097
3141
  value: true
3098
3142
  });
3099
- types$1.url = types$1.transformList = types$1.transformFunction = types$1.time = types$1.resolution = types$1.percentage = types$1.number = types$1.lengthPercentage = types$1.length = types$1.isCSSType = types$1.integer = types$1.image = types$1.color = types$1.angle = types$1.Url = types$1.TransformList = types$1.TransformFunction = types$1.Time = types$1.Resolution = types$1.Percentage = types$1.Num = types$1.LengthPercentage = types$1.Length = types$1.Integer = types$1.Image = types$1.Color = types$1.Angle = void 0;
3143
+ types$2.url = types$2.transformList = types$2.transformFunction = types$2.time = types$2.resolution = types$2.percentage = types$2.number = types$2.lengthPercentage = types$2.length = types$2.isCSSType = types$2.integer = types$2.image = types$2.color = types$2.angle = types$2.Url = types$2.TransformList = types$2.TransformFunction = types$2.Time = types$2.Resolution = types$2.Percentage = types$2.Num = types$2.LengthPercentage = types$2.Length = types$2.Integer = types$2.Image = types$2.Color = types$2.Angle = void 0;
3100
3144
  class BaseCSSType {
3101
3145
  constructor(value) {
3102
3146
  this.value = value;
@@ -3105,7 +3149,7 @@ class BaseCSSType {
3105
3149
  const isCSSType = value => {
3106
3150
  return value instanceof BaseCSSType && value.value != null && typeof value.syntax === 'string';
3107
3151
  };
3108
- types$1.isCSSType = isCSSType;
3152
+ types$2.isCSSType = isCSSType;
3109
3153
  class Angle extends BaseCSSType {
3110
3154
  syntax = '<angle>';
3111
3155
  static syntax = '<angle>';
@@ -3113,24 +3157,24 @@ class Angle extends BaseCSSType {
3113
3157
  return new Angle(value);
3114
3158
  }
3115
3159
  }
3116
- types$1.Angle = Angle;
3117
- types$1.angle = Angle.create;
3160
+ types$2.Angle = Angle;
3161
+ types$2.angle = Angle.create;
3118
3162
  class Color extends BaseCSSType {
3119
3163
  syntax = '<color>';
3120
3164
  static create(value) {
3121
3165
  return new Color(value);
3122
3166
  }
3123
3167
  }
3124
- types$1.Color = Color;
3125
- types$1.color = Color.create;
3168
+ types$2.Color = Color;
3169
+ types$2.color = Color.create;
3126
3170
  class Url extends BaseCSSType {
3127
3171
  syntax = '<url>';
3128
3172
  static create(value) {
3129
3173
  return new Url(value);
3130
3174
  }
3131
3175
  }
3132
- types$1.Url = Url;
3133
- types$1.url = Url.create;
3176
+ types$2.Url = Url;
3177
+ types$2.url = Url.create;
3134
3178
  class Image extends Url {
3135
3179
  syntax = '<image>';
3136
3180
  constructor(value) {
@@ -3141,16 +3185,16 @@ class Image extends Url {
3141
3185
  return new Image(value);
3142
3186
  }
3143
3187
  }
3144
- types$1.Image = Image;
3145
- types$1.image = Image.create;
3188
+ types$2.Image = Image;
3189
+ types$2.image = Image.create;
3146
3190
  class Integer extends BaseCSSType {
3147
3191
  syntax = '<integer>';
3148
3192
  static create(value) {
3149
3193
  return new Integer(convertNumberToStringUsing(String)(value));
3150
3194
  }
3151
3195
  }
3152
- types$1.Integer = Integer;
3153
- types$1.integer = Integer.create;
3196
+ types$2.Integer = Integer;
3197
+ types$2.integer = Integer.create;
3154
3198
  class LengthPercentage extends BaseCSSType {
3155
3199
  syntax = '<length-percentage>';
3156
3200
  static createLength(value) {
@@ -3160,64 +3204,64 @@ class LengthPercentage extends BaseCSSType {
3160
3204
  return new LengthPercentage(convertNumberToPercentage(value));
3161
3205
  }
3162
3206
  }
3163
- types$1.LengthPercentage = LengthPercentage;
3164
- types$1.lengthPercentage = LengthPercentage.createLength;
3207
+ types$2.LengthPercentage = LengthPercentage;
3208
+ types$2.lengthPercentage = LengthPercentage.createLength;
3165
3209
  class Length extends LengthPercentage {
3166
3210
  syntax = '<length>';
3167
3211
  static create(value) {
3168
3212
  return new Length(convertNumberToLength(value));
3169
3213
  }
3170
3214
  }
3171
- types$1.Length = Length;
3172
- types$1.length = Length.create;
3215
+ types$2.Length = Length;
3216
+ types$2.length = Length.create;
3173
3217
  class Percentage extends LengthPercentage {
3174
3218
  syntax = '<percentage>';
3175
3219
  static create(value) {
3176
3220
  return new Percentage(convertNumberToPercentage(value));
3177
3221
  }
3178
3222
  }
3179
- types$1.Percentage = Percentage;
3180
- types$1.percentage = Percentage.create;
3223
+ types$2.Percentage = Percentage;
3224
+ types$2.percentage = Percentage.create;
3181
3225
  class Num extends BaseCSSType {
3182
3226
  syntax = '<number>';
3183
3227
  static create(value) {
3184
3228
  return new Num(convertNumberToBareString(value));
3185
3229
  }
3186
3230
  }
3187
- types$1.Num = Num;
3188
- types$1.number = Num.create;
3231
+ types$2.Num = Num;
3232
+ types$2.number = Num.create;
3189
3233
  class Resolution extends BaseCSSType {
3190
3234
  syntax = '<resolution>';
3191
3235
  static create(value) {
3192
3236
  return new Resolution(value);
3193
3237
  }
3194
3238
  }
3195
- types$1.Resolution = Resolution;
3196
- types$1.resolution = Resolution.create;
3239
+ types$2.Resolution = Resolution;
3240
+ types$2.resolution = Resolution.create;
3197
3241
  class Time extends BaseCSSType {
3198
3242
  syntax = '<time>';
3199
3243
  static create(value) {
3200
3244
  return new Time(value);
3201
3245
  }
3202
3246
  }
3203
- types$1.Time = Time;
3204
- types$1.time = Time.create;
3247
+ types$2.Time = Time;
3248
+ types$2.time = Time.create;
3205
3249
  class TransformFunction extends BaseCSSType {
3206
3250
  syntax = '<transform-function>';
3207
3251
  static create(value) {
3208
3252
  return new TransformFunction(value);
3209
3253
  }
3210
3254
  }
3211
- types$1.TransformFunction = TransformFunction;
3212
- types$1.transformFunction = TransformFunction.create;
3255
+ types$2.TransformFunction = TransformFunction;
3256
+ types$2.transformFunction = TransformFunction.create;
3213
3257
  class TransformList extends BaseCSSType {
3214
3258
  syntax = '<transform-list>';
3215
3259
  static create(value) {
3216
3260
  return new TransformList(value);
3217
3261
  }
3218
3262
  }
3219
- types$1.TransformList = TransformList;
3220
- types$1.transformList = TransformList.create;
3263
+ types$2.TransformList = TransformList;
3264
+ types$2.transformList = TransformList.create;
3221
3265
  const convertNumberToStringUsing = (transformNumber, defaultStr) => value => {
3222
3266
  if (typeof value === 'number') {
3223
3267
  return transformNumber(value);
@@ -3247,7 +3291,7 @@ var _hash$3 = _interopRequireDefault$3(hash$1);
3247
3291
  var _objectUtils$1 = objectUtils;
3248
3292
  var _defaultOptions$2 = defaultOptions;
3249
3293
  var _stylexVarsUtils$1 = stylexVarsUtils;
3250
- var _types$2 = types$1;
3294
+ var _types$2 = types$2;
3251
3295
  function _interopRequireDefault$3(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
3252
3296
  function styleXDefineVars(variables, options) {
3253
3297
  const {
@@ -3260,7 +3304,7 @@ function styleXDefineVars(variables, options) {
3260
3304
  const themeNameHash = classNamePrefix + (0, _hash$3.default)(themeName);
3261
3305
  const typedVariables = {};
3262
3306
  const variablesMap = (0, _objectUtils$1.objMap)(variables, (value, key) => {
3263
- const nameHash = classNamePrefix + (0, _hash$3.default)(`${themeName}.${key}`);
3307
+ const nameHash = key.startsWith('--') ? key.slice(2) : classNamePrefix + (0, _hash$3.default)(`${themeName}.${key}`);
3264
3308
  if ((0, _types$2.isCSSType)(value)) {
3265
3309
  const v = value;
3266
3310
  typedVariables[nameHash] = {
@@ -3338,7 +3382,7 @@ Object.defineProperty(stylexCreateTheme$1, "__esModule", {
3338
3382
  stylexCreateTheme$1.default = styleXCreateTheme;
3339
3383
  var _hash$2 = _interopRequireDefault$2(hash$1);
3340
3384
  var _stylexVarsUtils = stylexVarsUtils;
3341
- var _types$1 = types$1;
3385
+ var _types$1 = types$2;
3342
3386
  var _defaultOptions$1 = defaultOptions;
3343
3387
  function _interopRequireDefault$2(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
3344
3388
  function styleXCreateTheme(themeVars, variables, options) {
@@ -3484,7 +3528,7 @@ var messages_1;
3484
3528
  Object.defineProperty(lib, "__esModule", {
3485
3529
  value: true
3486
3530
  });
3487
- var utils_1 = lib.utils = lib.types = messages_1 = lib.messages = keyframes_1 = lib.keyframes = include_1 = lib.include = firstThatWorks_1 = lib.firstThatWorks = defineVars_1 = lib.defineVars = createTheme_1 = lib.createTheme = create_1 = lib.create = lib.PSEUDO_ELEMENT_PRIORITY = lib.PSEUDO_CLASS_PRIORITIES = IncludedStyles_1 = lib.IncludedStyles = lib.AT_RULE_PRIORITIES = void 0;
3531
+ var utils_1 = lib.utils = types$1 = lib.types = messages_1 = lib.messages = keyframes_1 = lib.keyframes = include_1 = lib.include = firstThatWorks_1 = lib.firstThatWorks = defineVars_1 = lib.defineVars = createTheme_1 = lib.createTheme = create_1 = lib.create = lib.PSEUDO_ELEMENT_PRIORITY = lib.PSEUDO_CLASS_PRIORITIES = IncludedStyles_1 = lib.IncludedStyles = lib.AT_RULE_PRIORITIES = void 0;
3488
3532
  var _stylexCreate = _interopRequireDefault(stylexCreate$1);
3489
3533
  var _stylexDefineVars = _interopRequireDefault(stylexDefineVars$1);
3490
3534
  var _stylexCreateTheme = _interopRequireDefault(stylexCreateTheme$1);
@@ -3494,8 +3538,8 @@ var _stylexFirstThatWorks = _interopRequireDefault(stylexFirstThatWorks$1);
3494
3538
  var _hash = _interopRequireDefault(hash$1);
3495
3539
  var _fileBasedIdentifier = _interopRequireDefault(fileBasedIdentifier);
3496
3540
  var m = _interopRequireWildcard(messages$4);
3497
- var _types = _interopRequireWildcard(types$1);
3498
- lib.types = _types;
3541
+ var _types = _interopRequireWildcard(types$2);
3542
+ var types$1 = lib.types = _types;
3499
3543
  var _propertyPriorities = propertyPriorities;
3500
3544
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
3501
3545
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -3619,7 +3663,7 @@ function evaluateThemeRef(fileName, exportName, state) {
3619
3663
  const strToHash = key === '__themeName__' ? utils_1.genFileBasedIdentifier({
3620
3664
  fileName,
3621
3665
  exportName
3622
- }) : utils_1.genFileBasedIdentifier({
3666
+ }) : key.startsWith('--') ? `var(${key})` : utils_1.genFileBasedIdentifier({
3623
3667
  fileName,
3624
3668
  exportName,
3625
3669
  key
@@ -4016,14 +4060,16 @@ function _evaluate(path, state) {
4016
4060
  const val = object.node.value;
4017
4061
  func = val[property.node.name];
4018
4062
  }
4019
- const parsedObj = evaluate(object, state.traversalState, state.functions);
4020
- if (parsedObj.confident && isIdentifier(property)) {
4021
- func = parsedObj.value[property.node.name];
4022
- context = parsedObj.value;
4023
- }
4024
- if (parsedObj.confident && isStringLiteral(property)) {
4025
- func = parsedObj.value[property.node.value];
4026
- context = parsedObj.value;
4063
+ if (func == null) {
4064
+ const parsedObj = evaluate(object, state.traversalState, state.functions);
4065
+ if (parsedObj.confident && isIdentifier(property)) {
4066
+ func = parsedObj.value[property.node.name];
4067
+ context = parsedObj.value;
4068
+ }
4069
+ if (parsedObj.confident && isStringLiteral(property)) {
4070
+ func = parsedObj.value[property.node.value];
4071
+ context = parsedObj.value;
4072
+ }
4027
4073
  }
4028
4074
  }
4029
4075
  if (func) {
@@ -4430,6 +4476,9 @@ function transformStyleXDefineVars(callExpressionPath, state) {
4430
4476
  fn: keyframes
4431
4477
  };
4432
4478
  });
4479
+ state.stylexTypesImport.forEach(name => {
4480
+ identifiers[name] = types$1;
4481
+ });
4433
4482
  state.stylexImport.forEach(name => {
4434
4483
  if (memberExpressions[name] === undefined) {
4435
4484
  memberExpressions[name] = {};
@@ -4437,6 +4486,10 @@ function transformStyleXDefineVars(callExpressionPath, state) {
4437
4486
  memberExpressions[name].keyframes = {
4438
4487
  fn: keyframes
4439
4488
  };
4489
+ identifiers[name] = {
4490
+ ...(identifiers[name] ?? {}),
4491
+ types: types$1
4492
+ };
4440
4493
  });
4441
4494
  const {
4442
4495
  confident,
@@ -4518,10 +4571,41 @@ function transformStyleXCreateTheme(callExpressionPath, state) {
4518
4571
  if (!confident1) {
4519
4572
  throw new Error(messages_1.NON_STATIC_VALUE);
4520
4573
  }
4574
+ const injectedKeyframes = {};
4575
+ function keyframes(animation) {
4576
+ const [animationName, injectedStyle] = keyframes_1(animation, state.options);
4577
+ injectedKeyframes[animationName] = injectedStyle;
4578
+ return animationName;
4579
+ }
4580
+ const identifiers = {};
4581
+ const memberExpressions = {};
4582
+ state.stylexKeyframesImport.forEach(name => {
4583
+ identifiers[name] = {
4584
+ fn: keyframes
4585
+ };
4586
+ });
4587
+ state.stylexTypesImport.forEach(name => {
4588
+ identifiers[name] = types$1;
4589
+ });
4590
+ state.stylexImport.forEach(name => {
4591
+ if (memberExpressions[name] === undefined) {
4592
+ memberExpressions[name] = {};
4593
+ }
4594
+ memberExpressions[name].keyframes = {
4595
+ fn: keyframes
4596
+ };
4597
+ identifiers[name] = {
4598
+ ...(identifiers[name] ?? {}),
4599
+ types: types$1
4600
+ };
4601
+ });
4521
4602
  const {
4522
4603
  confident: confident2,
4523
4604
  value: overrides
4524
- } = evaluate(secondArg, state);
4605
+ } = evaluate(secondArg, state, {
4606
+ identifiers,
4607
+ memberExpressions
4608
+ });
4525
4609
  if (!confident2) {
4526
4610
  throw new Error(messages_1.NON_STATIC_VALUE);
4527
4611
  }
@@ -4550,7 +4634,10 @@ function transformStyleXCreateTheme(callExpressionPath, state) {
4550
4634
  };
4551
4635
  }
4552
4636
  callExpressionPath.replaceWith(convertObjectToAST(overridesObj));
4553
- const listOfStyles = Object.entries(injectedStyles).map(_ref => {
4637
+ const listOfStyles = Object.entries({
4638
+ ...injectedKeyframes,
4639
+ ...injectedStyles
4640
+ }).map(_ref => {
4554
4641
  let [key, {
4555
4642
  priority,
4556
4643
  ...rest
@@ -10,9 +10,7 @@
10
10
  import type { NodePath } from '@babel/traverse';
11
11
  import StateManager from './state-manager';
12
12
  export type FunctionConfig = {
13
- identifiers: {
14
- [fnName: string]: { fn: (...args: any[]) => any; takesPath?: boolean };
15
- };
13
+ identifiers: { [fnName: string]: any };
16
14
  memberExpressions: {
17
15
  [key: string]: {
18
16
  [memberName: string]: {
@@ -11,15 +11,12 @@ import type { NodePath } from '../../flow_modules/@babel/traverse';
11
11
  import StateManager from './state-manager';
12
12
  export type FunctionConfig = {
13
13
  identifiers: {
14
- [fnName: string]: {
15
- fn: (...args: any[]) => any,
16
- takesPath?: boolean,
17
- },
14
+ [fnName: string]: $FlowFixMe,
18
15
  },
19
16
  memberExpressions: {
20
17
  [key: string]: {
21
18
  [memberName: string]: {
22
- fn: (...args: any[]) => any,
19
+ fn: (...args: $FlowFixMe[]) => $FlowFixMe,
23
20
  takesPath?: boolean,
24
21
  },
25
22
  },
@@ -11,9 +11,9 @@ import * as t from '../../../flow_modules/@babel/types';
11
11
  import type { NodePath } from '../../../flow_modules/@babel/traverse';
12
12
  import StateManager from '../../utils/state-manager';
13
13
  /// This function looks for `stylex.create` calls and transforms them.
14
- //. 1. It finds the first argument to `stylex.create` and validates it.
14
+ /// 1. It finds the first argument to `stylex.create` and validates it.
15
15
  /// 2. It pre-processes valid-dynamic parts of style object such as custom presets (spreads)
16
- /// 3. It envalues the style object to get a JS object. This also handles local constants automatically.
16
+ /// 3. It evaluates the style object to get a JS object. This also handles local constants automatically.
17
17
  /// 4. It uses the `stylexCreate` from `@stylexjs/shared` to transform the JS
18
18
  /// object and to get a list of injected styles.
19
19
  /// 5. It converts the resulting Object back into an AST and replaces the call with it.
@@ -11,7 +11,7 @@ import * as t from '../../flow_modules/@babel/types';
11
11
  import type { NodePath } from '../../flow_modules/@babel/traverse';
12
12
  import StateManager from '../utils/state-manager';
13
13
  /// This function looks for `stylex.createTheme` calls and transforms them.
14
- //. 1. It finds the first two arguments to `stylex.createTheme` and validates those.
14
+ /// 1. It finds the first two arguments to `stylex.createTheme` and validates those.
15
15
  /// 2. This handles local constants automatically.
16
16
  /// 4. It uses the `stylexCreateTheme` from `@stylexjs/shared` to transform the JS
17
17
  /// object and to get a list of injected styles.
@@ -11,8 +11,8 @@ import * as t from '../../flow_modules/@babel/types';
11
11
  import type { NodePath } from '../../flow_modules/@babel/traverse';
12
12
  import StateManager from '../utils/state-manager';
13
13
  /// This function looks for `stylex.defineVars` calls and transforms them.
14
- //. 1. It finds the first argument to `stylex.defineVars` and validates it.
15
- /// 2. It envalues the style object to get a JS object. This also handles local constants automatically.
14
+ /// 1. It finds the first argument to `stylex.defineVars` and validates it.
15
+ /// 2. It evaluates the style object to get a JS object. This also handles local constants automatically.
16
16
  /// 4. It uses the `stylexDefineVars` from `@stylexjs/shared` to transform the JS
17
17
  /// object and to get a list of injected styles.
18
18
  /// 5. It converts the resulting Object back into an AST and replaces the call with it.
@@ -11,8 +11,8 @@ import * as t from '../../flow_modules/@babel/types';
11
11
  import type { NodePath } from '../../flow_modules/@babel/traverse';
12
12
  import StateManager from '../utils/state-manager';
13
13
  /// This function looks for `stylex.keyframes` calls and transforms them.
14
- //. 1. It finds the first argument to `stylex.keyframes` and validates it.
15
- /// 2. It envalues the style object to get a JS object. This also handles local constants automatically.
14
+ /// 1. It finds the first argument to `stylex.keyframes` and validates it.
15
+ /// 2. It evaluates the style object to get a JS object. This also handles local constants automatically.
16
16
  /// 4. It uses the `stylexKeyframes` from `@stylexjs/shared` to transform the JS
17
17
  /// object and to get a list of injected styles.
18
18
  /// 5. It converts the resulting Object back into an AST and replaces the call with it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/babel-plugin",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "StyleX babel plugin.",
5
5
  "main": "lib/index.js",
6
6
  "repository": "https://github.com/facebook/stylex",
@@ -14,8 +14,8 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@babel/helper-module-imports": "^7.22.15",
17
- "@stylexjs/shared": "0.6.0",
18
- "@stylexjs/stylex": "0.6.0",
17
+ "@stylexjs/shared": "0.7.0",
18
+ "@stylexjs/stylex": "0.7.0",
19
19
  "@babel/core": "^7.23.6",
20
20
  "@babel/traverse": "^7.23.6",
21
21
  "@babel/types": "^7.23.6"