@stylexjs/babel-plugin 0.16.2 → 0.16.3

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 (34) hide show
  1. package/lib/index.d.ts +5 -5
  2. package/lib/index.js +58 -14
  3. package/lib/index.js.flow +1 -1
  4. package/lib/shared/common-types.d.ts +3 -4
  5. package/lib/shared/stylex-create-theme.d.ts +1 -1
  6. package/lib/shared/stylex-define-vars.d.ts +3 -3
  7. package/lib/shared/types/index.js.flow +11 -11
  8. package/lib/utils/add-sourcemap-data.js.flow +2 -2
  9. package/lib/utils/ast-helpers.js.flow +3 -3
  10. package/lib/utils/evaluate-path.js.flow +2 -2
  11. package/lib/utils/js-to-ast.js.flow +1 -1
  12. package/lib/utils/state-manager.d.ts +36 -19
  13. package/lib/utils/state-manager.js.flow +36 -22
  14. package/lib/utils/validate.d.ts +1 -0
  15. package/lib/utils/validate.js.flow +2 -0
  16. package/lib/visitors/imports.js.flow +2 -2
  17. package/lib/visitors/parse-stylex-create-arg.js.flow +2 -2
  18. package/lib/visitors/stylex-create-theme.js.flow +2 -2
  19. package/lib/visitors/stylex-create.js.flow +2 -2
  20. package/lib/visitors/stylex-default-marker.js.flow +2 -2
  21. package/lib/visitors/stylex-define-consts.js.flow +2 -2
  22. package/lib/visitors/stylex-define-vars.js.flow +2 -2
  23. package/lib/visitors/stylex-keyframes.js.flow +2 -2
  24. package/lib/visitors/stylex-merge.js.flow +2 -2
  25. package/lib/visitors/stylex-position-try.js.flow +2 -2
  26. package/lib/visitors/stylex-props.js.flow +2 -2
  27. package/lib/visitors/stylex-view-transition-class.js.flow +2 -2
  28. package/package.json +3 -3
  29. package/flow_modules/@babel/core/index.js.flow +0 -854
  30. package/flow_modules/@babel/generator/index.js.flow +0 -216
  31. package/flow_modules/@babel/helper-module-imports/index.js.flow +0 -182
  32. package/flow_modules/@babel/parser/index.js.flow +0 -253
  33. package/flow_modules/@babel/traverse/index.js.flow +0 -1007
  34. package/flow_modules/@babel/types/index.js.flow +0 -5225
package/lib/index.d.ts CHANGED
@@ -39,10 +39,10 @@ declare function processStylexRules(
39
39
  config?:
40
40
  | boolean
41
41
  | {
42
- useLayers?: boolean,
43
- enableLTRRTLComments?: boolean,
44
- legacyDisableLayers?: boolean,
45
- }
42
+ useLayers?: boolean;
43
+ enableLTRRTLComments?: boolean;
44
+ legacyDisableLayers?: boolean;
45
+ },
46
46
  ): string;
47
47
  export type StyleXTransformObj = Readonly<{
48
48
  (): PluginObj;
@@ -50,4 +50,4 @@ export type StyleXTransformObj = Readonly<{
50
50
  processStylexRules: typeof processStylexRules;
51
51
  }>;
52
52
  declare const $$EXPORT_DEFAULT_DECLARATION$$: StyleXTransformObj;
53
- export = $$EXPORT_DEFAULT_DECLARATION$$;
53
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
package/lib/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var t = require('@babel/types');
4
- var path = require('path');
5
- var fs = require('fs');
6
- var url$1 = require('url');
4
+ var path = require('node:path');
5
+ var fs = require('node:fs');
6
+ var url$1 = require('node:url');
7
7
  var importMetaResolve = require('@dual-bundle/import-meta-resolve');
8
8
  var require$$0 = require('assert');
9
9
  var core = require('@babel/core');
@@ -48,6 +48,12 @@ const boolean = (message = defaultMessage('a boolean')) => (value, name) => {
48
48
  }
49
49
  return value;
50
50
  };
