@stylexjs/babel-plugin 0.16.3 → 0.17.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.
Files changed (61) hide show
  1. package/lib/index.js +994 -1837
  2. package/lib/index.js.flow +1 -0
  3. package/lib/shared/common-types.d.ts +1 -0
  4. package/lib/shared/common-types.js.flow +9 -0
  5. package/lib/shared/hash.d.ts +3 -0
  6. package/lib/shared/index.d.ts +13 -1
  7. package/lib/shared/index.js.flow +1 -1
  8. package/lib/shared/messages.d.ts +32 -0
  9. package/lib/shared/physical-rtl/generate-ltr.d.ts +1 -1
  10. package/lib/shared/physical-rtl/generate-ltr.js.flow +1 -1
  11. package/lib/shared/physical-rtl/generate-rtl.d.ts +1 -1
  12. package/lib/shared/physical-rtl/generate-rtl.js.flow +1 -1
  13. package/lib/shared/preprocess-rules/application-order.d.ts +35 -34
  14. package/lib/shared/preprocess-rules/application-order.js.flow +35 -29
  15. package/lib/shared/preprocess-rules/basic-validation.d.ts +1 -1
  16. package/lib/shared/preprocess-rules/basic-validation.js.flow +1 -1
  17. package/lib/shared/preprocess-rules/legacy-expand-shorthands.d.ts +26 -15
  18. package/lib/shared/preprocess-rules/legacy-expand-shorthands.js.flow +19 -14
  19. package/lib/shared/preprocess-rules/property-specificity.d.ts +12 -11
  20. package/lib/shared/preprocess-rules/property-specificity.js.flow +12 -6
  21. package/lib/shared/stylex-define-consts.d.ts +1 -1
  22. package/lib/shared/stylex-keyframes.d.ts +1 -1
  23. package/lib/shared/stylex-keyframes.js.flow +1 -1
  24. package/lib/shared/stylex-position-try.d.ts +1 -1
  25. package/lib/shared/stylex-position-try.js.flow +1 -1
  26. package/lib/shared/stylex-vars-utils.d.ts +2 -2
  27. package/lib/shared/stylex-vars-utils.js.flow +3 -3
  28. package/lib/shared/stylex-view-transition-class.d.ts +1 -1
  29. package/lib/shared/stylex-view-transition-class.js.flow +1 -1
  30. package/lib/shared/types/index.d.ts +14 -0
  31. package/lib/shared/types/index.js.flow +1 -1
  32. package/lib/shared/utils/convert-to-className.d.ts +1 -1
  33. package/lib/shared/utils/convert-to-className.js.flow +1 -1
  34. package/lib/shared/utils/default-options.d.ts +1 -0
  35. package/lib/shared/utils/file-based-identifier.js.flow +1 -1
  36. package/lib/shared/utils/generate-css-rule.d.ts +1 -1
  37. package/lib/shared/utils/generate-css-rule.js.flow +1 -1
  38. package/lib/shared/utils/normalize-value.js.flow +1 -1
  39. package/lib/shared/utils/object-utils.d.ts +10 -8
  40. package/lib/shared/utils/object-utils.js.flow +2 -2
  41. package/lib/shared/utils/rule-utils.d.ts +2 -0
  42. package/lib/shared/utils/transform-value.d.ts +2 -0
  43. package/lib/shared/validate.js.flow +3 -1
  44. package/lib/shared/when/when.d.ts +10 -10
  45. package/lib/shared/when/when.js.flow +10 -10
  46. package/lib/utils/evaluate-path.d.ts +3 -2
  47. package/lib/utils/evaluate-path.js.flow +3 -2
  48. package/lib/utils/evaluation-errors.d.ts +15 -0
  49. package/lib/utils/js-to-ast.d.ts +0 -4
  50. package/lib/utils/js-to-ast.js.flow +0 -6
  51. package/lib/utils/state-manager.d.ts +41 -35
  52. package/lib/utils/state-manager.js.flow +5 -0
  53. package/lib/utils/validate.d.ts +18 -3
  54. package/lib/utils/validate.js.flow +5 -3
  55. package/lib/visitors/parse-stylex-create-arg.d.ts +1 -1
  56. package/lib/visitors/parse-stylex-create-arg.js.flow +1 -1
  57. package/lib/visitors/stylex-default-target.d.ts +20 -0
  58. package/lib/visitors/stylex-default-target.js.flow +21 -0
  59. package/lib/visitors/stylex-define-marker.d.ts +22 -0
  60. package/lib/visitors/stylex-define-marker.js.flow +22 -0
  61. package/package.json +5 -4
