@stylexjs/babel-plugin 0.15.3 → 0.15.4

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
@@ -829,6 +829,7 @@ class StateManager {
829
829
  const enableMediaQueryOrder = logAndDefault(boolean(), options.enableMediaQueryOrder ?? false, false, 'options.enableMediaQueryOrder');
830
830
  const enableLegacyValueFlipping = logAndDefault(boolean(), options.enableLegacyValueFlipping ?? false, false, 'options.enableLegacyValueFlipping');
831
831
  const enableLogicalStylesPolyfill = logAndDefault(boolean(), options.enableLogicalStylesPolyfill ?? false, false, 'options.enableLogicalStylesPolyfill');
832
+ const enableLTRRTLComments = logAndDefault(boolean(), options.enableLTRRTLComments ?? false, false, 'options.enableLTRRTLComments');
832
833
  const test = logAndDefault(boolean(), options.test ?? false, false, 'options.test');
833
834
  const configRuntimeInjection = logAndDefault(checkRuntimeInjection, options.runtimeInjection ?? false, false, 'options.runtimeInjection');
834
835
  const runtimeInjection = configRuntimeInjection === true ? DEFAULT_INJECT_PATH : configRuntimeInjection === false ? undefined : configRuntimeInjection;
@@ -860,6 +861,7 @@ class StateManager {
860
861
  enableMediaQueryOrder,
861
862
  enableLegacyValueFlipping,
862
863
  enableLogicalStylesPolyfill,
864
+ enableLTRRTLComments,
863
865
  importSources,
864
866
  rewriteAliases: typeof options.rewriteAliases === 'boolean' ? options.rewriteAliases : false,
865
867
  runtimeInjection,
@@ -978,32 +980,27 @@ class StateManager {
978
980
  if (sourceFilePath == null) {
979
981
  return false;
980
982
  }
983
+ const themeFileExtension = this.options.unstable_moduleResolution?.themeFileExtension ?? '.stylex';
984
+ const transformedVarsFileExtension = '.transformed';
985
+ const isValidStylexFile = matchesFileSuffix(themeFileExtension)(importPath);
986
+ const isValidTransformedVarsFile = matchesFileSuffix(transformedVarsFileExtension)(importPath);
987
+ if (!isValidStylexFile && !isValidTransformedVarsFile) {
988
+ return false;
989
+ }
981
990
  switch (this.options.unstable_moduleResolution?.type) {
982
991
  case 'commonJS':
983
992
  {
984
993
  const aliases = this.options.aliases;
985
- const themeFileExtension = this.options.unstable_moduleResolution?.themeFileExtension ?? '.stylex';
986
- if (!matchesFileSuffix(themeFileExtension)(importPath)) {
987
- return false;
988
- }
989
994
  const resolvedFilePath = filePathResolver(importPath, sourceFilePath, aliases);
990
995
  return resolvedFilePath ? ['themeNameRef', this.getCanonicalFilePath(resolvedFilePath)] : false;
991
996
  }
992
997
  case 'haste':
993
998
  {
994
- const themeFileExtension = this.options.unstable_moduleResolution.themeFileExtension ?? '.stylex';
995
- if (!matchesFileSuffix(themeFileExtension)(importPath)) {
996
- return false;
997
- }
998
999
  return ['themeNameRef', addFileExtension(importPath, sourceFilePath)];
999
1000
  }
1000
1001
  case 'experimental_crossFileParsing':
1001
1002
  {
1002
1003
  const aliases = this.options.aliases;
1003
- const themeFileExtension = this.options.unstable_moduleResolution.themeFileExtension ?? '.stylex';
1004
- if (!matchesFileSuffix(themeFileExtension)(importPath)) {
1005
- return false;
1006
- }
1007
1004
  const resolvedFilePath = filePathResolver(importPath, sourceFilePath, aliases);
1008
1005
  return resolvedFilePath ? ['filePath', resolvedFilePath] : false;
1009
1006
  }
@@ -1295,6 +1292,7 @@ const defaultOptions = {
1295
1292
  enableMediaQueryOrder: false,
1296
1293
  enableLegacyValueFlipping: false,
1297
1294
  enableLogicalStylesPolyfill: false,
1295
+ enableLTRRTLComments: false,
1298
1296
  enableMinifiedKeys: true,
1299
1297
  styleResolution: 'property-specificity',
1300
1298
  test: false
@@ -7146,10 +7144,13 @@ function evaluatePartialObjectRecursively(path, traversalState, functions = {
7146
7144
  };
7147
7145
  }
7148
7146
  let key = keyResult.value;
7147
+ const valuePath = prop.get('value');
7149
7148
  if (key.startsWith('var(') && key.endsWith(')')) {
7150
- key = key.slice(4, -1);
7149
+ const inner = key.slice(4, -1);
7150
+ if (keyPath.length === 0) {
7151
+ key = inner;
7152
+ }
7151
7153
  }
7152
- const valuePath = prop.get('value');
7153
7154
  if (valuePath.isObjectExpression()) {
7154
7155
  const result = evaluatePartialObjectRecursively(valuePath, traversalState, functions, [...keyPath, key]);
7155
7156
  if (!result.confident) {
@@ -8720,7 +8721,13 @@ function isExported(path) {
8720
8721
  }
8721
8722
  return isExported(path.parentPath);
8722
8723
  }
8723
- function processStylexRules(rules, useLayers = false) {
8724
+ function processStylexRules(rules, config) {
8725
+ const {
8726
+ useLayers = false,
8727
+ enableLTRRTLComments = false
8728
+ } = typeof config === 'boolean' ? {
8729
+ useLayers: config
8730
+ } : config ?? {};
8724
8731
  if (rules.length === 0) {
8725
8732
  return '';
8726
8733
  }
@@ -8811,7 +8818,11 @@ function processStylexRules(rules, useLayers = false) {
8811
8818
  ltrRule = addSpecificityLevel(ltrRule, index);
8812
8819
  rtlRule = rtlRule && addSpecificityLevel(rtlRule, index);
8813
8820
  }
8814
- return rtlRule ? [addAncestorSelector(ltrRule, "html:not([dir='rtl'])"), addAncestorSelector(rtlRule, "html[dir='rtl']")] : [ltrRule];
8821
+ ltrRule = ltrRule.replace(/\.([a-zA-Z0-9]+), \.([a-zA-Z0-9]+):root/g, '.$1.$1, .$1.$1:root');
8822
+ if (rtlRule) {
8823
+ rtlRule = rtlRule.replace(/\.([a-zA-Z0-9]+), \.([a-zA-Z0-9]+):root/g, '.$1.$1, .$1.$1:root');
8824
+ }
8825
+ return rtlRule ? enableLTRRTLComments ? [`/* @ltr begin */${ltrRule}/* @ltr end */`, `/* @rtl begin */${rtlRule}/* @rtl end */`] : [addAncestorSelector(ltrRule, "html:not([dir='rtl'])"), addAncestorSelector(rtlRule, "html[dir='rtl']")] : [ltrRule];
8815
8826
  }).join('\n');
8816
8827
  return useLayers && pri > 0 ? `@layer priority${index + 1}{\n${collectedCSS}\n}` : collectedCSS;
8817
8828
  }).join('\n');
package/lib/index.js.flow CHANGED
@@ -47,7 +47,13 @@ export type Rule = [
47
47
  ];
48
48
  declare function processStylexRules(
49
49
  rules: Array<Rule>,
50
- useLayers: boolean,
50
+ config?:
51
+ | boolean
52
+ | {
53
+ useLayers?: boolean,
54
+ enableLTRRTLComments?: boolean,
55
+ ...
56
+ },
51
57
  ): string;
52
58
 
53
59
  export type StyleXTransformObj = $ReadOnly<{
@@ -49,6 +49,7 @@ export type StyleXOptions = Readonly<{
49
49
  enableMediaQueryOrder?: null | undefined | boolean;
50
50
  enableLegacyValueFlipping?: null | undefined | boolean;
51
51
  enableLogicalStylesPolyfill?: null | undefined | boolean;
52
+ enableLTRRTLComments?: null | undefined | boolean;
52
53
  enableMinifiedKeys?: null | undefined | boolean;
53
54
  styleResolution:
54
55
  | 'application-order'
@@ -55,6 +55,7 @@ export type StyleXOptions = $ReadOnly<{
55
55
  enableMediaQueryOrder?: ?boolean,
56
56
  enableLegacyValueFlipping?: ?boolean,
57
57
  enableLogicalStylesPolyfill?: ?boolean,
58
+ enableLTRRTLComments?: ?boolean,
58
59
  enableMinifiedKeys?: ?boolean,
59
60
  styleResolution:
60
61
  | 'application-order' // The last style applied wins.
@@ -44,6 +44,7 @@ export type StyleXOptions = Readonly<
44
44
  enableMediaQueryOrder?: boolean;
45
45
  enableLegacyValueFlipping?: boolean;
46
46
  enableLogicalStylesPolyfill?: boolean;
47
+ enableLTRRTLComments?: boolean;
47
48
  enableMinifiedKeys?: boolean;
48
49
  importSources: ReadonlyArray<
49
50
  string | Readonly<{ from: string; as: string }>
@@ -68,6 +69,7 @@ export type StyleXOptions = Readonly<
68
69
  enableMediaQueryOrder?: boolean;
69
70
  enableLegacyValueFlipping?: boolean;
70
71
  enableLogicalStylesPolyfill?: boolean;
72
+ enableLTRRTLComments?: boolean;
71
73
  enableMinifiedKeys?: boolean;
72
74
  importSources: ReadonlyArray<
73
75
  string | Readonly<{ from: string; as: string }>
@@ -44,6 +44,7 @@ export type StyleXOptions = $ReadOnly<{
44
44
  enableMediaQueryOrder?: boolean,
45
45
  enableLegacyValueFlipping?: boolean,
46
46
  enableLogicalStylesPolyfill?: boolean,
47
+ enableLTRRTLComments?: boolean,
47
48
  enableMinifiedKeys?: boolean,
48
49
  importSources: $ReadOnlyArray<
49
50
  string | $ReadOnly<{ from: string, as: string }>,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/babel-plugin",
3
- "version": "0.15.3",
3
+ "version": "0.15.4",
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.15.3",
24
+ "@stylexjs/stylex": "0.15.4",
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.15.3"
36
+ "scripts": "0.15.4"
37
37
  },
38
38
  "files": [
39
39
  "flow_modules/*",