@stylexjs/babel-plugin 0.12.0 → 0.13.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 (119) hide show
  1. package/lib/index.js +3758 -2215
  2. package/lib/index.js.flow +11 -1
  3. package/lib/shared/common-types.d.ts +57 -0
  4. package/lib/shared/common-types.js.flow +71 -0
  5. package/lib/shared/hash.d.ts +12 -0
  6. package/lib/shared/hash.js.flow +12 -0
  7. package/lib/shared/index.d.ts +57 -0
  8. package/lib/shared/index.js.flow +66 -0
  9. package/lib/shared/messages.d.ts +35 -0
  10. package/lib/shared/messages.js.flow +40 -0
  11. package/lib/shared/physical-rtl/generate-ltr.d.ts +13 -0
  12. package/lib/shared/physical-rtl/generate-ltr.js.flow +12 -0
  13. package/lib/shared/physical-rtl/generate-rtl.d.ts +13 -0
  14. package/lib/shared/physical-rtl/generate-rtl.js.flow +12 -0
  15. package/lib/shared/preprocess-rules/PreRule.d.ts +51 -0
  16. package/lib/shared/preprocess-rules/PreRule.js.flow +63 -0
  17. package/lib/shared/preprocess-rules/application-order.d.ts +183 -0
  18. package/lib/shared/preprocess-rules/application-order.js.flow +134 -0
  19. package/lib/shared/preprocess-rules/basic-validation.d.ts +13 -0
  20. package/lib/shared/preprocess-rules/basic-validation.js.flow +13 -0
  21. package/lib/shared/preprocess-rules/flatten-raw-style-obj.d.ts +20 -0
  22. package/lib/shared/preprocess-rules/flatten-raw-style-obj.js.flow +23 -0
  23. package/lib/shared/preprocess-rules/index.d.ts +18 -0
  24. package/lib/shared/preprocess-rules/index.js.flow +22 -0
  25. package/lib/shared/preprocess-rules/legacy-expand-shorthands.d.ts +165 -0
  26. package/lib/shared/preprocess-rules/legacy-expand-shorthands.js.flow +144 -0
  27. package/lib/shared/preprocess-rules/property-specificity.d.ts +78 -0
  28. package/lib/shared/preprocess-rules/property-specificity.js.flow +87 -0
  29. package/lib/shared/stylex-consts-utils.d.ts +11 -0
  30. package/lib/shared/stylex-consts-utils.js.flow +14 -0
  31. package/lib/shared/stylex-create-theme.d.ts +26 -0
  32. package/lib/shared/stylex-create-theme.js.flow +19 -0
  33. package/lib/shared/stylex-create.d.ts +27 -0
  34. package/lib/shared/stylex-create.js.flow +37 -0
  35. package/lib/shared/stylex-define-consts.d.ts +23 -0
  36. package/lib/shared/stylex-define-consts.js.flow +19 -0
  37. package/lib/shared/stylex-define-vars.d.ts +28 -0
  38. package/lib/shared/stylex-define-vars.js.flow +26 -0
  39. package/lib/shared/stylex-first-that-works.d.ts +13 -0
  40. package/lib/shared/stylex-first-that-works.js.flow +12 -0
  41. package/lib/shared/stylex-keyframes.d.ts +17 -0
  42. package/lib/shared/stylex-keyframes.js.flow +20 -0
  43. package/lib/shared/stylex-position-try.d.ts +15 -0
  44. package/lib/shared/stylex-position-try.js.flow +18 -0
  45. package/lib/shared/stylex-vars-utils.d.ts +27 -0
  46. package/lib/shared/stylex-vars-utils.js.flow +31 -0
  47. package/lib/shared/types/index.d.ts +240 -0
  48. package/lib/shared/types/index.js.flow +280 -0
  49. package/lib/shared/utils/Rule.d.ts +58 -0
  50. package/lib/shared/utils/Rule.js.flow +64 -0
  51. package/lib/shared/utils/convert-to-className.d.ts +21 -0
  52. package/lib/shared/utils/convert-to-className.js.flow +29 -0
  53. package/lib/shared/utils/dashify.d.ts +11 -0
  54. package/lib/shared/utils/dashify.js.flow +10 -0
  55. package/lib/shared/utils/default-options.d.ts +11 -0
  56. package/lib/shared/utils/default-options.js.flow +12 -0
  57. package/lib/shared/utils/file-based-identifier.d.ts +15 -0
  58. package/lib/shared/utils/file-based-identifier.js.flow +14 -0
  59. package/lib/shared/utils/genCSSRule.d.ts +15 -0
  60. package/lib/shared/utils/genCSSRule.js.flow +15 -0
  61. package/lib/shared/utils/generate-css-rule.d.ts +18 -0
  62. package/lib/shared/utils/generate-css-rule.js.flow +19 -0
  63. package/lib/shared/utils/normalize-value.d.ts +16 -0
  64. package/lib/shared/utils/normalize-value.js.flow +16 -0
  65. package/lib/shared/utils/normalizers/convert-camel-case-values.d.ts +14 -0
  66. package/lib/shared/utils/normalizers/convert-camel-case-values.js.flow +13 -0
  67. package/lib/shared/utils/normalizers/detect-unclosed-fns.d.ts +17 -0
  68. package/lib/shared/utils/normalizers/detect-unclosed-fns.js.flow +16 -0
  69. package/lib/shared/utils/normalizers/font-size-px-to-rem.d.ts +19 -0
  70. package/lib/shared/utils/normalizers/font-size-px-to-rem.js.flow +18 -0
  71. package/lib/shared/utils/normalizers/leading-zero.d.ts +17 -0
  72. package/lib/shared/utils/normalizers/leading-zero.js.flow +16 -0
  73. package/lib/shared/utils/normalizers/quotes.d.ts +18 -0
  74. package/lib/shared/utils/normalizers/quotes.js.flow +17 -0
  75. package/lib/shared/utils/normalizers/timings.d.ts +18 -0
  76. package/lib/shared/utils/normalizers/timings.js.flow +17 -0
  77. package/lib/shared/utils/normalizers/whitespace.d.ts +19 -0
  78. package/lib/shared/utils/normalizers/whitespace.js.flow +18 -0
  79. package/lib/shared/utils/normalizers/zero-dimensions.d.ts +19 -0
  80. package/lib/shared/utils/normalizers/zero-dimensions.js.flow +18 -0
  81. package/lib/shared/utils/object-utils.d.ts +66 -0
  82. package/lib/shared/utils/object-utils.js.flow +78 -0
  83. package/lib/shared/utils/property-priorities.d.ts +17 -0
  84. package/lib/shared/utils/property-priorities.js.flow +78 -0
  85. package/lib/shared/utils/rule-utils.d.ts +15 -0
  86. package/lib/shared/utils/rule-utils.js.flow +16 -0
  87. package/lib/shared/utils/split-css-value.d.ts +14 -0
  88. package/lib/shared/utils/split-css-value.js.flow +15 -0
  89. package/lib/shared/utils/transform-value.d.ts +22 -0
  90. package/lib/shared/utils/transform-value.js.flow +25 -0
  91. package/lib/shared/validate.d.ts +12 -0
  92. package/lib/shared/validate.js.flow +12 -0
  93. package/lib/utils/add-sourcemap-data.d.ts +1 -1
  94. package/lib/utils/add-sourcemap-data.js.flow +1 -1
  95. package/lib/utils/dev-classname.d.ts +1 -1
  96. package/lib/utils/dev-classname.js.flow +2 -1
  97. package/lib/utils/evaluate-path.d.ts +14 -0
  98. package/lib/utils/evaluate-path.js.flow +15 -0
  99. package/lib/utils/js-to-ast.d.ts +1 -1
  100. package/lib/utils/js-to-ast.js.flow +1 -1
  101. package/lib/utils/state-manager.d.ts +34 -6
  102. package/lib/utils/state-manager.js.flow +34 -5
  103. package/lib/visitors/imports.d.ts +1 -1
  104. package/lib/visitors/imports.js.flow +2 -1
  105. package/lib/visitors/parse-stylex-create-arg.d.ts +37 -0
  106. package/lib/visitors/parse-stylex-create-arg.js.flow +42 -0
  107. package/lib/visitors/stylex-create-theme.d.ts +1 -1
  108. package/lib/visitors/stylex-create-theme.js.flow +1 -1
  109. package/lib/visitors/stylex-create.d.ts +17 -0
  110. package/lib/visitors/stylex-create.js.flow +24 -0
  111. package/lib/visitors/stylex-define-consts.d.ts +1 -14
  112. package/lib/visitors/stylex-define-consts.js.flow +9 -14
  113. package/lib/visitors/stylex-define-vars.d.ts +1 -1
  114. package/lib/visitors/stylex-define-vars.js.flow +1 -1
  115. package/lib/visitors/stylex-keyframes.d.ts +1 -1
  116. package/lib/visitors/stylex-keyframes.js.flow +1 -1
  117. package/lib/visitors/stylex-position-try.d.ts +17 -0
  118. package/lib/visitors/stylex-position-try.js.flow +22 -0
  119. package/package.json +7 -11