@@ -45,31 +45,32 @@ type ModuleResolution =
45
45
  export type StyleXOptions = Readonly<
46
46
  Omit<
47
47
  RuntimeOptions,
48
- keyof ({
49
- aliases?:
50
- | null
51
- | undefined
52
- | Readonly<{ [$$Key$$: string]: string | ReadonlyArray<string> }>;
53
- enableDebugClassNames?: boolean;
54
- enableDebugDataProp?: boolean;
55
- enableDevClassNames?: boolean;
56
- enableInlinedConditionalMerge?: boolean;
57
- enableMediaQueryOrder?: boolean;
58
- enableLegacyValueFlipping?: boolean;
59
- enableLogicalStylesPolyfill?: boolean;
60
- enableLTRRTLComments?: boolean;
61
- enableMinifiedKeys?: boolean;
62
- importSources: ReadonlyArray<
63
- string | Readonly<{ from: string; as: string }>
64
- >;
65
- rewriteAliases?: boolean;
66
- runtimeInjection:
67
- | boolean
68
- | (null | undefined | string)
69
- | Readonly<{ from: string; as: string }>;
70
- treeshakeCompensation?: boolean;
71
- unstable_moduleResolution?: null | undefined | ModuleResolution;
72
- })
48
+ | keyof {
49
+ aliases?:
50
+ | null
51
+ | undefined
52
+ | Readonly<{ [$$Key$$: string]: string | ReadonlyArray<string> }>;
53
+ enableDebugClassNames?: boolean;
54
+ enableDebugDataProp?: boolean;
55
+ enableDevClassNames?: boolean;
56
+ enableInlinedConditionalMerge?: boolean;
57
+ enableMediaQueryOrder?: boolean;
58
+ enableLegacyValueFlipping?: boolean;
59
+ enableLogicalStylesPolyfill?: boolean;
60
+ enableLTRRTLComments?: boolean;
61
+ enableMinifiedKeys?: boolean;
62
+ importSources: ReadonlyArray<
63
+ string | Readonly<{ from: string; as: string }>
64
+ >;
65
+ rewriteAliases?: boolean;
66
+ runtimeInjection:
67
+ | boolean
68
+ | (null | undefined | string)
69
+ | Readonly<{ from: string; as: string }>;
70
+ treeshakeCompensation?: boolean;
71
+ unstable_moduleResolution?: null | undefined | ModuleResolution;
72
+ debugFilePath?: (filePath: string) => string;
73
+ }
73
74
  > & {
74
75
  aliases?:
75
76
  | null
@@ -94,21 +95,22 @@ export type StyleXOptions = Readonly<
94
95
  | Readonly<{ from: string; as: string }>;
95
96
  treeshakeCompensation?: boolean;
96
97
  unstable_moduleResolution?: null | undefined | ModuleResolution;
98
+ debugFilePath?: (filePath: string) => string;
97
99
  }
98
100
  >;
99
101
  type StyleXStateOptions = Readonly<
100
102
  Omit<
101
103
  StyleXOptions,
