@stylexjs/babel-plugin 0.16.0 → 0.16.2

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.
@@ -2541,7 +2541,7 @@ declare export function buildChildren(
2541
2541
  ): ReturnedChild[];
2542
2542
 
2543
2543
  /*
2544
- Skipping all the asertX functions as they're not supported in Flow yet.
2544
+ Skipping all the assertX functions as they're not supported in Flow yet.
2545
2545
  */
2546
2546
  // TODO: What is this????
2547
2547
  declare export var _default$4: {
package/lib/index.d.ts CHANGED
@@ -42,8 +42,7 @@ declare function processStylexRules(
42
42
  useLayers?: boolean,
43
43
  enableLTRRTLComments?: boolean,
44
44
  legacyDisableLayers?: boolean,
45
- ...
46
- },
45
+ }
47
46
  ): string;
48
47
  export type StyleXTransformObj = Readonly<{
49
48
  (): PluginObj;
package/lib/index.js CHANGED
@@ -5403,6 +5403,13 @@ const AT_RULE_PRIORITIES = {
5403
5403
  '@container': 300
5404
5404
  };
5405
5405
  const PSEUDO_ELEMENT_PRIORITY = 5000;
5406
+ const RELATIONAL_SELECTORS = {
5407
+ ANCESTOR: /^:where\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\s+\*\)$/,
5408
+ DESCENDANT: /^:where\(:has\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\)\)$/,
5409
+ SIBLING_BEFORE: /^:where\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\s+~\s+\*\)$/,
5410
+ SIBLING_AFTER: /^:where\(:has\(~\s\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\)\)$/,
5411
+ ANY_SIBLING: /^:where\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\s+~\s+\*,\s+:has\(~\s\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\)\)$/
5412
+ };
5406
5413
  function getPriority(key) {
5407
5414
  if (key.startsWith('--')) {
5408
5415
  return 1;
@@ -5419,6 +5426,25 @@ function getPriority(key) {
5419
5426
  if (key.startsWith('::')) {
5420
5427
  return PSEUDO_ELEMENT_PRIORITY;
5421
5428
  }
5429
+ const pseudoBase = p => (PSEUDO_CLASS_PRIORITIES[p] ?? 40) / 100;
5430
+ const ancestorMatch = RELATIONAL_SELECTORS.ANCESTOR.exec(key);
5431
+ if (ancestorMatch) {
5432
+ return 10 + pseudoBase(ancestorMatch[1]);
5433
+ }
5434
+ const descendantMatch = RELATIONAL_SELECTORS.DESCENDANT.exec(key);
5435
+ if (descendantMatch) {
5436
+ return 15 + pseudoBase(descendantMatch[1]);
5437
+ }
5438
+ const anySiblingMatch = RELATIONAL_SELECTORS.ANY_SIBLING.exec(key);
5439
+ if (anySiblingMatch) return 20 + Math.max(pseudoBase(anySiblingMatch[1]), pseudoBase(anySiblingMatch[2]));
5440
+ const siblingBeforeMatch = RELATIONAL_SELECTORS.SIBLING_BEFORE.exec(key);
5441
+ if (siblingBeforeMatch) {
5442
+ return 30 + pseudoBase(siblingBeforeMatch[1]);
5443
+ }
5444
+ const siblingAfterMatch = RELATIONAL_SELECTORS.SIBLING_AFTER.exec(key);
5445
+ if (siblingAfterMatch) {
5446
+ return 40 + pseudoBase(siblingAfterMatch[1]);
5447
+ }
5422
5448
  if (key.startsWith(':')) {
5423
5449
  const prop = key.startsWith(':') && key.includes('(') ? key.slice(0, key.indexOf('(')) : key;
5424
5450
  return PSEUDO_CLASS_PRIORITIES[prop] ?? 40;
@@ -6060,7 +6086,7 @@ function priorityForAtRule(atRule) {
6060
6086
  if (atRule === 'default') {
6061
6087
  return 1;
6062
6088
  }
6063
- return atRule.split(SPLIT_TOKEN).length;
6089
+ return 1 + atRule.split(SPLIT_TOKEN).length;
6064
6090
  }
6065
6091
  function getDefaultValue(value) {
6066
6092
  if (typeof value === 'string' || typeof value === 'number') {
@@ -6154,7 +6180,7 @@ function constructCssVariablesString(variables, varGroupHash) {
6154
6180
  result[varGroupHash + suffix] = {
6155
6181
  ltr,
6156
6182
  rtl: null,
6157
- priority: priorityForAtRule(atRule) * 0.1
6183
+ priority: priorityForAtRule(atRule) / 10
6158
6184
  };
6159
6185
  }
6160
6186
  return result;
@@ -6217,19 +6243,14 @@ function styleXCreateTheme(themeVars, variables, options) {
6217
6243
  for (const atRule of sortedAtRules) {
6218
6244
  const decls = rulesByAtRule[atRule].join('');
6219
6245
  const rule = `.${overrideClassName}, .${overrideClassName}:root{${decls}}`;
6220
- if (atRule === 'default') {
6221
- stylesToInject[overrideClassName] = {
6222
- ltr: rule,
6223
- priority: 0.5,
6224
- rtl: null
6225
- };
6226
- } else {
6227
- stylesToInject[overrideClassName + '-' + hash(atRule)] = {
6228
- ltr: wrapWithAtRules(rule, atRule),
6229
- priority: 0.5 + 0.1 * priorityForAtRule(atRule),
6230
- rtl: null
6231
- };
6232
- }
6246
+ const priority = 0.4 + priorityForAtRule(atRule) / 10;
6247
+ const suffix = atRule === 'default' ? '' : `-${hash(atRule)}`;
6248
+ const ltr = atRule === 'default' ? rule : wrapWithAtRules(rule, atRule);
6249
+ stylesToInject[overrideClassName + suffix] = {
6250
+ ltr: ltr,
6251
+ priority: priority,
6252
+ rtl: null
6253
+ };
6233
6254
  }
6234
6255
  const themeClass = `${overrideClassName} ${themeVars.__varGroupHash__}`;
6235
6256
  return [{
@@ -6349,7 +6370,7 @@ function ancestor(pseudo, options = defaultOptions) {
6349
6370
  function descendant(pseudo, options = defaultOptions) {
6350
6371
  validatePseudoSelector(pseudo);
6351
6372
  const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
6352
- return `:has(.${defaultMarker}${pseudo})`;
6373
+ return `:where(:has(.${defaultMarker}${pseudo}))`;
6353
6374
  }
6354
6375
  function siblingBefore(pseudo, options = defaultOptions) {
6355
6376
  validatePseudoSelector(pseudo);
@@ -6359,7 +6380,7 @@ function siblingBefore(pseudo, options = defaultOptions) {
6359
6380
  function siblingAfter(pseudo, options = defaultOptions) {
6360
6381
  validatePseudoSelector(pseudo);
6361
6382
  const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
6362
- return `:has(~ .${defaultMarker}${pseudo})`;
6383
+ return `:where(:has(~ .${defaultMarker}${pseudo}))`;
6363
6384
  }
6364
6385
  function anySibling(pseudo, options = defaultOptions) {
6365
6386
  validatePseudoSelector(pseudo);
@@ -7442,7 +7463,7 @@ function transformStyleXCreate(path, state) {
7442
7463
  ...convertToTestStyles(compiledStyles, varName, state)
7443
7464
  };
7444
7465
  }
7445
- if (varName != null) {
7466
+ if (varName != null && isTopLevel(path)) {
7446
7467
  const stylesToRemember = removeObjectsWithSpreads(compiledStyles);
7447
7468
  state.styleMap.set(varName, stylesToRemember);
7448
7469
  state.styleVars.set(varName, path.parentPath);
@@ -7578,6 +7599,12 @@ function legacyExpandShorthands(dynamicStyles) {
7578
7599
  }).filter(Boolean);
7579
7600
  return expandedKeysToKeyPaths;
7580
7601
  }
7602
+ function isTopLevel(path) {
7603
+ if (path.isStatement()) {
7604
+ return path.parentPath?.isProgram() || path.parentPath?.isExportDeclaration();
7605
+ }
7606
+ return path.parentPath != null && isTopLevel(path.parentPath);
7607
+ }
7581
7608
 
7582
7609
  function transformStyleXCreateTheme(callExpressionPath, state) {
7583
7610
  const callExpressionNode = callExpressionPath.node;
@@ -8841,7 +8868,8 @@ function processStylexRules(rules, config) {
8841
8868
  const {
8842
8869
  useLayers = false,
8843
8870
  enableLTRRTLComments = false,
8844
- legacyDisableLayers = false
8871
+ legacyDisableLayers = false,
8872
+ useLegacyClassnamesSort = false
8845
8873
  } = typeof config === 'boolean' ? {
8846
8874
  useLayers: config
8847
8875
  } : config ?? {};
@@ -8881,23 +8909,27 @@ function processStylexRules(rules, config) {
8881
8909
  for (const [key, value] of constsMap.entries()) {
8882
8910
  constsMap.set(key, resolveConstant(value));
8883
8911
  }
8884
- const sortedRules = nonConstantRules.sort(([, {
8912
+ const sortedRules = nonConstantRules.sort(([classname1, {
8885
8913
  ltr: rule1
8886
- }, firstPriority], [, {
8914
+ }, firstPriority], [classname2, {
8887
8915
  ltr: rule2
8888
8916
  }, secondPriority]) => {
8889
8917
  const priorityComparison = firstPriority - secondPriority;
8890
8918
  if (priorityComparison !== 0) return priorityComparison;
8891
- if (rule1.startsWith('@') && !rule2.startsWith('@')) {
8892
- const query1 = rule1.slice(0, rule1.indexOf('{'));
8893
- const query2 = rule2.slice(0, rule2.indexOf('{'));
8894
- if (query1 !== query2) {
8895
- return query1.localeCompare(query2);
8919
+ if (useLegacyClassnamesSort) {
8920
+ return classname1.localeCompare(classname2);
8921
+ } else {
8922
+ if (rule1.startsWith('@') && !rule2.startsWith('@')) {
8923
+ const query1 = rule1.slice(0, rule1.indexOf('{'));
8924
+ const query2 = rule2.slice(0, rule2.indexOf('{'));
8925
+ if (query1 !== query2) {
8926
+ return query1.localeCompare(query2);
8927
+ }
8896
8928
  }
8929
+ const property1 = rule1.slice(rule1.lastIndexOf('{'));
8930
+ const property2 = rule2.slice(rule2.lastIndexOf('{'));
8931
+ return property1.localeCompare(property2);
8897
8932
  }
8898
- const property1 = rule1.slice(rule1.lastIndexOf('{'));
8899
- const property2 = rule2.slice(rule2.lastIndexOf('{'));
8900
- return property1.localeCompare(property2);
8901
8933
  });
8902
8934
  let lastKPri = -1;
8903
8935
  const grouped = sortedRules.reduce((acc, rule) => {
package/lib/index.js.flow CHANGED
@@ -53,6 +53,7 @@ declare function processStylexRules(
53
53
  useLayers?: boolean,
54
54
  enableLTRRTLComments?: boolean,
55
55
  legacyDisableLayers?: boolean,
56
+ useLegacyClassnamesSort?: boolean,
56
57
  ...
57
58
  },
58
59
  ): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/babel-plugin",
3
- "version": "0.16.0",
3
+ "version": "0.16.2",
4
4
  "description": "StyleX babel plugin.",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -21,7 +21,7 @@
21
21
  "@babel/traverse": "^7.26.8",
22
22
  "@babel/types": "^7.26.8",
23
23
  "@dual-bundle/import-meta-resolve": "^4.1.0",
24
- "@stylexjs/stylex": "0.16.0",
24
+ "@stylexjs/stylex": "0.16.2",
25
25
  "postcss-value-parser": "^4.1.0"
26
26
  },
27
27
  "devDependencies": {
@@ -33,7 +33,7 @@
33
33
  "@rollup/plugin-replace": "^6.0.1",
34
34
  "babel-plugin-syntax-hermes-parser": "^0.26.0",
35
35
  "rollup": "^4.24.0",
36
- "scripts": "0.16.0"
36
+ "scripts": "0.16.2"
37
37
  },
38
38
  "files": [
39
39
  "flow_modules/*",