@@ -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
+ }>;
@@ -7,8 +7,8 @@
7
7
  *
8
8
  */
9
9
 
10
- import * as t from '@babel/types';
11
10
  import type { NodePath } from '@babel/traverse';
11
+ import * as t from '@babel/types';
12
12
  import StateManager from '../utils/state-manager';
13
13
  declare function transformStyleXCreateTheme(
14
14
  callExpressionPath: NodePath<t.CallExpression>,
@@ -7,8 +7,8 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import * as t from '../../flow_modules/@babel/types';
11
10
  import type { NodePath } from '../../flow_modules/@babel/traverse';
11
+ import * as t from '../../flow_modules/@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.
@@ -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;
@@ -7,22 +7,9 @@
7
7
  *
8
8
  */
9
9
 
10
- import * as t from '@babel/types';
11
10
  import type { NodePath } from '@babel/traverse';
11
+ import * as t from '@babel/types';
12
12
  import StateManager from '../utils/state-manager';
13
- /**
14
- * This function looks for `stylex.defineConsts` calls and transforms them.
15
- *
16
- * 1. It finds the first argument to `stylex.defineConsts` and validates it.
17
- * 2. It evaluates the constants object to get a JS object.
18
- * 3. It uses `styleXDefineConsts` to transform the object into a structured format.
19
- * 4. It converts the resulting object back into an AST and replaces the function call with it.
20
- * 5. The transformed constants are stored in metadata and used during rule processing.
21
- * 6. During CSS rule generation, any references to `var(--keyhash)` (or `var(--keyhash, fallback)`)
22
- * are replaced with their corresponding `constVal` from `defineConsts`.
23
- * 7. Unlike `stylex.defineVars`, `defineConsts` does not generate runtime CSS variables but instead
24
- * directly inlines the resolved values into the final CSS output.
25
- */
26
13
  declare function transformStyleXDefineConsts(
27
14
  callExpressionPath: NodePath<t.CallExpression>,
28
15
  state: StateManager,
@@ -7,23 +7,18 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import * as t from '../../flow_modules/@babel/types';
11
10
  import type { NodePath } from '../../flow_modules/@babel/traverse';
11
+
12
+ import * as t from '../../flow_modules/@babel/types';
12
13
  import StateManager from '../utils/state-manager';
13
14
 
14
- /**
15
- * This function looks for `stylex.defineConsts` calls and transforms them.
16
- *
17
- * 1. It finds the first argument to `stylex.defineConsts` and validates it.
18
- * 2. It evaluates the constants object to get a JS object.
19
- * 3. It uses `styleXDefineConsts` to transform the object into a structured format.
20
- * 4. It converts the resulting object back into an AST and replaces the function call with it.
21
- * 5. The transformed constants are stored in metadata and used during rule processing.
22
- * 6. During CSS rule generation, any references to `var(--keyhash)` (or `var(--keyhash, fallback)`)
23
- * are replaced with their corresponding `constVal` from `defineConsts`.
24
- * 7. Unlike `stylex.defineVars`, `defineConsts` does not generate runtime CSS variables but instead
25
- * directly inlines the resolved values into the final CSS output.
26
- */
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.
27
22
  declare export default function transformStyleXDefineConsts(
28
23
  callExpressionPath: NodePath<t.CallExpression>,
29
24
  state: StateManager,
@@ -7,8 +7,8 @@
7
7
  *
8
8
  */
9
9
 
10
- import * as t from '@babel/types';
11
10
  import type { NodePath } from '@babel/traverse';
11
+ import * as t from '@babel/types';
12
12
  import StateManager from '../utils/state-manager';
13
13
  declare function transformStyleXDefineVars(
14
14
  callExpressionPath: NodePath<t.CallExpression>,
@@ -7,8 +7,8 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import * as t from '../../flow_modules/@babel/types';
11
10
  import type { NodePath } from '../../flow_modules/@babel/traverse';
11
+ import * as t from '../../flow_modules/@babel/types';
12
12
  import StateManager from '../utils/state-manager';
13
13
  /// This function looks for `stylex.defineVars` calls and transforms them.
14
14
  /// 1. It finds the first argument to `stylex.defineVars` and validates it.
@@ -7,8 +7,8 @@
7
7
  *
8
8
  */
9
9
 
10
- import * as t from '@babel/types';
11
10
  import type { NodePath } from '@babel/traverse';
11
+ import * as t from '@babel/types';
12
12
  import StateManager from '../utils/state-manager';
13
13
  declare function transformStyleXKeyframes(
14
14
  path: NodePath<t.VariableDeclarator>,
@@ -7,8 +7,8 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import * as t from '../../flow_modules/@babel/types';
11
10
  import type { NodePath } from '../../flow_modules/@babel/traverse';
11
+ import * as t from '../../flow_modules/@babel/types';
12
12
  import StateManager from '../utils/state-manager';
13
13
  /// This function looks for `stylex.keyframes` calls and transforms them.
14
14
  /// 1. It finds the first argument to `stylex.keyframes` and validates it.
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/babel-plugin",
3
- "version": "0.12.0",
3
+ "version": "0.13.1",
4
4
  "description": "StyleX babel plugin.",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -13,7 +13,7 @@
13
13
  "build": "rollup --config ./rollup.config.mjs",
14
14
  "build-haste": "HASTE=true rollup --config ./rollup.config.mjs",
15
15
  "build-watch": "rollup --config ./rollup.config.mjs --watch",
16
- "test": "jest"
16
+ "test": "jest --coverage"
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/helper-module-imports": "^7.25.9",
@@ -21,8 +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/shared": "0.12.0",
25
- "@stylexjs/stylex": "0.12.0"
24
+ "@stylexjs/stylex": "0.13.1",
25
+ "postcss-value-parser": "^4.1.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@rollup/plugin-alias": "^5.1.1",
@@ -31,13 +31,9 @@
31
31
  "@rollup/plugin-json": "^6.1.0",
32
32
  "@rollup/plugin-node-resolve": "^15.3.0",
33
33
  "@rollup/plugin-replace": "^6.0.1",
34
- "rollup": "^4.24.0"
35
- },
36
- "jest": {
37
- "verbose": true,
38
- "snapshotFormat": {
39
- "printBasicPrototype": false
40
- }
34
+ "babel-plugin-syntax-hermes-parser": "^0.26.0",
35
+ "rollup": "^4.24.0",
36
+ "scripts": "0.13.1"
41
37
  },
42
38
  "files": [
43
39
  "flow_modules/*",