102
- keyof ({
103
- runtimeInjection:
104
- | (null | undefined | string)
105
- | Readonly<{ from: string; as: null | undefined | string }>;
106
- aliases?:
107
- | null
108
- | undefined
109
- | Readonly<{ [$$Key$$: string]: ReadonlyArray<string> }>;
110
- rewriteAliases: boolean;
111
- })
104
+ | keyof {
105
+ runtimeInjection:
106
+ | (null | undefined | string)
107
+ | Readonly<{ from: string; as: null | undefined | string }>;
108
+ aliases?:
109
+ | null
110
+ | undefined
111
+ | Readonly<{ [$$Key$$: string]: ReadonlyArray<string> }>;
112
+ rewriteAliases: boolean;
113
+ }
112
114
  > & {
113
115
  runtimeInjection:
114
116
  | (null | undefined | string)
@@ -132,6 +134,7 @@ declare class StateManager {
132
134
  readonly stylexKeyframesImport: Set<string>;
133
135
  readonly stylexPositionTryImport: Set<string>;
134
136
  readonly stylexDefineVarsImport: Set<string>;
137
+ readonly stylexDefineMarkerImport: Set<string>;
135
138
  readonly stylexDefineConstsImport: Set<string>;
136
139
  readonly stylexCreateThemeImport: Set<string>;
137
140
  readonly stylexTypesImport: Set<string>;
@@ -217,8 +220,11 @@ export declare const filePathResolver: (
217
220
  sourceFilePath: string,
218
221
  aliases: StyleXStateOptions['aliases'],
219
222
  ) => null | undefined | string;
223
+ export declare type filePathResolver = typeof filePathResolver;
220
224
  export declare const EXTENSIONS: any;
225
+ export declare type EXTENSIONS = typeof EXTENSIONS;
221
226
  export declare const matchesFileSuffix: (
222
227
  $$PARAM_0$$: string,
223
228
  ) => ($$PARAM_0$$: string) => boolean;
229
+ export declare type matchesFileSuffix = typeof matchesFileSuffix;
224
230
  export declare function getRelativePath(from: string, to: string): string;
@@ -63,6 +63,7 @@ export type StyleXOptions = $ReadOnly<{
63
63
  runtimeInjection: boolean | ?string | $ReadOnly<{ from: string, as: string }>,
64
64
  treeshakeCompensation?: boolean,
65
65
  unstable_moduleResolution?: ?ModuleResolution,
66
+ debugFilePath?: (filePath: string) => string,
66
67
  ...
67
68
  }>;
68
69
 
@@ -76,6 +77,7 @@ type StyleXStateOptions = $ReadOnly<{
76
77
 
77
78
  declare export default class StateManager {
78
79
  +_state: PluginPass;
80
+ // Imports
79
81
  +importPaths: Set<string>;
80
82
  +stylexImport: Set<string>;
81
83
  +stylexPropsImport: Set<string>;
@@ -86,6 +88,7 @@ declare export default class StateManager {
86
88
  +stylexKeyframesImport: Set<string>;
87
89
  +stylexPositionTryImport: Set<string>;
88
90
  +stylexDefineVarsImport: Set<string>;
91
+ +stylexDefineMarkerImport: Set<string>;
89
92
  +stylexDefineConstsImport: Set<string>;
90
93
  +stylexCreateThemeImport: Set<string>;
91
94
  +stylexTypesImport: Set<string>;
@@ -93,8 +96,10 @@ declare export default class StateManager {
93
96
  +stylexDefaultMarkerImport: Set<string>;
94
97
  +stylexWhenImport: Set<string>;
95
98
  injectImportInserted: ?t.Identifier;
99
+ // `stylex.create` calls
96
100
  +styleMap: Map<string, CompiledNamespaces>;
97
101
  +styleVars: Map<string, NodePath<>>;
102
+ // results of `stylex.create` calls that should be kept
98
103
  +styleVarsToKeep: Set<[string, true | string, true | Array<string>]>;
99
104
  inStyleXCreate: boolean;
100
105
  +options: StyleXStateOptions;
@@ -19,18 +19,27 @@ export type InferCheckType<T> =
19
19
  type Msg = (value: unknown, name?: string) => string;
20
20
  type PrimitiveChecker<T> = (message?: Msg) => Check<T>;
21
21
  export declare const string: PrimitiveChecker<string>;
22
+ export declare type string = typeof string;
22
23
  export declare const nullish: PrimitiveChecker<null | void>;
24
+ export declare type nullish = typeof nullish;
25
+ export declare const optional: <T>($$PARAM_0$$: Check<T>) => Check<void | T>;
26
+ export declare type optional = typeof optional;
23
27
  export declare const boolean: PrimitiveChecker<boolean>;
28
+ export declare type boolean = typeof boolean;
24
29
  export declare const number: PrimitiveChecker<number>;
30
+ export declare type number = typeof number;
25
31
  export declare const func: <T extends Function>(msg?: Msg) => Check<T>;
32
+ export declare type func = typeof func;
26
33
  export declare const literal: <T extends string | number | boolean>(
27
34
  $$PARAM_0$$: T,
28
35
  msg?: Msg,
29
36
  ) => Check<T>;
37
+ export declare type literal = typeof literal;
30
38
  export declare const array: <T>(
31
39
  $$PARAM_0$$: Check<T>,
32
40
  msg?: Msg,
33
41
  ) => Check<ReadonlyArray<T>>;
42
+ export declare type array = typeof array;
34
43
  type ObjOfChecks<T extends { readonly [$$Key$$: string]: Check<unknown> }> =
35
44
  Readonly<{ [K in keyof T]: InferCheckType<T[K]> }>;
36
45
  export declare const object: <
@@ -39,31 +48,37 @@ export declare const object: <
39
48
  $$PARAM_0$$: T,
40
49
  msg?: Msg,
41
50
  ) => Check<ObjOfChecks<T>>;
51
+ export declare type object = typeof object;
42
52
  export declare const objectOf: <T>(
43
53
  $$PARAM_0$$: Check<T>,
44
54
  message?: Msg,
45
55
  ) => Check<{ readonly [$$Key$$: string]: T }>;
56
+ export declare type objectOf = typeof objectOf;
46
57
  export declare const unionOf: <A, B>(
47
58
  a: Check<A>,
48
59
  b: Check<B>,
49
- message: Msg,
60
+ message?: Msg,
50
61
  ) => Check<A | B>;
62
+ export declare type unionOf = typeof unionOf;
51
63
  export declare const unionOf3: <A, B, C>(
52
64
  a: Check<A>,
53
65
  b: Check<B>,
54
66
  c: Check<C>,
55
- message: Msg,
67
+ message?: Msg,
56
68
  ) => Check<A | B | C>;
69
+ export declare type unionOf3 = typeof unionOf3;
57
70
  export declare const unionOf4: <A, B, C, D>(
58
71
  a: Check<A>,
59
72
  b: Check<B>,
60
73
  c: Check<C>,
61
74
  d: Check<D>,
62
- message: Msg,
75
+ message?: Msg,
63
76
  ) => Check<A | B | C | D>;
77
+ export declare type unionOf4 = typeof unionOf4;
64
78
  export declare const logAndDefault: <T>(
65
79
  check: Check<T>,
66
80
  value: unknown,
67
81
  def: T,
68
82
  name?: string,
69
83
  ) => T;
84
+ export declare type logAndDefault = typeof logAndDefault;
@@ -17,6 +17,8 @@ declare export const string: PrimitiveChecker<string>;
17
17
 
18
18
  declare export const nullish: PrimitiveChecker<null | void>;
19
19
 
20
+ declare export const optional: <T>(Check<T>) => Check<void | T>;
21
+
20
22
  declare export const boolean: PrimitiveChecker<boolean>;
21
23
 
22
24
  declare export const number: PrimitiveChecker<number>;
@@ -50,14 +52,14 @@ declare export const objectOf: <T>(
50
52
  declare export const unionOf: <A, B>(
51
53
  a: Check<A>,
52
54
  b: Check<B>,
53
- message: Msg,
55
+ message?: Msg,
54
56
  ) => Check<A | B>;
55
57
 
56
58
  declare export const unionOf3: <A, B, C>(
57
59
  a: Check<A>,
58
60
  b: Check<B>,
59
61
  c: Check<C>,
60
- message: Msg,
62
+ message?: Msg,
61
63
  ) => Check<A | B | C>;
62
64
 
63
65
  declare export const unionOf4: <A, B, C, D>(
@@ -65,7 +67,7 @@ declare export const unionOf4: <A, B, C, D>(
65
67
  b: Check<B>,
66
68
  c: Check<C>,
67
69
  d: Check<D>,
68
- message: Msg,
70
+ message?: Msg,
69
71
  ) => Check<A | B | C | D>;
70
72
 
71
73
  declare export const logAndDefault: <T>(
@@ -27,7 +27,7 @@ type DynamicFns = {
27
27
  export declare function evaluateStyleXCreateArg(
28
28
  path: NodePath,
29
29
  traversalState: StateManager,
30
- functions: FunctionConfig,
30
+ functions?: FunctionConfig,
31
31
  ): Readonly<{
32
32
  confident: boolean;
33
33
  value: any;
@@ -32,7 +32,7 @@ type DynamicFns = {
32
32
  declare export function evaluateStyleXCreateArg(
33
33
  path: NodePath<>,
34
34
  traversalState: StateManager,
35
- functions: FunctionConfig,
35
+ functions?: FunctionConfig,
36
36
  ): $ReadOnly<{
37
37
  confident: boolean,
38
38
  value: any,
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
10
+ import type { NodePath } from '@babel/traverse';
11
+ import type StateManager from '../utils/state-manager';
12
+ import * as t from '@babel/types';
13
+ /**
14
+ * Transform `stylex.defaultTarget` calls and property access to use the configured classNamePrefix
15
+ */
16
+ declare function transformStyleXDefaultTarget(
17
+ path: NodePath<t.CallExpression | t.MemberExpression>,
18
+ state: StateManager,
19
+ ): void;
20
+ export default transformStyleXDefaultTarget;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type { NodePath } from '../../flow_modules/@babel/traverse';
11
+ import type StateManager from '../utils/state-manager';
12
+
13
+ import * as t from '../../flow_modules/@babel/types';
14
+
15
+ /**
16
+ * Transform `stylex.defaultTarget` calls and property access to use the configured classNamePrefix
17
+ */
18
+ declare export default function transformStyleXDefaultTarget(
19
+ path: NodePath<t.CallExpression | t.MemberExpression>,
20
+ state: StateManager,
21
+ ): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
10
+ import type { NodePath } from '@babel/traverse';
11
+ import * as t from '@babel/types';
12
+ import StateManager from '../utils/state-manager';
13
+ /**
14
+ * Transforms calls to `stylex.defineMarker()` (or imported `defineMarker()`)
15
+ * into an object: { $$css: true, [hash]: hash } where `hash` is generated from
16
+ * the file path and the export name.
17
+ */
18
+ declare function transformStyleXDefineMarker(
19
+ path: NodePath<t.CallExpression>,
20
+ state: StateManager,
21
+ ): void;
22
+ export default transformStyleXDefineMarker;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type { NodePath } from '@babel/traverse';
11
+
12
+ import * as t from '@babel/types';
13
+ import StateManager from '../utils/state-manager';
14
+ /**
15
+ * Transforms calls to `stylex.defineMarker()` (or imported `defineMarker()`)
16
+ * into an object: { $$css: true, [hash]: hash } where `hash` is generated from
17
+ * the file path and the export name.
18
+ */
19
+ declare export default function transformStyleXDefineMarker(
20
+ path: NodePath<t.CallExpression>,
21
+ state: StateManager,
22
+ ): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/babel-plugin",
3
- "version": "0.16.3",
3
+ "version": "0.17.1",
4
4
  "description": "StyleX babel plugin.",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -21,7 +21,8 @@
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.3",
24
+ "@stylexjs/shared": "0.17.1",
25
+ "@stylexjs/stylex": "0.17.1",
25
26
  "postcss-value-parser": "^4.1.0"
26
27
  },
27
28
  "devDependencies": {
@@ -31,9 +32,9 @@
31
32
  "@rollup/plugin-json": "^6.1.0",
32
33
  "@rollup/plugin-node-resolve": "^15.3.0",
33
34
  "@rollup/plugin-replace": "^6.0.1",
34
- "babel-plugin-syntax-hermes-parser": "^0.26.0",
35
+ "babel-plugin-syntax-hermes-parser": "^0.32.1",
35
36
  "rollup": "^4.24.0",
36
- "scripts": "0.16.3"
37
+ "scripts": "0.17.1"
37
38
  },
38
39
  "files": [
39
40
  "flow_modules/*",