@stylexjs/babel-plugin 0.16.0 → 0.16.1

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.js CHANGED
@@ -7442,7 +7442,7 @@ function transformStyleXCreate(path, state) {
7442
7442
  ...convertToTestStyles(compiledStyles, varName, state)
7443
7443
  };
7444
7444
  }
7445
- if (varName != null) {
7445
+ if (varName != null && isTopLevel(path)) {
7446
7446
  const stylesToRemember = removeObjectsWithSpreads(compiledStyles);
7447
7447
  state.styleMap.set(varName, stylesToRemember);
7448
7448
  state.styleVars.set(varName, path.parentPath);
@@ -7578,6 +7578,12 @@ function legacyExpandShorthands(dynamicStyles) {
7578
7578
  }).filter(Boolean);
7579
7579
  return expandedKeysToKeyPaths;
7580
7580
  }
7581
+ function isTopLevel(path) {
7582
+ if (path.isStatement()) {
7583
+ return path.parentPath?.isProgram() || path.parentPath?.isExportDeclaration();
7584
+ }
7585
+ return path.parentPath != null && isTopLevel(path.parentPath);
7586
+ }
7581
7587
 
7582
7588
  function transformStyleXCreateTheme(callExpressionPath, state) {
7583
7589
  const callExpressionNode = callExpressionPath.node;
@@ -8841,7 +8847,8 @@ function processStylexRules(rules, config) {
8841
8847
  const {
8842
8848
  useLayers = false,
8843
8849
  enableLTRRTLComments = false,
8844
- legacyDisableLayers = false
8850
+ legacyDisableLayers = false,
8851
+ useLegacyClassnamesSort = false
8845
8852
  } = typeof config === 'boolean' ? {
8846
8853
  useLayers: config
8847
8854
  } : config ?? {};
@@ -8881,23 +8888,27 @@ function processStylexRules(rules, config) {
8881
8888
  for (const [key, value] of constsMap.entries()) {
8882
8889
  constsMap.set(key, resolveConstant(value));
8883
8890
  }
8884
- const sortedRules = nonConstantRules.sort(([, {
8891
+ const sortedRules = nonConstantRules.sort(([classname1, {
8885
8892
  ltr: rule1
8886
- }, firstPriority], [, {
8893
+ }, firstPriority], [classname2, {
8887
8894
  ltr: rule2
8888
8895
  }, secondPriority]) => {
8889
8896
  const priorityComparison = firstPriority - secondPriority;
8890
8897
  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);
8898
+ if (useLegacyClassnamesSort) {
8899
+ return classname1.localeCompare(classname2);
8900
+ } else {
8901
+ if (rule1.startsWith('@') && !rule2.startsWith('@')) {
8902
+ const query1 = rule1.slice(0, rule1.indexOf('{'));
8903
+ const query2 = rule2.slice(0, rule2.indexOf('{'));
8904
+ if (query1 !== query2) {
8905
+ return query1.localeCompare(query2);
8906
+ }
8896
8907
  }
8908
+ const property1 = rule1.slice(rule1.lastIndexOf('{'));
8909
+ const property2 = rule2.slice(rule2.lastIndexOf('{'));
8910
+ return property1.localeCompare(property2);
8897
8911
  }
8898
- const property1 = rule1.slice(rule1.lastIndexOf('{'));
8899
- const property2 = rule2.slice(rule2.lastIndexOf('{'));
8900
- return property1.localeCompare(property2);
8901
8912
  });
8902
8913
  let lastKPri = -1;
8903
8914
  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.1",
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.1",
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.1"
37
37
  },
38
38
  "files": [
39
39
  "flow_modules/*",