@stylexjs/babel-plugin 0.17.0 → 0.17.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.
Files changed (53) hide show
  1. package/lib/index.js +159 -76
  2. package/lib/shared/common-types.js.flow +9 -0
  3. package/lib/shared/hash.d.ts +3 -0
  4. package/lib/shared/index.d.ts +12 -0
  5. package/lib/shared/messages.d.ts +32 -0
  6. package/lib/shared/physical-rtl/generate-ltr.d.ts +1 -1
  7. package/lib/shared/physical-rtl/generate-ltr.js.flow +1 -1
  8. package/lib/shared/physical-rtl/generate-rtl.d.ts +1 -1
  9. package/lib/shared/physical-rtl/generate-rtl.js.flow +1 -1
  10. package/lib/shared/preprocess-rules/application-order.d.ts +35 -34
  11. package/lib/shared/preprocess-rules/application-order.js.flow +35 -29
  12. package/lib/shared/preprocess-rules/basic-validation.d.ts +1 -1
  13. package/lib/shared/preprocess-rules/basic-validation.js.flow +1 -1
  14. package/lib/shared/preprocess-rules/legacy-expand-shorthands.d.ts +22 -15
  15. package/lib/shared/preprocess-rules/legacy-expand-shorthands.js.flow +14 -14
  16. package/lib/shared/preprocess-rules/property-specificity.d.ts +12 -11
  17. package/lib/shared/preprocess-rules/property-specificity.js.flow +12 -6
  18. package/lib/shared/stylex-define-consts.d.ts +1 -1
  19. package/lib/shared/stylex-keyframes.d.ts +1 -1
  20. package/lib/shared/stylex-keyframes.js.flow +1 -1
  21. package/lib/shared/stylex-position-try.d.ts +1 -1
  22. package/lib/shared/stylex-position-try.js.flow +1 -1
  23. package/lib/shared/stylex-vars-utils.d.ts +2 -2
  24. package/lib/shared/stylex-vars-utils.js.flow +3 -3
  25. package/lib/shared/stylex-view-transition-class.d.ts +1 -1
  26. package/lib/shared/stylex-view-transition-class.js.flow +1 -1
  27. package/lib/shared/types/index.d.ts +14 -0
  28. package/lib/shared/utils/convert-to-className.d.ts +1 -1
  29. package/lib/shared/utils/convert-to-className.js.flow +1 -1
  30. package/lib/shared/utils/default-options.d.ts +1 -0
  31. package/lib/shared/utils/file-based-identifier.js.flow +1 -1
  32. package/lib/shared/utils/generate-css-rule.d.ts +1 -1
  33. package/lib/shared/utils/generate-css-rule.js.flow +1 -1
  34. package/lib/shared/utils/normalize-value.js.flow +1 -1
  35. package/lib/shared/utils/object-utils.d.ts +10 -8
  36. package/lib/shared/utils/object-utils.js.flow +1 -1
  37. package/lib/shared/utils/rule-utils.d.ts +2 -0
  38. package/lib/shared/utils/transform-value.d.ts +2 -0
  39. package/lib/shared/validate.js.flow +3 -1
  40. package/lib/shared/when/when.d.ts +5 -5
  41. package/lib/shared/when/when.js.flow +5 -5
  42. package/lib/utils/evaluate-path.d.ts +2 -2
  43. package/lib/utils/evaluate-path.js.flow +2 -2
  44. package/lib/utils/evaluation-errors.d.ts +15 -0
  45. package/lib/utils/state-manager.d.ts +40 -35
  46. package/lib/utils/state-manager.js.flow +4 -0
  47. package/lib/utils/validate.d.ts +18 -3
  48. package/lib/utils/validate.js.flow +5 -3
  49. package/lib/visitors/parse-stylex-create-arg.d.ts +1 -1
  50. package/lib/visitors/parse-stylex-create-arg.js.flow +1 -1
  51. package/package.json +5 -5
  52. package/lib/shared/utils/property-priorities.d.ts +0 -17
  53. package/lib/shared/utils/property-priorities.js.flow +0 -78
package/lib/index.js CHANGED
@@ -43,6 +43,12 @@ const string = (message = defaultMessage('a string')) => (value, name) => {
43
43
  return value;
44
44
  };
45
45
  const nullish = (message = defaultMessage('`null` or `undefined`')) => (value, name) => value == null ? value : new Error(message(value, name));
