@stylexjs/babel-plugin 0.0.0-6e16619c

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 (151) hide show
  1. package/README.md +33 -0
  2. package/flow_modules/@babel/core/index.js.flow +854 -0
  3. package/flow_modules/@babel/generator/index.js.flow +216 -0
  4. package/flow_modules/@babel/helper-module-imports/index.js.flow +182 -0
  5. package/flow_modules/@babel/parser/index.js.flow +253 -0
  6. package/flow_modules/@babel/traverse/index.js.flow +1007 -0
  7. package/flow_modules/@babel/types/index.js.flow +5225 -0
  8. package/lib/babel-path-utils.d.ts +1100 -0
  9. package/lib/babel-path-utils.js.flow +1108 -0
  10. package/lib/index.d.ts +47 -0
  11. package/lib/index.js +8760 -0
  12. package/lib/index.js.flow +60 -0
  13. package/lib/shared/common-types.d.ts +60 -0
  14. package/lib/shared/common-types.js.flow +74 -0
  15. package/lib/shared/hash.d.ts +12 -0
  16. package/lib/shared/hash.js.flow +12 -0
  17. package/lib/shared/index.d.ts +57 -0
  18. package/lib/shared/index.js.flow +66 -0
  19. package/lib/shared/messages.d.ts +38 -0
  20. package/lib/shared/messages.js.flow +44 -0
  21. package/lib/shared/physical-rtl/generate-ltr.d.ts +15 -0
  22. package/lib/shared/physical-rtl/generate-ltr.js.flow +14 -0
  23. package/lib/shared/physical-rtl/generate-rtl.d.ts +15 -0
  24. package/lib/shared/physical-rtl/generate-rtl.js.flow +14 -0
  25. package/lib/shared/preprocess-rules/PreRule.d.ts +51 -0
  26. package/lib/shared/preprocess-rules/PreRule.js.flow +63 -0
  27. package/lib/shared/preprocess-rules/application-order.d.ts +183 -0
  28. package/lib/shared/preprocess-rules/application-order.js.flow +134 -0
  29. package/lib/shared/preprocess-rules/basic-validation.d.ts +13 -0
  30. package/lib/shared/preprocess-rules/basic-validation.js.flow +13 -0
  31. package/lib/shared/preprocess-rules/flatten-raw-style-obj.d.ts +20 -0
  32. package/lib/shared/preprocess-rules/flatten-raw-style-obj.js.flow +23 -0
  33. package/lib/shared/preprocess-rules/index.d.ts +18 -0
  34. package/lib/shared/preprocess-rules/index.js.flow +22 -0
  35. package/lib/shared/preprocess-rules/legacy-expand-shorthands.d.ts +157 -0
  36. package/lib/shared/preprocess-rules/legacy-expand-shorthands.js.flow +136 -0
  37. package/lib/shared/preprocess-rules/property-specificity.d.ts +78 -0
  38. package/lib/shared/preprocess-rules/property-specificity.js.flow +87 -0
  39. package/lib/shared/stylex-consts-utils.d.ts +11 -0
  40. package/lib/shared/stylex-consts-utils.js.flow +14 -0
  41. package/lib/shared/stylex-create-theme.d.ts +26 -0
  42. package/lib/shared/stylex-create-theme.js.flow +19 -0
  43. package/lib/shared/stylex-create.d.ts +27 -0
  44. package/lib/shared/stylex-create.js.flow +37 -0
  45. package/lib/shared/stylex-define-consts.d.ts +23 -0
  46. package/lib/shared/stylex-define-consts.js.flow +19 -0
  47. package/lib/shared/stylex-define-vars.d.ts +28 -0
  48. package/lib/shared/stylex-define-vars.js.flow +26 -0
  49. package/lib/shared/stylex-first-that-works.d.ts +13 -0
  50. package/lib/shared/stylex-first-that-works.js.flow +12 -0
  51. package/lib/shared/stylex-keyframes.d.ts +17 -0
  52. package/lib/shared/stylex-keyframes.js.flow +20 -0
  53. package/lib/shared/stylex-position-try.d.ts +15 -0
  54. package/lib/shared/stylex-position-try.js.flow +18 -0
  55. package/lib/shared/stylex-vars-utils.d.ts +27 -0
  56. package/lib/shared/stylex-vars-utils.js.flow +31 -0
  57. package/lib/shared/stylex-view-transition-class.d.ts +22 -0
  58. package/lib/shared/stylex-view-transition-class.js.flow +23 -0
  59. package/lib/shared/types/index.d.ts +240 -0
  60. package/lib/shared/types/index.js.flow +280 -0
  61. package/lib/shared/utils/Rule.d.ts +58 -0
  62. package/lib/shared/utils/Rule.js.flow +64 -0
  63. package/lib/shared/utils/convert-to-className.d.ts +21 -0
  64. package/lib/shared/utils/convert-to-className.js.flow +29 -0
  65. package/lib/shared/utils/dashify.d.ts +11 -0
  66. package/lib/shared/utils/dashify.js.flow +10 -0
  67. package/lib/shared/utils/default-options.d.ts +11 -0
  68. package/lib/shared/utils/default-options.js.flow +12 -0
  69. package/lib/shared/utils/file-based-identifier.d.ts +15 -0
  70. package/lib/shared/utils/file-based-identifier.js.flow +14 -0
  71. package/lib/shared/utils/genCSSRule.d.ts +15 -0
  72. package/lib/shared/utils/genCSSRule.js.flow +15 -0
  73. package/lib/shared/utils/generate-css-rule.d.ts +19 -0
  74. package/lib/shared/utils/generate-css-rule.js.flow +19 -0
  75. package/lib/shared/utils/normalize-value.d.ts +16 -0
  76. package/lib/shared/utils/normalize-value.js.flow +16 -0
  77. package/lib/shared/utils/normalizers/convert-camel-case-values.d.ts +14 -0
  78. package/lib/shared/utils/normalizers/convert-camel-case-values.js.flow +13 -0
  79. package/lib/shared/utils/normalizers/detect-unclosed-fns.d.ts +17 -0
  80. package/lib/shared/utils/normalizers/detect-unclosed-fns.js.flow +16 -0
  81. package/lib/shared/utils/normalizers/font-size-px-to-rem.d.ts +19 -0
  82. package/lib/shared/utils/normalizers/font-size-px-to-rem.js.flow +18 -0
  83. package/lib/shared/utils/normalizers/leading-zero.d.ts +17 -0
  84. package/lib/shared/utils/normalizers/leading-zero.js.flow +16 -0
  85. package/lib/shared/utils/normalizers/quotes.d.ts +18 -0
  86. package/lib/shared/utils/normalizers/quotes.js.flow +17 -0
  87. package/lib/shared/utils/normalizers/timings.d.ts +18 -0
  88. package/lib/shared/utils/normalizers/timings.js.flow +17 -0
  89. package/lib/shared/utils/normalizers/whitespace.d.ts +19 -0
  90. package/lib/shared/utils/normalizers/whitespace.js.flow +18 -0
  91. package/lib/shared/utils/normalizers/zero-dimensions.d.ts +19 -0
  92. package/lib/shared/utils/normalizers/zero-dimensions.js.flow +18 -0
  93. package/lib/shared/utils/object-utils.d.ts +66 -0
  94. package/lib/shared/utils/object-utils.js.flow +78 -0
  95. package/lib/shared/utils/property-priorities.d.ts +17 -0
  96. package/lib/shared/utils/property-priorities.js.flow +78 -0
  97. package/lib/shared/utils/rule-utils.d.ts +15 -0
  98. package/lib/shared/utils/rule-utils.js.flow +16 -0
  99. package/lib/shared/utils/split-css-value.d.ts +14 -0
  100. package/lib/shared/utils/split-css-value.js.flow +15 -0
  101. package/lib/shared/utils/transform-value.d.ts +22 -0
  102. package/lib/shared/utils/transform-value.js.flow +25 -0
  103. package/lib/shared/validate.d.ts +12 -0
  104. package/lib/shared/validate.js.flow +12 -0
  105. package/lib/utils/add-sourcemap-data.d.ts +23 -0
  106. package/lib/utils/add-sourcemap-data.js.flow +25 -0
  107. package/lib/utils/ast-helpers.d.ts +37 -0
  108. package/lib/utils/ast-helpers.js.flow +44 -0
  109. package/lib/utils/dev-classname.d.ts +26 -0
  110. package/lib/utils/dev-classname.js.flow +32 -0
  111. package/lib/utils/evaluate-path.d.ts +51 -0
  112. package/lib/utils/evaluate-path.js.flow +61 -0
  113. package/lib/utils/evaluation-errors.d.ts +22 -0
  114. package/lib/utils/evaluation-errors.js.flow +35 -0
  115. package/lib/utils/helpers.d.ts +12 -0
  116. package/lib/utils/helpers.js.flow +10 -0
  117. package/lib/utils/js-to-ast.d.ts +20 -0
  118. package/lib/utils/js-to-ast.js.flow +24 -0
  119. package/lib/utils/state-manager.d.ts +203 -0
  120. package/lib/utils/state-manager.js.flow +159 -0
  121. package/lib/utils/validate.d.ts +68 -0
  122. package/lib/utils/validate.js.flow +74 -0
  123. package/lib/visitors/imports.d.ts +20 -0
  124. package/lib/visitors/imports.js.flow +25 -0
  125. package/lib/visitors/parse-stylex-create-arg.d.ts +37 -0
  126. package/lib/visitors/parse-stylex-create-arg.js.flow +42 -0
  127. package/lib/visitors/stylex-attrs.d.ts +21 -0
  128. package/lib/visitors/stylex-attrs.js.flow +25 -0
  129. package/lib/visitors/stylex-create/index.d.ts +17 -0
  130. package/lib/visitors/stylex-create/index.js.flow +24 -0
  131. package/lib/visitors/stylex-create/parse-stylex-create-arg.d.ts +37 -0
  132. package/lib/visitors/stylex-create/parse-stylex-create-arg.js.flow +41 -0
  133. package/lib/visitors/stylex-create-theme.d.ts +17 -0
  134. package/lib/visitors/stylex-create-theme.js.flow +23 -0
  135. package/lib/visitors/stylex-create.d.ts +17 -0
  136. package/lib/visitors/stylex-create.js.flow +24 -0
  137. package/lib/visitors/stylex-define-consts.d.ts +17 -0
  138. package/lib/visitors/stylex-define-consts.js.flow +25 -0
  139. package/lib/visitors/stylex-define-vars.d.ts +17 -0
  140. package/lib/visitors/stylex-define-vars.js.flow +23 -0
  141. package/lib/visitors/stylex-keyframes.d.ts +17 -0
  142. package/lib/visitors/stylex-keyframes.js.flow +23 -0
  143. package/lib/visitors/stylex-merge.d.ts +21 -0
  144. package/lib/visitors/stylex-merge.js.flow +25 -0
  145. package/lib/visitors/stylex-position-try.d.ts +17 -0
  146. package/lib/visitors/stylex-position-try.js.flow +22 -0
  147. package/lib/visitors/stylex-props.d.ts +21 -0
  148. package/lib/visitors/stylex-props.js.flow +25 -0
  149. package/lib/visitors/stylex-view-transition-class.d.ts +17 -0
  150. package/lib/visitors/stylex-view-transition-class.js.flow +22 -0
  151. package/package.json +42 -0