51
+ const func = (message = defaultMessage('a function')) => (value, name) => {
52
+ if (typeof value !== 'function') {
53
+ return new Error(message(value, name));
54
+ }
55
+ return value;
56
+ };
51
57
  const literal = (expected, message = defaultMessage(`the literal ${JSON.stringify(expected)}`)) => (value, name) => {
52
58
  if (value === expected) {
53
59
  return expected;
@@ -128,6 +134,25 @@ const unionOf3 = (a, b, c, message = defaultUnionMessage('one of')) => (value, n
128
134
  }
129
135
  return new Error(`${message(value, name)}${indent(resultA.message)}${indent(resultB.message)}${indent(resultC.message)}\nBut got: ${JSON.stringify(value)}`);
130
136
  };
137
+ const unionOf4 = (a, b, c, d, message = defaultUnionMessage('one of')) => (value, name) => {
138
+ const resultA = a(value);
139
+ if (!(resultA instanceof Error)) {
140
+ return resultA;
141
+ }
142
+ const resultB = b(value);
143
+ if (!(resultB instanceof Error)) {
144
+ return resultB;
145
+ }
146
+ const resultC = c(value);
147
+ if (!(resultC instanceof Error)) {
148
+ return resultC;
149
+ }
150
+ const resultD = d(value);
151
+ if (!(resultD instanceof Error)) {
152
+ return resultD;
153
+ }
154
+ return new Error(`${message(value, name)}${indent(resultA.message)}${indent(resultB.message)}${indent(resultC.message)}${indent(resultD.message)}\nBut got: ${JSON.stringify(value)}`);
155
+ };
131
156
  const logAndDefault = (check, value, def, name) => {
132
157
  const result = check(value, name);
133
158
  if (result instanceof Error) {
@@ -770,13 +795,18 @@ function getProgramStatement(path) {
770
795
  return programPath;
771
796
  }
772
797
 
773
- const CheckModuleResolution = unionOf3(object({
798
+ const CheckModuleResolution = unionOf4(object({
774
799
  type: literal('commonJS'),
775
800
  rootDir: unionOf(nullish(), string()),
776
801
  themeFileExtension: unionOf(nullish(), string())
777
802
  }), object({
778
803
  type: literal('haste'),
779
804
  themeFileExtension: unionOf(nullish(), string())
805
+ }), object({
806
+ type: literal('custom'),
807
+ themeFileExtension: unionOf(nullish(), string()),
808
+ filePathResolver: func(),
809
+ getCanonicalFilePath: func()
780
810
  }), object({
781
811
  type: literal('experimental_crossFileParsing'),
782
812
  rootDir: string(),
@@ -828,7 +858,7 @@ class StateManager {
828
858
  const enableFontSizePxToRem = logAndDefault(boolean(), options.enableFontSizePxToRem ?? false, false, 'options.enableFontSizePxToRem');
829
859
  const enableInlinedConditionalMerge = logAndDefault(boolean(), options.enableInlinedConditionalMerge ?? true, true, 'options.enableInlinedConditionalMerge');
830
860
  const enableMinifiedKeys = logAndDefault(boolean(), options.enableMinifiedKeys ?? true, true, 'options.enableMinifiedKeys');
831
- const enableMediaQueryOrder = logAndDefault(boolean(), options.enableMediaQueryOrder ?? false, false, 'options.enableMediaQueryOrder');
861
+ const enableMediaQueryOrder = logAndDefault(boolean(), options.enableMediaQueryOrder ?? true, true, 'options.enableMediaQueryOrder');
832
862
  const enableLegacyValueFlipping = logAndDefault(boolean(), options.enableLegacyValueFlipping ?? false, false, 'options.enableLegacyValueFlipping');
833
863
  const enableLogicalStylesPolyfill = logAndDefault(boolean(), options.enableLogicalStylesPolyfill ?? false, false, 'options.enableLogicalStylesPolyfill');
834
864
  const enableLTRRTLComments = logAndDefault(boolean(), options.enableLTRRTLComments ?? false, false, 'options.enableLTRRTLComments');
@@ -935,12 +965,20 @@ class StateManager {
935
965
  get fileNameForHashing() {
936
966
  const filename = this.filename;
937
967
  const themeFileExtension = this.options.unstable_moduleResolution?.themeFileExtension ?? '.stylex';
938
- if (filename == null || !matchesFileSuffix(themeFileExtension)(filename) || this.options.unstable_moduleResolution == null) {
968
+ const constsFileExtension = `${themeFileExtension}.const`;
969
+ if (filename == null || this.options.unstable_moduleResolution == null) {
939
970
  return null;
940
971
  }
941
- switch (this.options.unstable_moduleResolution.type) {
972
+ const isThemeFile = matchesFileSuffix(themeFileExtension)(filename);
973
+ const isConstsOnlyFile = matchesFileSuffix(constsFileExtension)(filename);
974
+ if (!isThemeFile && !isConstsOnlyFile) {
975
+ return null;
976
+ }
977
+ switch (this.options.unstable_moduleResolution?.type) {
942
978
  case 'haste':
943
979
  return path.basename(filename);
980
+ case 'custom':
981
+ return this.options.unstable_moduleResolution.getCanonicalFilePath(filename);
944
982
  default:
945
983
  return this.getCanonicalFilePath(filename);
946
984
  }
@@ -983,10 +1021,12 @@ class StateManager {
983
1021
  return false;
984
1022
  }
985
1023
  const themeFileExtension = this.options.unstable_moduleResolution?.themeFileExtension ?? '.stylex';
1024
+ const constsFileExtension = `${themeFileExtension}.const`;
986
1025
  const transformedVarsFileExtension = '.transformed';
987
1026
  const isValidStylexFile = matchesFileSuffix(themeFileExtension)(importPath);
988
1027
  const isValidTransformedVarsFile = matchesFileSuffix(transformedVarsFileExtension)(importPath);
989
- if (!isValidStylexFile && !isValidTransformedVarsFile) {
1028
+ const isValidConstsOnlyFile = matchesFileSuffix(constsFileExtension)(importPath);
1029
+ if (!isValidStylexFile && !isValidTransformedVarsFile && !isValidConstsOnlyFile) {
990
1030
  return false;
991
1031
  }
992
1032
  switch (this.options.unstable_moduleResolution?.type) {
@@ -1000,6 +1040,13 @@ class StateManager {
1000
1040
  {
1001
1041
  return ['themeNameRef', addFileExtension(importPath, sourceFilePath)];
1002
1042
  }
1043
+ case 'custom':
1044
+ {
1045
+ const aliases = this.options.aliases;
1046
+ const moduleResolution = this.options.unstable_moduleResolution;
1047
+ const result = moduleResolution.filePathResolver(importPath, sourceFilePath, aliases);
1048
+ return result ? ['themeNameRef', moduleResolution.getCanonicalFilePath(result)] : false;
1049
+ }
1003
1050
  case 'experimental_crossFileParsing':
1004
1051
  {
1005
1052
  const aliases = this.options.aliases;
@@ -4018,7 +4065,7 @@ function requireMediaQuery () {
4018
4065
  })), mediaAndRulesParser, mediaOrRulesParser, simplePairParser, mediaWordRuleParser, () => notParser, () => mediaOrRulesParser.surroundedBy(_tokenParser.TokenParser.tokens.OpenParen, _tokenParser.TokenParser.tokens.CloseParen), () => mediaAndRulesParser.surroundedBy(_tokenParser.TokenParser.tokens.OpenParen, _tokenParser.TokenParser.tokens.CloseParen)).skip(_tokenParser.TokenParser.tokens.Whitespace.optional);
4019
4066
  notParser = _tokenParser.TokenParser.sequence(_tokenParser.TokenParser.tokens.OpenParen, _tokenParser.TokenParser.string('not'), _tokenParser.TokenParser.tokens.Whitespace, getNormalRuleParser(), _tokenParser.TokenParser.tokens.CloseParen).map(([_openParen, _not, _space, rule, _closeParen]) => ({
4020
4067
  type: 'not',
4021
- rule
4068
+ rule: rule
4022
4069
  }));
4023
4070
  function isNumericLength(val) {
4024
4071
  return typeof val === 'object' && val !== null && !Array.isArray(val) && typeof val.value === 'number' && typeof val.unit === 'string' && (val.type === 'integer' || val.type === 'number');
@@ -6507,14 +6554,11 @@ function convertToTestStyles(obj, varName, state) {
6507
6554
  }
6508
6555
 
6509
6556
  function convertObjectToAST(obj) {
6510
- return t__namespace.objectExpression(Object.entries(obj).map(([key, value]) => t__namespace.objectProperty(canBeIdentifier(key) ? t__namespace.identifier(key) : t__namespace.stringLiteral(key), typeof value === 'string' ? t__namespace.stringLiteral(value) : typeof value === 'number' ? t__namespace.numericLiteral(value) : typeof value === 'boolean' ? t__namespace.booleanLiteral(value) : value === null ? t__namespace.nullLiteral() : convertObjectToAST(value))));
6557
+ return t__namespace.objectExpression(Object.entries(obj).map(([key, value]) => t__namespace.objectProperty(t__namespace.isValidIdentifier(key, false) ? t__namespace.identifier(key) : t__namespace.stringLiteral(key), typeof value === 'string' ? t__namespace.stringLiteral(value) : typeof value === 'number' ? t__namespace.numericLiteral(value) : typeof value === 'boolean' ? t__namespace.booleanLiteral(value) : value === null ? t__namespace.nullLiteral() : convertObjectToAST(value))));
6511
6558
  }
6512
6559
  function removeObjectsWithSpreads(obj) {
6513
6560
  return Object.fromEntries(Object.entries(obj).filter(Boolean));
6514
6561
  }
6515
- function canBeIdentifier(str) {
6516
- return str.match(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/) != null;
6517
- }
6518
6562
 
6519
6563
  const IMPORT_FILE_PARSING_ERROR = `There was error when attempting to parse the imported file.
6520
6564
  Please ensure that the 'babelrc' file is configured to be able to parse this file.
@@ -6557,7 +6601,7 @@ function deopt(path, state, reason) {
6557
6601
  state.deoptReason = reason;
6558
6602
  }
6559
6603
  function evaluateImportedFile(filePath, namedExport, state, bindingPath) {
6560
- const fs = require('fs');
6604
+ const fs = require('node:fs');
6561
6605
  const fileContents = fs.readFileSync(filePath, 'utf8');
6562
6606
  const ast = core.parseSync(fileContents, {
6563
6607
  babelrc: true
package/lib/index.js.flow CHANGED
@@ -7,7 +7,7 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { PluginObj } from '../flow_modules/@babel/core';
10
+ import type { PluginObj } from '@babel/core';
11
11
  import type { StyleXOptions } from './utils/state-manager';
12
12
 
13
13
  export type Options = StyleXOptions;
@@ -33,10 +33,9 @@ export type CompiledStyles = Readonly<{
33
33
  | string
34
34
  | Readonly<{ [$$Key$$: string]: null | string }>;
35
35
  }>;
36
- export type FlatCompiledStyles = Readonly<{
37
- [$$Key$$: string]: string | null;
38
- $$css: true | string;
39
- }>;
36
+ export type FlatCompiledStyles = Readonly<
37
+ { [$$Key$$: string]: string | null } & { $$css: true | string }
38
+ >;
40
39
  export type StyleXOptions = Readonly<{
41
40
  classNamePrefix: string;
42
41
  debug: null | undefined | boolean;
@@ -20,7 +20,7 @@ declare function styleXCreateTheme(
20
20
  },
21
21
  options?: StyleXOptions,
22
22
  ): [
23
- { $$css: true; readonly [$$Key$$: string]: string },
23
+ { $$css: true } & { readonly [$$Key$$: string]: string },
24
24
  { [$$Key$$: string]: InjectableStyle },
25
25
  ];
26
26
  export default styleXCreateTheme;
@@ -10,17 +10,17 @@
10
10
  import type { InjectableStyle, StyleXOptions } from './common-types';
11
11
  import type { VarsConfig } from './stylex-vars-utils';
12
12
  type VarsKeysWithStringValues<Vars extends VarsConfig> = Readonly<{
13
- [$$Key$$: keyof Vars]: string;
13
+ [$$Key$$ in keyof Vars]: string;
14
14
  }>;
15
15
  type VarsObject<Vars extends VarsConfig> = Readonly<
16
- Omit<VarsKeysWithStringValues<Vars>, keyof ({ __varGroupHash__: string })> & {
16
+ Omit<VarsKeysWithStringValues<Vars>, keyof { __varGroupHash__: string }> & {
17
17
  __varGroupHash__: string;
18
18
  }
19
19
  >;
20
20
  declare function styleXDefineVars<Vars extends VarsConfig>(
21
21
  variables: Vars,
22
22
  options: Readonly<
23
- Omit<Partial<StyleXOptions>, keyof ({ exportId: string })> & {
23
+ Omit<Partial<StyleXOptions>, keyof { exportId: string }> & {
24
24
  exportId: string;
25
25
  }
26
26
  >,
@@ -79,7 +79,7 @@ declare export class Angle<+T: AngleValue>
79
79
  }
80
80
  declare export const angle: <T: AngleValue = AngleValue>(
81
81
  value: ValueWithDefault,
82
- // $FlowIgnore[method-unbinding]
82
+ // $FlowFixMe[method-unbinding]
83
83
  ) => Angle<T>;
84
84
 
85
85
  type ColorValue = string;
@@ -93,7 +93,7 @@ declare export class Color<+T: ColorValue>
93
93
  }
94
94
  declare export const color: <T: ColorValue = ColorValue>(
95
95
  value: ValueWithDefault,
96
- // $FlowIgnore[method-unbinding]
96
+ // $FlowFixMe[method-unbinding]
97
97
  ) => Color<T>;
98
98
 
99
99
  type URLValue = string;
@@ -123,7 +123,7 @@ declare export class Image<+T: ImageValue>
123
123
  }
124
124
  declare export const image: <T: ImageValue = ImageValue>(
125
125
  value: ValueWithDefault,
126
- // $FlowIgnore[method-unbinding]
126
+ // $FlowFixMe[method-unbinding]
127
127
  ) => Image<T>;
128
128
 
129
129
  type IntegerValue = number;
@@ -157,7 +157,7 @@ declare export class LengthPercentage<+_T: LengthPercentageValue>
157
157
  }
158
158
  declare export const lengthPercentage: <_T: LengthPercentageValue | number>(
159
159
  value: ValueWithDefault,
160
- // $FlowIgnore[method-unbinding]
160
+ // $FlowFixMe[method-unbinding]
161
161
  ) => LengthPercentage<string>;
162
162
 
163
163
  type LengthValue = number | string;
@@ -174,7 +174,7 @@ declare export class Length<+_T: LengthValue>
174
174
  }
175
175
  declare export const length: <T: LengthValue = LengthValue>(
176
176
  value: NestedWithNumbers,
177
- // $FlowIgnore[method-unbinding]
177
+ // $FlowFixMe[method-unbinding]
178
178
  ) => Length<T>;
179
179
 
180
180
  type PercentageValue = string | number;
@@ -191,7 +191,7 @@ declare export class Percentage<+_T: PercentageValue>
191
191
  }
192
192
  declare export const percentage: <T: PercentageValue = PercentageValue>(
193
193
  value: NestedWithNumbers,
194
- // $FlowIgnore[method-unbinding]
194
+ // $FlowFixMe[method-unbinding]
195
195
  ) => Percentage<T>;
196
196
 
197
197
  type NumberValue = number;
@@ -206,7 +206,7 @@ declare export class Num<+T: NumberValue>
206
206
  }
207
207
  declare export const number: <T: NumberValue = NumberValue>(
208
208
  value: NestedWithNumbers,
209
- // $FlowIgnore[method-unbinding]
209
+ // $FlowFixMe[method-unbinding]
210
210
  ) => Num<T>;
211
211
 
212
212
  type ResolutionValue = string | 0;
@@ -223,7 +223,7 @@ declare export class Resolution<+T: ResolutionValue>
223
223
  }
224
224
  declare export const resolution: <T: ResolutionValue = ResolutionValue>(
225
225
  value: ValueWithDefault,
226
- // $FlowIgnore[method-unbinding]
226
+ // $FlowFixMe[method-unbinding]
227
227
  ) => Resolution<T>;
228
228
 
229
229
  type TimeValue = string | 0;
@@ -238,7 +238,7 @@ declare export class Time<+T: TimeValue>
238
238
  }
239
239
  declare export const time: <T: TimeValue = TimeValue>(
240
240
  value: ValueWithDefault,
241
- // $FlowIgnore[method-unbinding]
241
+ // $FlowFixMe[method-unbinding]
242
242
  ) => Time<T>;
243
243
 
244
244
  type TransformFunctionValue = string;
@@ -257,7 +257,7 @@ declare export const transformFunction: <
257
257
  T: TransformFunctionValue = TransformFunctionValue,
258
258
  >(
259
259
  value: ValueWithDefault,
260
- // $FlowIgnore[method-unbinding]
260
+ // $FlowFixMe[method-unbinding]
261
261
  ) => TransformFunction<T>;
262
262
 
263
263
  type TransformListValue = string;
@@ -276,5 +276,5 @@ declare export const transformList: <
276
276
  T: TransformListValue = TransformListValue,
277
277
  >(
278
278
  value: ValueWithDefault,
279
- // $FlowIgnore[method-unbinding]
279
+ // $FlowFixMe[method-unbinding]
280
280
  ) => TransformList<T>;
@@ -7,10 +7,10 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { NodePath } from '../../flow_modules/@babel/traverse';
10
+ import type { NodePath } from '@babel/traverse';
11
11
  import type { CompiledNamespaces } from '../shared';
12
12
 
13
- import * as t from '../../flow_modules/@babel/types';
13
+ import * as t from '@babel/types';
14
14
  import StateManager from './state-manager';
15
15
 
16
16
  /**
@@ -7,14 +7,14 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { ImportOptions } from '../../flow_modules/@babel/helper-module-imports';
11
- import type { NodePath } from '../../flow_modules/@babel/traverse';
10
+ import type { ImportOptions } from '@babel/helper-module-imports';
11
+ import type { NodePath } from '@babel/traverse';
12
12
  type ImportAdditionOptions = Omit<
13
13
  Partial<ImportOptions>,
14
14
  'ensureLiveReference' | 'ensureNoContext',
15
15
  >;
16
16
 
17
- import * as t from '../../flow_modules/@babel/types';
17
+ import * as t from '@babel/types';
18
18
 
19
19
  declare export function hoistExpression(
20
20
  path: NodePath<>,
@@ -21,9 +21,9 @@
21
21
  * - It can handle object spreads when the spread value itself is statically evaluated.
22
22
  */
23
23
 
24
- import type { NodePath } from '../../flow_modules/@babel/traverse';
24
+ import type { NodePath } from '@babel/traverse';
25
25
 
26
- import * as t from '../../flow_modules/@babel/types';
26
+ import * as t from '@babel/types';
27
27
  import StateManager from './state-manager';
28
28
  export type FunctionConfig = {
29
29
  identifiers: {
@@ -9,7 +9,7 @@
9
9
 
10
10
  import type { FlatCompiledStyles } from '../shared/common-types';
11
11
 
12
- import * as t from '../../flow_modules/@babel/types';
12
+ import * as t from '@babel/types';
13
13
 
14
14
  type NestedStringObject = $ReadOnly<{
15
15
  [key: string]: string | number | null | boolean | NestedStringObject,
@@ -28,6 +28,19 @@ type ModuleResolution =
28
28
  type: 'experimental_crossFileParsing';
29
29
  rootDir?: string;
30
30
  themeFileExtension?: null | undefined | string;
31
+ }>
32
+ | Readonly<{
33
+ type: 'custom';
34
+ themeFileExtension?: null | undefined | string;
35
+ filePathResolver: (
36
+ importPath: string,
37
+ sourceFilePath: string,
38
+ aliases:
39
+ | null
40
+ | undefined
41
+ | Readonly<{ [$$Key$$: string]: ReadonlyArray<string> }>,
42
+ ) => string | void;
43
+ getCanonicalFilePath: (filePath: string) => string;
31
44
  }>;
32
45
  export type StyleXOptions = Readonly<
33
46
  Omit<
@@ -158,36 +171,40 @@ declare class StateManager {
158
171
  getCanonicalFilePath(filePath: string): string;
159
172
  importPathResolver(importPath: string): ImportPathResolution;
160
173
  addStyle(
161
- style: [
162
- string,
163
- (
164
- | { ltr: string; rtl?: string | null }
165
- | {
166
- constKey: string;
167
- constVal: string | number;
168
- rtl?: string | null;
169
- ltr: string;
170
- }
171
- ),
172
- number,
173
- ],
174
- ): void;
175
- registerStyles(
176
- styles: ReadonlyArray<
174
+ style: Readonly<
177
175
  [
178
176
  string,
179
177
  (
180
- | { ltr: string; rtl?: string | null }
181
- | {
178
+ | Readonly<{ ltr: string; rtl?: string | null }>
179
+ | Readonly<{
182
180
  constKey: string;
183
181
  constVal: string | number;
184
182
  rtl?: string | null;
185
183
  ltr: string;
186
- }
184
+ }>
187
185
  ),
188
186
  number,
189
187
  ]
190
188
  >,
189
+ ): void;
190
+ registerStyles(
191
+ styles: ReadonlyArray<
192
+ Readonly<
193
+ [
194
+ string,
195
+ (
196
+ | Readonly<{ ltr: string; rtl?: string | null }>
197
+ | Readonly<{
198
+ constKey: string;
199
+ constVal: string | number;
200
+ rtl?: string | null;
201
+ ltr: string;
202
+ }>
203
+ ),
204
+ number,
205
+ ]
206
+ >
207
+ >,
191
208
  path?: null | undefined | NodePath,
192
209
  ): void;
193
210
  markComposedNamespace(
@@ -7,13 +7,13 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { PluginPass } from '../../flow_modules/@babel/core';
11
- import type { NodePath } from '../../flow_modules/@babel/traverse';
10
+ import type { PluginPass } from '@babel/core';
11
+ import type { NodePath } from '@babel/traverse';
12
12
  import type {
13
13
  CompiledNamespaces,
14
14
  StyleXOptions as RuntimeOptions,
15
15
  } from '../shared';
16
- import * as t from '../../flow_modules/@babel/types';
16
+ import * as t from '@babel/types';
17
17
  export type ImportPathResolution =
18
18
  | false
19
19
  | ['themeNameRef' | 'filePath', string];
@@ -32,6 +32,16 @@ type ModuleResolution =
32
32
  type: 'experimental_crossFileParsing',
33
33
  rootDir?: string,
34
34
  themeFileExtension?: ?string,
35
+ }>
36
+ | $ReadOnly<{
37
+ type: 'custom',
38
+ themeFileExtension?: ?string,
39
+ filePathResolver: (
40
+ importPath: string,
41
+ sourceFilePath: string,
42
+ aliases: ?$ReadOnly<{ [string]: $ReadOnlyArray<string> }>,
43
+ ) => string | void,
44
+ getCanonicalFilePath: (filePath: string) => string,
35
45
  }>;
36
46
 
37
47
  export type StyleXOptions = $ReadOnly<{
@@ -110,36 +120,40 @@ declare export default class StateManager {
110
120
  getCanonicalFilePath(filePath: string): string;
111
121
  importPathResolver(importPath: string): ImportPathResolution;
112
122
  addStyle(
113
- style: [
114
- string,
115
- (
116
- | { ltr: string, rtl?: string | null }
117
- | {
118
- constKey: string,
119
- constVal: string | number,
120
- rtl?: string | null,
121
- ltr: string,
122
- }
123
- ),
124
- number,
125
- ],
126
- ): void;
127
- registerStyles(
128
- styles: $ReadOnlyArray<
123
+ style: $ReadOnly<
129
124
  [
130
125
  string,
131
126
  (
132
- | { ltr: string, rtl?: string | null }
133
- | {
127
+ | $ReadOnly<{ ltr: string, rtl?: string | null }>
128
+ | $ReadOnly<{
134
129
  constKey: string,
135
130
  constVal: string | number,
136
131
  rtl?: string | null,
137
132
  ltr: string,
138
- }
133
+ }>
139
134
  ),
140
135
  number,
141
136
  ],
142
137
  >,
138
+ ): void;
139
+ registerStyles(
140
+ styles: $ReadOnlyArray<
141
+ $ReadOnly<
142
+ [
143
+ string,
144
+ (
145
+ | $ReadOnly<{ ltr: string, rtl?: string | null }>
146
+ | $ReadOnly<{
147
+ constKey: string,
148
+ constVal: string | number,
149
+ rtl?: string | null,
150
+ ltr: string,
151
+ }>
152
+ ),
153
+ number,
154
+ ],
155
+ >,
156
+ >,
143
157
  path?: ?NodePath<>,
144
158
  ): void;
145
159
  markComposedNamespace(
@@ -22,6 +22,7 @@ export declare const string: PrimitiveChecker<string>;
22
22
  export declare const nullish: PrimitiveChecker<null | void>;
23
23
  export declare const boolean: PrimitiveChecker<boolean>;
24
24
  export declare const number: PrimitiveChecker<number>;
25
+ export declare const func: <T extends Function>(msg?: Msg) => Check<T>;
25
26
  export declare const literal: <T extends string | number | boolean>(
26
27
  $$PARAM_0$$: T,
27
28
  msg?: Msg,
@@ -21,6 +21,8 @@ declare export const boolean: PrimitiveChecker<boolean>;
21
21
 
22
22
  declare export const number: PrimitiveChecker<number>;
23
23
 
24
+ declare export const func: <T: Function>(msg?: Msg) => Check<T>;
25
+
24
26
  declare export const literal: <T: string | number | boolean>(
25
27
  T,
26
28
  msg?: Msg,
@@ -7,9 +7,9 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { NodePath } from '../../flow_modules/@babel/traverse';
10
+ import type { NodePath } from '@babel/traverse';
11
11
 
12
- import * as t from '../../flow_modules/@babel/types';
12
+ import * as t from '@babel/types';
13
13
  import StateManager from '../utils/state-manager';
14
14
 
15
15
  // Read imports of react and remember the name of the local variables for later
@@ -8,10 +8,10 @@
8
8
  */
9
9
 
10
10
  /* eslint-disable no-unused-vars */
11
- import type { NodePath } from '../../flow_modules/@babel/traverse';
11
+ import type { NodePath } from '@babel/traverse';
12
12
  import type { FunctionConfig } from '../utils/evaluate-path';
13
13
 
14
- import * as t from '../../flow_modules/@babel/types';
14
+ import * as t from '@babel/types';
15
15
  import StateManager from '../utils/state-manager';
16
16
  type TInlineStyles = {
17
17
  [string]: {
@@ -7,8 +7,8 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { NodePath } from '../../flow_modules/@babel/traverse';
11
- import * as t from '../../flow_modules/@babel/types';
10
+ import type { NodePath } from '@babel/traverse';
11
+ import * as t from '@babel/types';
12
12
  import StateManager from '../utils/state-manager';
13
13
  /// This function looks for `stylex.createTheme` calls and transforms them.
14
14
  /// 1. It finds the first two arguments to `stylex.createTheme` and validates those.
@@ -7,8 +7,8 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { NodePath } from '../../flow_modules/@babel/traverse';
11
- import * as t from '../../flow_modules/@babel/types';
10
+ import type { NodePath } from '@babel/traverse';
11
+ import * as t from '@babel/types';
12
12
  import StateManager from '../utils/state-manager';
13
13
  /// This function looks for `stylex.create` calls and transforms them.
14
14
  /// 1. It finds the first argument to `stylex.create` and validates it.
@@ -7,9 +7,9 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { NodePath } from '../../flow_modules/@babel/traverse';
10
+ import type { NodePath } from '@babel/traverse';
11
11
 
12
- import * as t from '../../flow_modules/@babel/types';
12
+ import * as t from '@babel/types';
13
13
  import StateManager from '../utils/state-manager';
14
14
  /**
15
15
  * Transforms calls to `stylex.defaultMarker()` (or imported `defaultMarker()`)
@@ -7,9 +7,9 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { NodePath } from '../../flow_modules/@babel/traverse';
10
+ import type { NodePath } from '@babel/traverse';
11
11
 
12
- import * as t from '../../flow_modules/@babel/types';
12
+ import * as t from '@babel/types';
13
13
  import StateManager from '../utils/state-manager';
14
14
 
15
15
  /// This function looks for `stylex.defineConsts` calls and transforms them.