46
+ const optional = check => (value, name) => {
47
+ if (value === undefined) {
48
+ return undefined;
49
+ }
50
+ return check(value, name);
51
+ };
46
52
  const boolean = (message = defaultMessage('a boolean')) => (value, name) => {
47
53
  if (typeof value !== 'boolean') {
48
54
  return new Error(message(value, name));
@@ -278,6 +284,26 @@ function getProgramStatement(path) {
278
284
  return programPath;
279
285
  }
280
286
 
287
+ const defaultOptions = {
288
+ classNamePrefix: 'x',
289
+ dev: false,
290
+ debug: false,
291
+ enableDebugClassNames: false,
292
+ enableDevClassNames: false,
293
+ enableDebugDataProp: true,
294
+ enableFontSizePxToRem: false,
295
+ enableInlinedConditionalMerge: true,
296
+ enableMediaQueryOrder: true,
297
+ enableLegacyValueFlipping: false,
298
+ enableLogicalStylesPolyfill: false,
299
+ enableLTRRTLComments: false,
300
+ enableMinifiedKeys: true,
301
+ styleResolution: 'property-specificity',
302
+ importSources: [],
303
+ treeshakeCompensation: false,
304
+ test: false
305
+ };
306
+
281
307
  const CheckModuleResolution = unionOf4(object({
282
308
  type: literal('commonJS'),
283
309
  rootDir: unionOf(nullish(), string()),
@@ -334,27 +360,27 @@ class StateManager {
334
360
  this.options = this.setOptions(state.opts ?? {});
335
361
  }
336
362
  setOptions(options) {
337
- const dev = logAndDefault(boolean(), options.dev ?? false, false, 'options.dev');
363
+ const dev = logAndDefault(boolean(), options.dev ?? defaultOptions.dev, false, 'options.dev');
338
364
  const debug = logAndDefault(boolean(), options.debug ?? dev, false, 'options.debug');
339
- const enableDebugClassNames = logAndDefault(boolean(), options.enableDebugClassNames ?? true, true, 'options.enableDebugClassNames');
340
- const enableDebugDataProp = logAndDefault(boolean(), options.enableDebugDataProp ?? true, true, 'options.enableDebugDataProp');
341
- const enableDevClassNames = logAndDefault(boolean(), options.enableDevClassNames ?? false, false, 'options.enableDevClassNames');
342
- const enableFontSizePxToRem = logAndDefault(boolean(), options.enableFontSizePxToRem ?? false, false, 'options.enableFontSizePxToRem');
343
- const enableInlinedConditionalMerge = logAndDefault(boolean(), options.enableInlinedConditionalMerge ?? true, true, 'options.enableInlinedConditionalMerge');
344
- const enableMinifiedKeys = logAndDefault(boolean(), options.enableMinifiedKeys ?? true, true, 'options.enableMinifiedKeys');
345
- const enableMediaQueryOrder = logAndDefault(boolean(), options.enableMediaQueryOrder ?? true, true, 'options.enableMediaQueryOrder');
346
- const enableLegacyValueFlipping = logAndDefault(boolean(), options.enableLegacyValueFlipping ?? false, false, 'options.enableLegacyValueFlipping');
347
- const enableLogicalStylesPolyfill = logAndDefault(boolean(), options.enableLogicalStylesPolyfill ?? false, false, 'options.enableLogicalStylesPolyfill');
348
- const enableLTRRTLComments = logAndDefault(boolean(), options.enableLTRRTLComments ?? false, false, 'options.enableLTRRTLComments');
349
- const test = logAndDefault(boolean(), options.test ?? false, false, 'options.test');
365
+ const enableDebugClassNames = logAndDefault(boolean(), options.enableDebugClassNames ?? defaultOptions.enableDebugClassNames, true, 'options.enableDebugClassNames');
366
+ const enableDebugDataProp = logAndDefault(boolean(), options.enableDebugDataProp ?? debug, false, 'options.enableDebugDataProp');
367
+ const enableDevClassNames = logAndDefault(boolean(), options.enableDevClassNames ?? dev, dev, 'options.enableDevClassNames');
368
+ const enableFontSizePxToRem = logAndDefault(boolean(), options.enableFontSizePxToRem ?? defaultOptions.enableFontSizePxToRem, false, 'options.enableFontSizePxToRem');
369
+ const enableInlinedConditionalMerge = logAndDefault(boolean(), options.enableInlinedConditionalMerge ?? defaultOptions.enableInlinedConditionalMerge, true, 'options.enableInlinedConditionalMerge');
370
+ const enableMinifiedKeys = logAndDefault(boolean(), options.enableMinifiedKeys ?? defaultOptions.enableMinifiedKeys, true, 'options.enableMinifiedKeys');
371
+ const enableMediaQueryOrder = logAndDefault(boolean(), options.enableMediaQueryOrder ?? defaultOptions.enableMediaQueryOrder, true, 'options.enableMediaQueryOrder');
372
+ const enableLegacyValueFlipping = logAndDefault(boolean(), options.enableLegacyValueFlipping ?? defaultOptions.enableLegacyValueFlipping, false, 'options.enableLegacyValueFlipping');
373
+ const enableLogicalStylesPolyfill = logAndDefault(boolean(), options.enableLogicalStylesPolyfill ?? defaultOptions.enableLogicalStylesPolyfill, false, 'options.enableLogicalStylesPolyfill');
374
+ const enableLTRRTLComments = logAndDefault(boolean(), options.enableLTRRTLComments ?? defaultOptions.enableLTRRTLComments, false, 'options.enableLTRRTLComments');
375
+ const test = logAndDefault(boolean(), options.test ?? defaultOptions.test, false, 'options.test');
350
376
  const configRuntimeInjection = logAndDefault(checkRuntimeInjection, options.runtimeInjection ?? false, false, 'options.runtimeInjection');
351
377
  const runtimeInjection = configRuntimeInjection === true ? DEFAULT_INJECT_PATH : configRuntimeInjection === false ? undefined : configRuntimeInjection;
352
- const classNamePrefix = logAndDefault(string(), options.classNamePrefix ?? 'x', 'x', 'options.classNamePrefix');
353
- const configuredImportSources = logAndDefault(checkImportSources, options.importSources ?? [], [], 'options.importSources');
378
+ const classNamePrefix = logAndDefault(string(), options.classNamePrefix ?? defaultOptions.classNamePrefix, 'x', 'options.classNamePrefix');
379
+ const configuredImportSources = logAndDefault(checkImportSources, options.importSources ?? defaultOptions.importSources, [], 'options.importSources');
354
380
  const importSources = [name, 'stylex', ...configuredImportSources];
355
- const styleResolution = logAndDefault(unionOf3(literal('application-order'), literal('property-specificity'), literal('legacy-expand-shorthands')), options.styleResolution ?? 'property-specificity', 'property-specificity', 'options.styleResolution');
381
+ const styleResolution = logAndDefault(unionOf3(literal('application-order'), literal('property-specificity'), literal('legacy-expand-shorthands')), options.styleResolution ?? defaultOptions.styleResolution, 'property-specificity', 'options.styleResolution');
356
382
  const unstable_moduleResolution = logAndDefault(unionOf(nullish(), CheckModuleResolution), options.unstable_moduleResolution, null, 'options.unstable_moduleResolution');
357
- const treeshakeCompensation = logAndDefault(boolean(), options.treeshakeCompensation ?? false, false, 'options.treeshakeCompensation');
383
+ const treeshakeCompensation = logAndDefault(boolean(), options.treeshakeCompensation ?? defaultOptions.treeshakeCompensation, false, 'options.treeshakeCompensation');
358
384
  const aliasesOption = logAndDefault(unionOf(nullish(), objectOf(unionOf(string(), array(string())))), options.aliases, null, 'options.aliases');
359
385
  const aliases = aliasesOption == null ? aliasesOption : Object.fromEntries(Object.entries(aliasesOption).map(([key, value]) => {
360
386
  if (typeof value === 'string') {
@@ -362,6 +388,7 @@ class StateManager {
362
388
  }
363
389
  return [key, value];
364
390
  }));
391
+ const debugFilePath = logAndDefault(optional(func()), options.debugFilePath, undefined, 'options.debugFilePath');
365
392
  const opts = {
366
393
  aliases,
367
394
  classNamePrefix,
@@ -384,7 +411,8 @@ class StateManager {
384
411
  styleResolution,
385
412
  test,
386
413
  treeshakeCompensation,
387
- unstable_moduleResolution
414
+ unstable_moduleResolution,
415
+ debugFilePath
388
416
  };
389
417
  return opts;
390
418
  }
@@ -569,11 +597,20 @@ class StateManager {
569
597
  });
570
598
  this.injectImportInserted = injectName;
571
599
  }
572
- for (const [_key, {
573
- ltr,
574
- rtl
575
- }, priority] of styles) {
576
- statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(injectName, [t__namespace.stringLiteral(ltr), t__namespace.numericLiteral(priority), ...(rtl != null ? [t__namespace.stringLiteral(rtl)] : [])])));
600
+ for (const [_key, styleObj, priority] of styles) {
601
+ const {
602
+ ltr,
603
+ rtl
604
+ } = styleObj;
605
+ const args = [t__namespace.stringLiteral(ltr), t__namespace.numericLiteral(priority), ...(rtl != null ? [t__namespace.stringLiteral(rtl)] : [])];
606
+ if ('constKey' in styleObj && 'constVal' in styleObj) {
607
+ const {
608
+ constKey,
609
+ constVal
610
+ } = styleObj;
611
+ args.push(t__namespace.stringLiteral(constKey), typeof constVal === 'number' ? t__namespace.numericLiteral(constVal) : t__namespace.stringLiteral(String(constVal)));
612
+ }
613
+ statementPath.insertBefore(t__namespace.expressionStatement(t__namespace.callExpression(injectName, args)));
577
614
  }
578
615
  }
579
616
  markComposedNamespace(memberExpression) {
@@ -832,23 +869,6 @@ function toBase62(num) {
832
869
  }
833
870
  const createShortHash = str => toBase62(murmurhash2_32_gc(str, 1) % 62 ** 5);
834
871
 
835
- const defaultOptions = {
836
- classNamePrefix: 'x',
837
- dev: false,
838
- debug: false,
839
- enableDebugClassNames: true,
840
- enableDevClassNames: false,
841
- enableDebugDataProp: true,
842
- enableFontSizePxToRem: false,
843
- enableMediaQueryOrder: false,
844
- enableLegacyValueFlipping: false,
845
- enableLogicalStylesPolyfill: false,
846
- enableLTRRTLComments: false,
847
- enableMinifiedKeys: true,
848
- styleResolution: 'property-specificity',
849
- test: false
850
- };
851
-
852
872
  const shorthands$2 = {
853
873
  all: _ => {
854
874
  throw new Error('all is not supported');
@@ -1030,16 +1050,23 @@ const expansions$3 = {
1030
1050
  };
1031
1051
 
1032
1052
  function printNode(node) {
1033
- switch (node.type) {
1034
- case 'word':
1035
- return `${node.value}`;
1036
- case 'string':
1037
- return `${node.quote}${node.value}${node.quote}`;
1038
- case 'function':
1039
- return `${node.value}(${node.nodes.map(printNode).join('')})`;
1040
- default:
1041
- return node.value;
1042
- }
1053
+ return ($$gen$m0 => {
1054
+ if ((typeof $$gen$m0 === "object" && $$gen$m0 !== null || typeof $$gen$m0 === "function") && $$gen$m0.type === 'word' && "value" in $$gen$m0) {
1055
+ const value = $$gen$m0.value;
1056
+ return value;
1057
+ }
1058
+ if ((typeof $$gen$m0 === "object" && $$gen$m0 !== null || typeof $$gen$m0 === "function") && $$gen$m0.type === 'string' && "value" in $$gen$m0 && "quote" in $$gen$m0) {
1059
+ const value = $$gen$m0.value;
1060
+ const quote = $$gen$m0.quote;
1061
+ return `${quote}${value}${quote}`;
1062
+ }
1063
+ if ((typeof $$gen$m0 === "object" && $$gen$m0 !== null || typeof $$gen$m0 === "function") && $$gen$m0.type === 'function' && "value" in $$gen$m0 && "nodes" in $$gen$m0) {
1064
+ const value = $$gen$m0.value;
1065
+ const nodes = $$gen$m0.nodes;
1066
+ return `${value}(${nodes.map(printNode).join('')})`;
1067
+ }
1068
+ return node.value;
1069
+ })(node);
1043
1070
  }
1044
1071
  function splitValue(str) {
1045
1072
  if (str == null || typeof str === 'number') {
@@ -3113,7 +3140,7 @@ function requireMediaQuery () {
3113
3140
  case 'media-keyword':
3114
3141
  {
3115
3142
  const prefix = queries.not ? 'not ' : queries.only ? 'only ' : '';
3116
- return prefix + queries.key;
3143
+ return prefix + (isTopLevel ? queries.key : `(${queries.key})`);
3117
3144
  }
3118
3145
  case 'word-rule':
3119
3146
  return `(${queries.keyValue})`;
@@ -3139,7 +3166,7 @@ function requireMediaQuery () {
3139
3166
  throw new Error(`cannot serialize media-pair value for key "${key}": ${String(value)}`);
3140
3167
  }
3141
3168
  case 'not':
3142
- return queries.rule && (queries.rule.type === 'and' || queries.rule.type === 'or') ? `(not (${this.#toString(queries.rule)}))` : `(not ${this.#toString(queries.rule)})`;
3169
+ return queries.rule && (queries.rule.type === 'and' || queries.rule.type === 'or' || queries.rule.type === 'not') ? `(not (${this.#toString(queries.rule)}))` : `(not ${this.#toString(queries.rule)})`;
3143
3170
  case 'and':
3144
3171
  return queries.rules.map(rule => this.#toString(rule)).join(' and ');
3145
3172
  case 'or':
@@ -3631,7 +3658,7 @@ function getNumberSuffix(key) {
3631
3658
  return suffix;
3632
3659
  }
3633
3660
  }
3634
- const unitlessNumberProperties = new Set(['WebkitLineClamp', 'animationIterationCount', 'aspectRatio', 'borderImageOutset', 'borderImageSlice', 'borderImageWidth', 'counterSet', 'counterReset', 'columnCount', 'flex', 'flexGrow', 'flexShrink', 'flexOrder', 'gridRow', 'gridRowStart', 'gridRowEnd', 'gridColumn', 'gridColumnStart', 'gridColumnEnd', 'gridArea', 'fontWeight', 'hyphenateLimitChars', 'lineClamp', 'lineHeight', 'maskBorderOutset', 'maskBorderSlice', 'maskBorderWidth', 'opacity', 'order', 'orphans', 'tabSize', 'widows', 'zIndex', 'fillOpacity', 'floodOpacity', 'rotate', 'scale', 'shapeImageThreshold', 'stopOpacity', 'strokeDasharray', 'strokeDashoffset', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth', 'scale', 'mathDepth']);
3661
+ const unitlessNumberProperties = new Set(['WebkitLineClamp', 'animationIterationCount', 'aspectRatio', 'borderImageOutset', 'borderImageSlice', 'borderImageWidth', 'counterSet', 'counterReset', 'columnCount', 'flex', 'flexGrow', 'flexShrink', 'flexOrder', 'gridRow', 'gridRowStart', 'gridRowEnd', 'gridColumn', 'gridColumnStart', 'gridColumnEnd', 'gridArea', 'fontWeight', 'hyphenateLimitChars', 'lineClamp', 'lineHeight', 'maskBorderOutset', 'maskBorderSlice', 'maskBorderWidth', 'opacity', 'order', 'orphans', 'tabSize', 'widows', 'zIndex', 'fillOpacity', 'floodOpacity', 'rotate', 'scale', 'shapeImageThreshold', 'stopOpacity', 'strokeDasharray', 'strokeDashoffset', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth', 'scale', 'mathDepth', 'zoom']);
3635
3662
  const numberPropertySuffixes = {
3636
3663
  animationDelay: 'ms',
3637
3664
  animationDuration: 'ms',
@@ -3649,20 +3676,20 @@ const logicalToPhysical$1 = {
3649
3676
  'inline-end': 'right'
3650
3677
  };
3651
3678
  const inlinePropertyToLTR = {
3652
- 'margin-inline-start': ([_key, val]) => ['margin-left', val],
3653
- 'margin-inline-end': ([_key, val]) => ['margin-right', val],
3654
- 'padding-inline-start': ([_key, val]) => ['padding-left', val],
3655
- 'padding-inline-end': ([_key, val]) => ['padding-right', val],
3656
- 'border-inline-start': ([_key, val]) => ['border-left', val],
3657
- 'border-inline-end': ([_key, val]) => ['border-right', val],
3658
- 'border-inline-start-width': ([_key, val]) => ['border-left-width', val],
3659
- 'border-inline-end-width': ([_key, val]) => ['border-right-width', val],
3679
+ 'margin-inline-start': ([_k, val]) => ['margin-left', val],
3680
+ 'margin-inline-end': ([_k, val]) => ['margin-right', val],
3681
+ 'padding-inline-start': ([_k, val]) => ['padding-left', val],
3682
+ 'padding-inline-end': ([_k, val]) => ['padding-right', val],
3683
+ 'border-inline-start': ([_k, val]) => ['border-left', val],
3684
+ 'border-inline-end': ([_k, val]) => ['border-right', val],
3685
+ 'border-inline-start-width': ([_k, val]) => ['border-left-width', val],
3686
+ 'border-inline-end-width': ([_k, val]) => ['border-right-width', val],
3660
3687
  'border-inline-start-color': ([_key, val]) => ['border-left-color', val],
3661
3688
  'border-inline-end-color': ([_key, val]) => ['border-right-color', val],
3662
3689
  'border-inline-start-style': ([_key, val]) => ['border-left-style', val],
3663
3690
  'border-inline-end-style': ([_key, val]) => ['border-right-style', val],
3664
3691
  'border-start-start-radius': ([_key, val]) => ['border-top-left-radius', val],
3665
- 'border-end-start-radius': ([_key, val]) => ['border-bottom-left-radius', val],
3692
+ 'border-end-start-radius': ([_k, val]) => ['border-bottom-left-radius', val],
3666
3693
  'border-start-end-radius': ([_key, val]) => ['border-top-right-radius', val],
3667
3694
  'border-end-end-radius': ([_key, val]) => ['border-bottom-right-radius', val],
3668
3695
  'inset-inline-start': ([_key, val]) => ['left', val],
@@ -3682,13 +3709,13 @@ const propertyToLTR = {
3682
3709
  'border-start-style': ([_key, val]) => ['border-left-style', val],
3683
3710
  'border-end-style': ([_key, val]) => ['border-right-style', val],
3684
3711
  'border-top-start-radius': ([_key, val]) => ['border-top-left-radius', val],
3685
- 'border-bottom-start-radius': ([_key, val]) => ['border-bottom-left-radius', val],
3686
- 'border-top-end-radius': ([_key, val]) => ['border-top-right-radius', val],
3687
- 'border-bottom-end-radius': ([_key, val]) => ['border-bottom-right-radius', val],
3712
+ 'border-bottom-start-radius': ([_k, v]) => ['border-bottom-left-radius', v],
3713
+ 'border-top-end-radius': ([_key, v]) => ['border-top-right-radius', v],
3714
+ 'border-bottom-end-radius': ([_k, v]) => ['border-bottom-right-radius', v],
3688
3715
  float: ([key, val]) => [key, logicalToPhysical$1[val] ?? val],
3689
3716
  clear: ([key, val]) => [key, logicalToPhysical$1[val] ?? val],
3690
- start: ([_key, val]) => ['left', val],
3691
- end: ([_key, val]) => ['right', val],
3717
+ start: ([_k, val]) => ['left', val],
3718
+ end: ([_k, val]) => ['right', val],
3692
3719
  'background-position': ([key, val]) => [key, val.split(' ').map(word => word === 'start' || word === 'insetInlineStart' ? 'left' : word === 'end' || word === 'insetInlineEnd' ? 'right' : word).join(' ')]
3693
3720
  };
3694
3721
  function generateLTR(pair, options = defaultOptions) {
@@ -3784,8 +3811,8 @@ const inlinePropertyToRTL = {
3784
3811
  'border-inline-end-color': ([_key, val]) => ['border-left-color', val],
3785
3812
  'border-inline-start-style': ([_key, val]) => ['border-right-style', val],
3786
3813
  'border-inline-end-style': ([_key, val]) => ['border-left-style', val],
3787
- 'border-start-start-radius': ([_key, val]) => ['border-top-right-radius', val],
3788
- 'border-end-start-radius': ([_key, val]) => ['border-bottom-right-radius', val],
3814
+ 'border-start-start-radius': ([_k, val]) => ['border-top-right-radius', val],
3815
+ 'border-end-start-radius': ([_k, val]) => ['border-bottom-right-radius', val],
3789
3816
  'border-start-end-radius': ([_key, val]) => ['border-top-left-radius', val],
3790
3817
  'border-end-end-radius': ([_key, val]) => ['border-bottom-left-radius', val],
3791
3818
  'inset-inline-start': ([_key, val]) => ['right', val],
@@ -3805,9 +3832,9 @@ const propertyToRTL = {
3805
3832
  'border-start-style': ([_key, val]) => ['border-right-style', val],
3806
3833
  'border-end-style': ([_key, val]) => ['border-left-style', val],
3807
3834
  'border-top-start-radius': ([_key, val]) => ['border-top-right-radius', val],
3808
- 'border-bottom-start-radius': ([_key, val]) => ['border-bottom-right-radius', val],
3835
+ 'border-bottom-start-radius': ([_k, v]) => ['border-bottom-right-radius', v],
3809
3836
  'border-top-end-radius': ([_key, val]) => ['border-top-left-radius', val],
3810
- 'border-bottom-end-radius': ([_key, val]) => ['border-bottom-left-radius', val],
3837
+ 'border-bottom-end-radius': ([_k, val]) => ['border-bottom-left-radius', val],
3811
3838
  float: ([key, val]) => logicalToPhysical[val] != null ? [key, logicalToPhysical[val]] : null,
3812
3839
  clear: ([key, val]) => logicalToPhysical[val] != null ? [key, logicalToPhysical[val]] : null,
3813
3840
  start: ([_key, val]) => ['right', val],
@@ -5464,21 +5491,37 @@ function getPackagePrefix(absolutePath) {
5464
5491
  }
5465
5492
  return undefined;
5466
5493
  }
5467
- function getShortPath(relativePath) {
5494
+ function getShortPath(relativePath, state) {
5495
+ if (state.options.unstable_moduleResolution?.type === 'commonJS' && state.options.unstable_moduleResolution?.rootDir) {
5496
+ const appRootPath = state.options.unstable_moduleResolution?.rootDir;
5497
+ return path.relative(appRootPath, relativePath);
5498
+ }
5468
5499
  return relativePath.split(path.sep).slice(-2).join('/');
5469
5500
  }
5470
5501
  function createShortFilename(absolutePath, state) {
5471
- const isHaste = state.options.unstable_moduleResolution?.type === 'haste';
5472
- const relativePath = path.relative(process.cwd(), absolutePath);
5502
+ if (typeof state.options.debugFilePath === 'function') {
5503
+ return state.options.debugFilePath(absolutePath);
5504
+ }
5505
+ const cwdPackage = state.getPackageNameAndPath(process.cwd());
5506
+ const packageDetails = state.getPackageNameAndPath(absolutePath);
5507
+ if (packageDetails) {
5508
+ const [packageName, packageRootPath] = packageDetails;
5509
+ const relativePath = path.relative(packageRootPath, absolutePath);
5510
+ if (cwdPackage && cwdPackage[0] === packageName) {
5511
+ return relativePath;
5512
+ }
5513
+ return `${packageName}:${relativePath}`;
5514
+ }
5473
5515
  const packagePrefix = getPackagePrefix(absolutePath);
5474
5516
  if (packagePrefix) {
5475
- const shortPath = getShortPath(relativePath);
5517
+ const shortPath = getShortPath(absolutePath, state);
5476
5518
  return `${packagePrefix}:${shortPath}`;
5477
5519
  } else {
5520
+ const isHaste = state.options.unstable_moduleResolution?.type === 'haste';
5478
5521
  if (isHaste) {
5479
5522
  return path.basename(absolutePath);
5480
5523
  }
5481
- return getShortPath(relativePath);
5524
+ return getShortPath(absolutePath, state);
5482
5525
  }
5483
5526
  }
5484
5527
  function addSourceMapData(obj, babelPath, state) {
@@ -5582,6 +5625,43 @@ function isValidCallee(val) {
5582
5625
  function isInvalidMethod(val) {
5583
5626
  return INVALID_METHODS.includes(val);
5584
5627
  }
5628
+ const MUTATING_ARRAY_METHODS = new Set(['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse', 'fill', 'copyWithin']);
5629
+ function isMutated(binding) {
5630
+ for (const path of binding.referencePaths) {
5631
+ const parentPath = path.parentPath;
5632
+ if (!parentPath) continue;
5633
+ if (parentPath.isMemberExpression() && parentPath.node.object === path.node) {
5634
+ const memberExpr = parentPath;
5635
+ const parent = memberExpr.parentPath;
5636
+ if (!parent) continue;
5637
+ if (parent.isAssignmentExpression() && parent.node.left === memberExpr.node) {
5638
+ return true;
5639
+ }
5640
+ if (parent.isUpdateExpression()) {
5641
+ return true;
5642
+ }
5643
+ if (parent.isUnaryExpression({
5644
+ operator: 'delete'
5645
+ })) {
5646
+ return true;
5647
+ }
5648
+ if (parent.isCallExpression() && parent.node.callee === memberExpr.node) {
5649
+ const property = memberExpr.node.property;
5650
+ if (t__namespace.isIdentifier(property) && MUTATING_ARRAY_METHODS.has(property.name)) {
5651
+ return true;
5652
+ }
5653
+ }
5654
+ }
5655
+ if (parentPath?.isCallExpression() && path.listKey === 'arguments' && path.key === 0) {
5656
+ const callExpr = parentPath;
5657
+ const callee = callExpr.get('callee');
5658
+ if (callee.matchesPattern('Object.assign') || callee.matchesPattern('Object.defineProperty') || callee.matchesPattern('Object.defineProperties') || callee.matchesPattern('Object.setPrototypeOf')) {
5659
+ return true;
5660
+ }
5661
+ }
5662
+ }
5663
+ return false;
5664
+ }
5585
5665
  function deopt(path, state, reason) {
5586
5666
  if (!state.confident) return;
5587
5667
  state.deoptPath = path;
@@ -5836,6 +5916,9 @@ function _evaluate(path, state) {
5836
5916
  if (binding && binding.constantViolations.length > 0) {
5837
5917
  return deopt(binding.path, state, NON_CONSTANT);
5838
5918
  }
5919
+ if (binding && isMutated(binding)) {
5920
+ return deopt(binding.path, state, NON_CONSTANT);
5921
+ }
5839
5922
  if (binding && path.node.start < binding.path.node.end) {
5840
5923
  return deopt(binding.path, state, USED_BEFORE_DECLARATION);
5841
5924
  }
@@ -6922,7 +7005,7 @@ function transformStyleXDefineConsts(callExpressionPath, state) {
6922
7005
  ltr: obj.ltr,
6923
7006
  rtl: obj.rtl ?? null
6924
7007
  }, obj.priority]);
6925
- state.registerStyles(styles);
7008
+ state.registerStyles(styles, variableDeclaratorPath);
6926
7009
  }
6927
7010
  }
6928
7011
  function validateStyleXDefineConsts(callExpressionPath) {
@@ -52,11 +52,20 @@ export type StyleXOptions = $ReadOnly<{
52
52
  enableDebugDataProp?: ?boolean,
53
53
  enableDevClassNames?: ?boolean,
54
54
  enableFontSizePxToRem?: ?boolean,
55
+ enableInlinedConditionalMerge?: ?boolean,
55
56
  enableMediaQueryOrder?: ?boolean,
56
57
  enableLegacyValueFlipping?: ?boolean,
57
58
  enableLogicalStylesPolyfill?: ?boolean,
58
59
  enableLTRRTLComments?: ?boolean,
59
60
  enableMinifiedKeys?: ?boolean,
61
+ // runtimeInjection?:
62
+ // | boolean
63
+ // | ?string
64
+ // | $ReadOnly<{ from: string, as: string }>,
65
+ importSources?: $ReadOnlyArray<
66
+ string | $ReadOnly<{ from: string, as: string }>,
67
+ >,
68
+ treeshakeCompensation?: boolean,
60
69
  styleResolution:
61
70
  | 'application-order' // The last style applied wins.
62
71
  // More specific styles will win over less specific styles. (margin-top wins over margin)
@@ -8,5 +8,8 @@
8
8
  */
9
9
 
10
10
  declare const $$EXPORT_DEFAULT_DECLARATION$$: (str: string) => string;
11
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
12
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
11
13
  export default $$EXPORT_DEFAULT_DECLARATION$$;
12
14
  export declare const createShortHash: (str: string) => string;
15
+ export declare type createShortHash = typeof createShortHash;
@@ -38,20 +38,32 @@ import {
38
38
  export * as types from './types';
39
39
  export * as when from './when/when';
40
40
  export declare const create: typeof styleXCreateSet;
41
+ export declare type create = typeof create;
41
42
  export declare const defineVars: typeof styleXDefineVars;
43
+ export declare type defineVars = typeof defineVars;
42
44
  export declare const defineConsts: typeof styleXDefineConsts;
45
+ export declare type defineConsts = typeof defineConsts;
43
46
  export declare const createTheme: typeof styleXCreateTheme;
47
+ export declare type createTheme = typeof createTheme;
44
48
  export declare const keyframes: typeof stylexKeyframes;
49
+ export declare type keyframes = typeof keyframes;
45
50
  export declare const positionTry: typeof stylexPositionTry;
51
+ export declare type positionTry = typeof positionTry;
46
52
  export declare const utils: {
47
53
  hash: typeof hash;
48
54
  genFileBasedIdentifier: typeof genFileBasedIdentifier;
49
55
  };
56
+ export declare type utils = typeof utils;
50
57
  export declare const messages: typeof m;
58
+ export declare type messages = typeof messages;
51
59
  export declare const firstThatWorks: typeof stylexFirstThatWorks;
60
+ export declare type firstThatWorks = typeof firstThatWorks;
52
61
  export declare const PSEUDO_CLASS_PRIORITIES: typeof _PSEUDO_CLASS_PRIORITIES;
62
+ export declare type PSEUDO_CLASS_PRIORITIES = typeof PSEUDO_CLASS_PRIORITIES;
53
63
  export declare const AT_RULE_PRIORITIES: typeof _AT_RULE_PRIORITIES;
64
+ export declare type AT_RULE_PRIORITIES = typeof AT_RULE_PRIORITIES;
54
65
  export declare const PSEUDO_ELEMENT_PRIORITY: typeof _PSEUDO_ELEMENT_PRIORITY;
66
+ export declare type PSEUDO_ELEMENT_PRIORITY = typeof PSEUDO_ELEMENT_PRIORITY;
55
67
  export type InjectableStyle = _InjectableStyle;
56
68
  export type CompiledNamespaces = _CompiledNamespaces;
57
69
  export type MutableCompiledNamespaces = _MutableCompiledNamespaces;
@@ -11,28 +11,60 @@ export declare const illegalArgumentLength: (
11
11
  fn: string,
12
12
  argLength: number,
13
13
  ) => string;
14
+ export declare type illegalArgumentLength = typeof illegalArgumentLength;
14
15
  export declare const nonStaticValue: (fn: string) => string;
16
+ export declare type nonStaticValue = typeof nonStaticValue;
15
17
  export declare const nonStyleObject: (fn: string) => string;
18
+ export declare type nonStyleObject = typeof nonStyleObject;
16
19
  export declare const nonExportNamedDeclaration: (fn: string) => string;
20
+ export declare type nonExportNamedDeclaration =
21
+ typeof nonExportNamedDeclaration;
17
22
  export declare const unboundCallValue: (fn: string) => string;
23
+ export declare type unboundCallValue = typeof unboundCallValue;
18
24
  export declare const cannotGenerateHash: (fn: string) => string;
25
+ export declare type cannotGenerateHash = typeof cannotGenerateHash;
19
26
  export declare const DUPLICATE_CONDITIONAL: 'The same pseudo selector or at-rule cannot be used more than once.';
27
+ export declare type DUPLICATE_CONDITIONAL = typeof DUPLICATE_CONDITIONAL;
20
28
  export declare const ESCAPED_STYLEX_VALUE: 'Escaping a create() value is not allowed.';
29
+ export declare type ESCAPED_STYLEX_VALUE = typeof ESCAPED_STYLEX_VALUE;
21
30
  export declare const ILLEGAL_NESTED_PSEUDO: "Pseudo objects can't be nested more than one level deep.";
31
+ export declare type ILLEGAL_NESTED_PSEUDO = typeof ILLEGAL_NESTED_PSEUDO;
22
32
  export declare const ILLEGAL_PROP_VALUE: 'A style value can only contain an array, string or number.';
33
+ export declare type ILLEGAL_PROP_VALUE = typeof ILLEGAL_PROP_VALUE;
23
34
  export declare const ILLEGAL_PROP_ARRAY_VALUE: 'A style array value can only contain strings or numbers.';
35
+ export declare type ILLEGAL_PROP_ARRAY_VALUE = typeof ILLEGAL_PROP_ARRAY_VALUE;
24
36
  export declare const ILLEGAL_NAMESPACE_VALUE: 'A StyleX namespace must be an object.';
37
+ export declare type ILLEGAL_NAMESPACE_VALUE = typeof ILLEGAL_NAMESPACE_VALUE;
25
38
  export declare const INVALID_CONST_KEY: 'Keys in defineConsts() cannot start with "--".';
39
+ export declare type INVALID_CONST_KEY = typeof INVALID_CONST_KEY;
26
40
  export declare const INVALID_PSEUDO: 'Invalid pseudo selector, not on the whitelist.';
41
+ export declare type INVALID_PSEUDO = typeof INVALID_PSEUDO;
27
42
  export declare const INVALID_PSEUDO_OR_AT_RULE: 'Invalid pseudo or at-rule.';
43
+ export declare type INVALID_PSEUDO_OR_AT_RULE =
44
+ typeof INVALID_PSEUDO_OR_AT_RULE;
28
45
  export declare const INVALID_MEDIA_QUERY_SYNTAX: 'Invalid media query syntax.';
46
+ export declare type INVALID_MEDIA_QUERY_SYNTAX =
47
+ typeof INVALID_MEDIA_QUERY_SYNTAX;
29
48
  export declare const LINT_UNCLOSED_FUNCTION: 'Rule contains an unclosed function';
49
+ export declare type LINT_UNCLOSED_FUNCTION = typeof LINT_UNCLOSED_FUNCTION;
30
50
  export declare const LOCAL_ONLY: 'The return value of create() should not be exported.';
51
+ export declare type LOCAL_ONLY = typeof LOCAL_ONLY;
31
52
  export declare const NON_OBJECT_KEYFRAME: 'Every frame within a keyframes() call must be an object.';
53
+ export declare type NON_OBJECT_KEYFRAME = typeof NON_OBJECT_KEYFRAME;
32
54
  export declare const NON_CONTIGUOUS_VARS: 'All variables passed to firstThatWorks() must be contiguous.';
55
+ export declare type NON_CONTIGUOUS_VARS = typeof NON_CONTIGUOUS_VARS;
33
56
  export declare const NO_OBJECT_SPREADS: 'Object spreads are not allowed in create() calls.';
57
+ export declare type NO_OBJECT_SPREADS = typeof NO_OBJECT_SPREADS;
34
58
  export declare const ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS: 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.';
59
+ export declare type ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS =
60
+ typeof ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS;
35
61
  export declare const ONLY_TOP_LEVEL: 'create() is only allowed at the root of a program.';
62
+ export declare type ONLY_TOP_LEVEL = typeof ONLY_TOP_LEVEL;
36
63
  export declare const UNKNOWN_PROP_KEY: 'Unknown property key';
64
+ export declare type UNKNOWN_PROP_KEY = typeof UNKNOWN_PROP_KEY;
37
65
  export declare const POSITION_TRY_INVALID_PROPERTY: 'Invalid property in `positionTry()` call. It may only contain, positionAnchor, positionArea, inset properties (top, left, insetInline etc.), margin properties, size properties (height, inlineSize, etc.), and self-alignment properties (alignSelf, justifySelf, placeSelf)';
66
+ export declare type POSITION_TRY_INVALID_PROPERTY =
67
+ typeof POSITION_TRY_INVALID_PROPERTY;
38
68
  export declare const VIEW_TRANSITION_CLASS_INVALID_PROPERTY: 'Invalid property in `viewTransitionClass()` call. It may only contain group, imagePair, old, and new properties';
69
+ export declare type VIEW_TRANSITION_CLASS_INVALID_PROPERTY =
70
+ typeof VIEW_TRANSITION_CLASS_INVALID_PROPERTY;
@@ -10,6 +10,6 @@
10
10
  import type { StyleXOptions } from '../common-types';
11
11
  declare function generateLTR(
12
12
  pair: Readonly<[string, string]>,
13
- options: StyleXOptions,
13
+ options?: StyleXOptions,
14
14
  ): Readonly<[string, string]>;
15
15
  export default generateLTR;
@@ -10,5 +10,5 @@
10
10
  import type { StyleXOptions } from '../common-types';
11
11
  declare export default function generateLTR(
12
12
  pair: $ReadOnly<[string, string]>,
13
- options: StyleXOptions,
13
+ options?: StyleXOptions,
14
14
  ): $ReadOnly<[string, string]>;
@@ -10,6 +10,6 @@
10
10
  import type { StyleXOptions } from '../common-types';
11
11
  declare function generateRTL(
12
12
  pair: Readonly<[string, string]>,
13
- options: StyleXOptions,
13
+ options?: StyleXOptions,
14
14
  ): null | undefined | Readonly<[string, string]>;
15
15
  export default generateRTL;
@@ -10,5 +10,5 @@
10
10
  import type { StyleXOptions } from '../common-types';
11
11
  declare export default function generateRTL(
12
12
  pair: $ReadOnly<[string, string]>,
13
- options: StyleXOptions,
13
+ options?: StyleXOptions,
14
14
  ): ?$ReadOnly<[string, string]>;