@@ -0,0 +1,42 @@
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
+ /* eslint-disable no-unused-vars */
11
+ import type { NodePath } from '../../flow_modules/@babel/traverse';
12
+ import type { FunctionConfig } from '../utils/evaluate-path';
13
+
14
+ import * as t from '../../flow_modules/@babel/types';
15
+ import StateManager from '../utils/state-manager';
16
+ type TInlineStyles = {
17
+ [string]: {
18
+ +path: $ReadOnlyArray<string>,
19
+ +originalExpression: t.Expression,
20
+ +expression: t.Expression | t.PatternLike,
21
+ },
22
+ };
23
+
24
+ type DynamicFns = {
25
+ [string]: [
26
+ +params: Array<t.Identifier>,
27
+ +inlineStyles: $ReadOnly<TInlineStyles>,
28
+ ],
29
+ };
30
+
31
+ // This
32
+ declare export function evaluateStyleXCreateArg(
33
+ path: NodePath<>,
34
+ traversalState: StateManager,
35
+ functions: FunctionConfig,
36
+ ): $ReadOnly<{
37
+ confident: boolean,
38
+ value: any,
39
+ deopt?: null | NodePath<>,
40
+ reason?: string,
41
+ fns?: DynamicFns,
42
+ }>;
@@ -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
+ *
8
+ */
9
+
10
+ import type { NodePath } from '@babel/traverse';
11
+ import * as t from '@babel/types';
12
+ import StateManager from '../utils/state-manager';
13
+ export declare function skipStylexAttrsChildren(
14
+ path: NodePath<t.CallExpression>,
15
+ state: StateManager,
16
+ ): void;
17
+ declare function transformStylexAttrs(
18
+ path: NodePath<t.CallExpression>,
19
+ state: StateManager,
20
+ ): void;
21
+ export default transformStylexAttrs;
@@ -0,0 +1,25 @@
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
+
12
+ import * as t from '../../flow_modules/@babel/types';
13
+ import StateManager from '../utils/state-manager';
14
+ declare export function skipStylexAttrsChildren(
15
+ path: NodePath<t.CallExpression>,
16
+ state: StateManager,
17
+ ): void;
18
+
19
+ // If a `stylex()` call uses styles that are all locally defined,
20
+ // This function is able to pre-compute that into a single string or
21
+ // a single expression of strings and ternary expressions.
22
+ declare export default function transformStylexAttrs(
23
+ path: NodePath<t.CallExpression>,
24
+ state: StateManager,
25
+ ): void;
@@ -0,0 +1,17 @@
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 * as t from '@babel/types';
11
+ import type { NodePath } from '@babel/traverse';
12
+ import StateManager from '../../utils/state-manager';
13
+ declare function transformStyleXCreate(
14
+ path: NodePath<t.CallExpression>,
15
+ state: StateManager,
16
+ ): void;
17
+ export default transformStyleXCreate;
@@ -0,0 +1,24 @@
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 * as t from '../../../flow_modules/@babel/types';
11
+ import type { NodePath } from '../../../flow_modules/@babel/traverse';
12
+ import StateManager from '../../utils/state-manager';
13
+ /// This function looks for `stylex.create` calls and transforms them.
14
+ /// 1. It finds the first argument to `stylex.create` and validates it.
15
+ /// 2. It pre-processes valid-dynamic parts of style object such as custom presets (spreads)
16
+ /// 3. It evaluates the style object to get a JS object. This also handles local constants automatically.
17
+ /// 4. It uses the `stylexCreate` from `@stylexjs/shared` to transform the JS
18
+ /// object and to get a list of injected styles.
19
+ /// 5. It converts the resulting Object back into an AST and replaces the call with it.
20
+ /// 6. It also inserts `stylex.inject` calls above the current statement as needed.
21
+ declare export default function transformStyleXCreate(
22
+ path: NodePath<t.CallExpression>,
23
+ state: StateManager,
24
+ ): void;
@@ -0,0 +1,37 @@
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
+ import { type FunctionConfig } from '../../utils/evaluate-path';
14
+ type TInlineStyles = {
15
+ [$$Key$$: string]: {
16
+ readonly path: ReadonlyArray<string>;
17
+ readonly originalExpression: t.Expression;
18
+ readonly expression: t.Expression | t.PatternLike;
19
+ };
20
+ };
21
+ type DynamicFns = {
22
+ [$$Key$$: string]: readonly [
23
+ params: Array<t.Identifier>,
24
+ inlineStyles: Readonly<TInlineStyles>,
25
+ ];
26
+ };
27
+ export declare function evaluateStyleXCreateArg(
28
+ path: NodePath,
29
+ traversalState: StateManager,
30
+ functions: FunctionConfig,
31
+ ): Readonly<{
32
+ confident: boolean;
33
+ value: any;
34
+ deopt?: null | NodePath;
35
+ reason?: string;
36
+ fns?: DynamicFns;
37
+ }>;
@@ -0,0 +1,41 @@
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
+ /* eslint-disable no-unused-vars */
11
+ import type { NodePath } from '../../../flow_modules/@babel/traverse';
12
+ import * as t from '../../../flow_modules/@babel/types';
13
+ import StateManager from '../../utils/state-manager';
14
+ import { type FunctionConfig } from '../../utils/evaluate-path';
15
+ type TInlineStyles = {
16
+ [string]: {
17
+ +path: $ReadOnlyArray<string>,
18
+ +originalExpression: t.Expression,
19
+ +expression: t.Expression | t.PatternLike,
20
+ },
21
+ };
22
+
23
+ type DynamicFns = {
24
+ [string]: [
25
+ +params: Array<t.Identifier>,
26
+ +inlineStyles: $ReadOnly<TInlineStyles>,
27
+ ],
28
+ };
29
+
30
+ // This
31
+ declare export function evaluateStyleXCreateArg(
32
+ path: NodePath<>,
33
+ traversalState: StateManager,
34
+ functions: FunctionConfig,
35
+ ): $ReadOnly<{
36
+ confident: boolean,
37
+ value: any,
38
+ deopt?: null | NodePath<>,
39
+ reason?: string,
40
+ fns?: DynamicFns,
41
+ }>;
@@ -0,0 +1,17 @@
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
+ declare function transformStyleXCreateTheme(
14
+ callExpressionPath: NodePath<t.CallExpression>,
15
+ state: StateManager,
16
+ ): void;
17
+ export default transformStyleXCreateTheme;
@@ -0,0 +1,23 @@
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 * as t from '../../flow_modules/@babel/types';
12
+ import StateManager from '../utils/state-manager';
13
+ /// This function looks for `stylex.createTheme` calls and transforms them.
14
+ /// 1. It finds the first two arguments to `stylex.createTheme` and validates those.
15
+ /// 2. This handles local constants automatically.
16
+ /// 4. It uses the `stylexCreateTheme` from `@stylexjs/shared` to transform the JS
17
+ /// object and to get a list of injected styles.
18
+ /// 5. It converts the resulting Object back into an AST and replaces the call with it.
19
+ /// 6. It also inserts `stylex.inject` calls above the current statement as needed.
20
+ declare export default function transformStyleXCreateTheme(
21
+ callExpressionPath: NodePath<t.CallExpression>,
22
+ state: StateManager,
23
+ ): void;
@@ -0,0 +1,17 @@
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
+ declare function transformStyleXCreate(
14
+ path: NodePath<t.CallExpression>,
15
+ state: StateManager,
16
+ ): void;
17
+ export default transformStyleXCreate;
@@ -0,0 +1,24 @@
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 * as t from '../../flow_modules/@babel/types';
12
+ import StateManager from '../utils/state-manager';
13
+ /// This function looks for `stylex.create` calls and transforms them.
14
+ /// 1. It finds the first argument to `stylex.create` and validates it.
15
+ /// 2. It pre-processes valid-dynamic parts of style object such as custom presets (spreads)
16
+ /// 3. It evaluates the style object to get a JS object. This also handles local constants automatically.
17
+ /// 4. It uses the `stylexCreate` from `@stylexjs/shared` to transform the JS
18
+ /// object and to get a list of injected styles.
19
+ /// 5. It converts the resulting Object back into an AST and replaces the call with it.
20
+ /// 6. It also inserts `stylex.inject` calls above the current statement as needed.
21
+ declare export default function transformStyleXCreate(
22
+ path: NodePath<t.CallExpression>,
23
+ state: StateManager,
24
+ ): void;
@@ -0,0 +1,17 @@
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
+ declare function transformStyleXDefineConsts(
14
+ callExpressionPath: NodePath<t.CallExpression>,
15
+ state: StateManager,
16
+ ): void;
17
+ export default transformStyleXDefineConsts;
@@ -0,0 +1,25 @@
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
+
12
+ import * as t from '../../flow_modules/@babel/types';
13
+ import StateManager from '../utils/state-manager';
14
+
15
+ /// This function looks for `stylex.defineConsts` calls and transforms them.
16
+ /// 1. It finds and validates the first argument to `stylex.defineConsts`.
17
+ /// 2. It evaluates the style const object to a JS value, erroring on non-static or non-object values.
18
+ /// 3. It generates a theme name from the filename and export name for hashing.
19
+ /// 4. It invokes `stylexDefineConsts` to transform the JS object and collect injected styles.
20
+ /// 5. It creates a map of key-value pairs of constants to be inlined.
21
+ /// 6. It replaces the call with the transformed AST and registers the styles in state.
22
+ declare export default function transformStyleXDefineConsts(
23
+ callExpressionPath: NodePath<t.CallExpression>,
24
+ state: StateManager,
25
+ ): void;
@@ -0,0 +1,17 @@
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
+ declare function transformStyleXDefineVars(
14
+ callExpressionPath: NodePath<t.CallExpression>,
15
+ state: StateManager,
16
+ ): void;
17
+ export default transformStyleXDefineVars;
@@ -0,0 +1,23 @@
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 * as t from '../../flow_modules/@babel/types';
12
+ import StateManager from '../utils/state-manager';
13
+ /// This function looks for `stylex.defineVars` calls and transforms them.
14
+ /// 1. It finds the first argument to `stylex.defineVars` and validates it.
15
+ /// 2. It evaluates the style object to get a JS object. This also handles local constants automatically.
16
+ /// 4. It uses the `stylexDefineVars` from `@stylexjs/shared` to transform the JS
17
+ /// object and to get a list of injected styles.
18
+ /// 5. It converts the resulting Object back into an AST and replaces the call with it.
19
+ /// 6. It also inserts `stylex.inject` calls above the current statement as needed.
20
+ declare export default function transformStyleXDefineVars(
21
+ callExpressionPath: NodePath<t.CallExpression>,
22
+ state: StateManager,
23
+ ): void;
@@ -0,0 +1,17 @@
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
+ declare function transformStyleXKeyframes(
14
+ path: NodePath<t.VariableDeclarator>,
15
+ state: StateManager,
16
+ ): void;
17
+ export default transformStyleXKeyframes;
@@ -0,0 +1,23 @@
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 * as t from '../../flow_modules/@babel/types';
12
+ import StateManager from '../utils/state-manager';
13
+ /// This function looks for `stylex.keyframes` calls and transforms them.
14
+ /// 1. It finds the first argument to `stylex.keyframes` and validates it.
15
+ /// 2. It evaluates the style object to get a JS object. This also handles local constants automatically.
16
+ /// 4. It uses the `stylexKeyframes` from `@stylexjs/shared` to transform the JS
17
+ /// object and to get a list of injected styles.
18
+ /// 5. It converts the resulting Object back into an AST and replaces the call with it.
19
+ /// 6. It also inserts `stylex.inject` calls above the current statement as needed.
20
+ declare export default function transformStyleXKeyframes(
21
+ path: NodePath<t.VariableDeclarator>,
22
+ state: StateManager,
23
+ ): void;
@@ -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
+ *
8
+ */
9
+
10
+ import type { NodePath } from '@babel/traverse';
11
+ import * as t from '@babel/types';
12
+ import StateManager from '../utils/state-manager';
13
+ export declare function skipStylexMergeChildren(
14
+ path: NodePath<t.CallExpression>,
15
+ state: StateManager,
16
+ ): void;
17
+ declare function transformStyleXMerge(
18
+ path: NodePath<t.CallExpression>,
19
+ state: StateManager,
20
+ ): void;
21
+ export default transformStyleXMerge;
@@ -0,0 +1,25 @@
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
+
12
+ import * as t from '../../flow_modules/@babel/types';
13
+ import StateManager from '../utils/state-manager';
14
+ declare export function skipStylexMergeChildren(
15
+ path: NodePath<t.CallExpression>,
16
+ state: StateManager,
17
+ ): void;
18
+
19
+ // If a `stylex()` call uses styles that are all locally defined,
20
+ // This function is able to pre-compute that into a single string or
21
+ // a single expression of strings and ternary expressions.
22
+ declare export default function transformStyleXMerge(
23
+ path: NodePath<t.CallExpression>,
24
+ state: StateManager,
25
+ ): void;
@@ -0,0 +1,17 @@
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
+ declare function transformStyleXPositionTry(
14
+ path: NodePath<t.VariableDeclarator>,
15
+ state: StateManager,
16
+ ): void;
17
+ export default transformStyleXPositionTry;
@@ -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 '../../flow_modules/@babel/traverse';
11
+ import * as t from '../../flow_modules/@babel/types';
12
+ import StateManager from '../utils/state-manager';
13
+ /// This function looks for `stylex.positionTry` calls within variable declarations and transforms them.
14
+ /// 1. It finds the first argument to `stylex.positionTry` and validates it.
15
+ /// 2. It evaluates the style object to get a JS object. This also handles local constants automatically.
16
+ /// 3. The actual transformation is done by `stylexPositionTry` from `../shared`
17
+ /// 4. The results are replaced, and generated CSS rules are injected as needed.
18
+
19
+ declare export default function transformStyleXPositionTry(
20
+ path: NodePath<t.VariableDeclarator>,
21
+ state: StateManager,
22
+ ): void;
@@ -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
+ *
8
+ */
9
+
10
+ import type { NodePath } from '@babel/traverse';
11
+ import * as t from '@babel/types';
12
+ import StateManager from '../utils/state-manager';
13
+ export declare function skipStylexPropsChildren(
14
+ path: NodePath<t.CallExpression>,
15
+ state: StateManager,
16
+ ): void;
17
+ declare function transformStylexProps(
18
+ path: NodePath<t.CallExpression>,
19
+ state: StateManager,
20
+ ): void;
21
+ export default transformStylexProps;
@@ -0,0 +1,25 @@
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
+
12
+ import * as t from '../../flow_modules/@babel/types';
13
+ import StateManager from '../utils/state-manager';
14
+ declare export function skipStylexPropsChildren(
15
+ path: NodePath<t.CallExpression>,
16
+ state: StateManager,
17
+ ): void;
18
+
19
+ // If a `stylex()` call uses styles that are all locally defined,
20
+ // This function is able to pre-compute that into a single string or
21
+ // a single expression of strings and ternary expressions.
22
+ declare export default function transformStylexProps(
23
+ path: NodePath<t.CallExpression>,
24
+ state: StateManager,
25
+ ): void;
@@ -0,0 +1,17 @@
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
+ declare function transformStyleXViewTransitionClass(
14
+ path: NodePath<t.VariableDeclarator>,
15
+ state: StateManager,
16
+ ): void;
17
+ export default transformStyleXViewTransitionClass;
@@ -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 '../../flow_modules/@babel/traverse';
11
+ import * as t from '../../flow_modules/@babel/types';
12
+ import StateManager from '../utils/state-manager';
13
+ /// This function looks for `stylex.viewTransitionClass` calls within variable declarations and transforms them.
14
+ /// 1. It finds the first argument to `stylex.viewTransitionClass` and validates it.
15
+ /// 2. It evaluates the style object to get a JS object. This also handles local constants automatically.
16
+ /// 3. The actual transform is done by `stylexViewTransitionClass` from `../shared`
17
+ /// 4. The results are replaced, and generated CSS rules are injected as needed.
18
+
19
+ declare export default function transformStyleXViewTransitionClass(
20
+ path: NodePath<t.VariableDeclarator>,
21
+ state: StateManager,
22
+ ): void;
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@stylexjs/babel-plugin",
3
+ "version": "0.0.0-6e16619c",
4
+ "description": "StyleX babel plugin.",
5
+ "main": "lib/index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/facebook/stylex.git"
9
+ },
10
+ "license": "MIT",
11
+ "scripts": {
12
+ "prebuild": "gen-types -i src/ -o lib/",
13
+ "build": "rollup --config ./rollup.config.mjs",
14
+ "build-haste": "HASTE=true rollup --config ./rollup.config.mjs",
15
+ "build-watch": "rollup --config ./rollup.config.mjs --watch",
16
+ "test": "jest --coverage"
17
+ },
18
+ "dependencies": {
19
+ "@babel/helper-module-imports": "^7.25.9",
20
+ "@babel/core": "^7.26.8",
21
+ "@babel/traverse": "^7.26.8",
22
+ "@babel/types": "^7.26.8",
23
+ "@dual-bundle/import-meta-resolve": "^4.1.0",
24
+ "@stylexjs/stylex": "0.15.1",
25
+ "postcss-value-parser": "^4.1.0"
26
+ },
27
+ "devDependencies": {
28
+ "@rollup/plugin-alias": "^5.1.1",
29
+ "@rollup/plugin-babel": "^6.0.4",
30
+ "@rollup/plugin-commonjs": "^28.0.1",
31
+ "@rollup/plugin-json": "^6.1.0",
32
+ "@rollup/plugin-node-resolve": "^15.3.0",
33
+ "@rollup/plugin-replace": "^6.0.1",
34
+ "babel-plugin-syntax-hermes-parser": "^0.26.0",
35
+ "rollup": "^4.24.0",
36
+ "scripts": "0.15.1"
37
+ },
38
+ "files": [
39
+ "flow_modules/*",
40
+ "lib/*"
41
+ ]
42
+ }