@stylexjs/babel-plugin 0.2.0-beta.16 → 0.2.0-beta.18

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 (33) hide show
  1. package/flow_modules/@babel/core/index.js.flow +854 -0
  2. package/flow_modules/@babel/generator/index.js.flow +216 -0
  3. package/flow_modules/@babel/parser/index.js.flow +252 -0
  4. package/flow_modules/@babel/traverse/index.js.flow +1002 -0
  5. package/flow_modules/@babel/types/index.js.flow +5224 -0
  6. package/lib/babel-path-utils.d.ts +1102 -0
  7. package/lib/babel-path-utils.js.flow +1108 -0
  8. package/lib/index.d.ts +15 -0
  9. package/lib/index.js +1089 -1895
  10. package/lib/index.js.flow +14 -0
  11. package/lib/utils/dev-classname.d.ts +26 -0
  12. package/lib/utils/dev-classname.js.flow +31 -0
  13. package/lib/utils/evaluate-path.d.ts +45 -0
  14. package/lib/utils/evaluate-path.js.flow +53 -0
  15. package/lib/utils/helpers.d.ts +12 -0
  16. package/lib/utils/helpers.js.flow +10 -0
  17. package/lib/utils/js-to-ast.d.ts +17 -0
  18. package/lib/utils/js-to-ast.js.flow +19 -0
  19. package/lib/utils/state-manager.d.ts +66 -0
  20. package/lib/utils/state-manager.js.flow +70 -0
  21. package/lib/visitors/imports.d.ts +20 -0
  22. package/lib/visitors/imports.js.flow +24 -0
  23. package/lib/visitors/stylex-create-vars.d.ts +17 -0
  24. package/lib/visitors/stylex-create-vars.js.flow +23 -0
  25. package/lib/visitors/stylex-create.d.ts +17 -0
  26. package/lib/visitors/stylex-create.js.flow +24 -0
  27. package/lib/visitors/stylex-keyframes.d.ts +17 -0
  28. package/lib/visitors/stylex-keyframes.js.flow +23 -0
  29. package/lib/visitors/stylex-merge.d.ts +21 -0
  30. package/lib/visitors/stylex-merge.js.flow +25 -0
  31. package/lib/visitors/stylex-override-vars.d.ts +17 -0
  32. package/lib/visitors/stylex-override-vars.js.flow +23 -0
  33. package/package.json +11 -5
@@ -0,0 +1,14 @@
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 { PluginObj } from '../flow_modules/@babel/core';
11
+ /**
12
+ * Entry point for the StyleX babel plugin.
13
+ */
14
+ declare export default function styleXTransform(): PluginObj<>;
@@ -0,0 +1,26 @@
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 { CompiledNamespaces } from '@stylexjs/shared';
11
+ import StateManager from './state-manager';
12
+ export declare function namespaceToDevClassName(
13
+ namespace: string,
14
+ varName: null | string,
15
+ filename: string,
16
+ ): string;
17
+ export declare function injectDevClassNames(
18
+ obj: CompiledNamespaces,
19
+ varName: null | string,
20
+ state: StateManager,
21
+ ): CompiledNamespaces;
22
+ export declare function convertToTestStyles(
23
+ obj: CompiledNamespaces,
24
+ varName: null | string,
25
+ state: StateManager,
26
+ ): CompiledNamespaces;
@@ -0,0 +1,31 @@
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 { CompiledNamespaces } from '@stylexjs/shared';
11
+ import StateManager from './state-manager';
12
+
13
+ // TODO: We will need to maintain the full path to the file eventually
14
+ // Perhaps this can be an option that is passed in.
15
+ declare export function namespaceToDevClassName(
16
+ namespace: string,
17
+ varName: null | string,
18
+ filename: string,
19
+ ): string;
20
+
21
+ declare export function injectDevClassNames(
22
+ obj: CompiledNamespaces,
23
+ varName: null | string,
24
+ state: StateManager,
25
+ ): CompiledNamespaces;
26
+
27
+ declare export function convertToTestStyles(
28
+ obj: CompiledNamespaces,
29
+ varName: null | string,
30
+ state: StateManager,
31
+ ): CompiledNamespaces;
@@ -0,0 +1,45 @@
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 StateManager from './state-manager';
12
+ export type FunctionConfig = {
13
+ identifiers: {
14
+ [fnName: string]: { fn: (...args: any[]) => any; takesPath?: boolean };
15
+ };
16
+ memberExpressions: {
17
+ [key: string]: {
18
+ [memberName: string]: {
19
+ fn: (...args: any[]) => any;
20
+ takesPath?: boolean;
21
+ };
22
+ };
23
+ };
24
+ };
25
+ /**
26
+ * Walk the input `node` and statically evaluate it.
27
+ *
28
+ * Returns an object in the form `{ confident, value, deopt }`. `confident`
29
+ * indicates whether or not we had to drop out of evaluating the expression
30
+ * because of hitting an unknown node that we couldn't confidently find the
31
+ * value of, in which case `deopt` is the path of said node.
32
+ *
33
+ * Example:
34
+ *
35
+ * evaluate(parse("5 + 5")) // { confident: true, value: 10 }
36
+ * evaluate(parse("!true")) // { confident: true, value: false }
37
+ * evaluate(parse("foo + foo")) // { confident: false, value: undefined, deopt: NodePath }
38
+ *
39
+ */
40
+
41
+ export declare function evaluate(
42
+ path: NodePath,
43
+ traversalState: StateManager,
44
+ functions: FunctionConfig,
45
+ ): { confident: boolean; value: any; deopt?: null | NodePath };
@@ -0,0 +1,53 @@
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 StateManager from './state-manager';
12
+ export type FunctionConfig = {
13
+ identifiers: {
14
+ [fnName: string]: {
15
+ fn: (...args: any[]) => any,
16
+ takesPath?: boolean,
17
+ },
18
+ },
19
+ memberExpressions: {
20
+ [key: string]: {
21
+ [memberName: string]: {
22
+ fn: (...args: any[]) => any,
23
+ takesPath?: boolean,
24
+ },
25
+ },
26
+ },
27
+ };
28
+
29
+ /**
30
+ * Walk the input `node` and statically evaluate it.
31
+ *
32
+ * Returns an object in the form `{ confident, value, deopt }`. `confident`
33
+ * indicates whether or not we had to drop out of evaluating the expression
34
+ * because of hitting an unknown node that we couldn't confidently find the
35
+ * value of, in which case `deopt` is the path of said node.
36
+ *
37
+ * Example:
38
+ *
39
+ * evaluate(parse("5 + 5")) // { confident: true, value: 10 }
40
+ * evaluate(parse("!true")) // { confident: true, value: false }
41
+ * evaluate(parse("foo + foo")) // { confident: false, value: undefined, deopt: NodePath }
42
+ *
43
+ */
44
+
45
+ declare export function evaluate(
46
+ path: NodePath<>,
47
+ traversalState: StateManager,
48
+ functions: FunctionConfig,
49
+ ): {
50
+ confident: boolean,
51
+ value: any,
52
+ deopt?: null | NodePath<>,
53
+ };
@@ -0,0 +1,12 @@
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
+ export declare function removeNulls<T>(
11
+ arr: Array<null | undefined | T>,
12
+ ): Array<T>;
@@ -0,0 +1,10 @@
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
+ declare export function removeNulls<T>(arr: Array<?T>): Array<T>;
@@ -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 { IncludedStyles } from '@stylexjs/shared';
12
+ type NestedStringObject = Readonly<{
13
+ [key: string]: string | null | boolean | NestedStringObject | IncludedStyles;
14
+ }>;
15
+ export declare function convertObjectToAST(
16
+ obj: NestedStringObject,
17
+ ): t.ObjectExpression;
@@ -0,0 +1,19 @@
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 { IncludedStyles } from '@stylexjs/shared';
12
+
13
+ type NestedStringObject = $ReadOnly<{
14
+ [key: string]: string | null | boolean | NestedStringObject | IncludedStyles,
15
+ }>;
16
+
17
+ declare export function convertObjectToAST(
18
+ obj: NestedStringObject,
19
+ ): t.ObjectExpression;
@@ -0,0 +1,66 @@
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 { PluginPass } from '@babel/core';
11
+ import type { NodePath } from '@babel/traverse';
12
+ import type {
13
+ CompiledNamespaces,
14
+ StyleXOptions as RuntimeOptions,
15
+ } from '@stylexjs/shared';
16
+ export type ImportPathResolution =
17
+ | false
18
+ | ['themeNameRef' | 'filePath', string];
19
+ type ModuleResolution =
20
+ | { type: 'commonJS'; rootDir: string; themeFileExtension?: string }
21
+ | { type: 'haste'; themeFileExtension?: string }
22
+ | {
23
+ type: 'experimental_crossFileParsing';
24
+ rootDir: string;
25
+ themeFileExtension?: string;
26
+ };
27
+ type StyleXOptions = Omit<
28
+ RuntimeOptions,
29
+ keyof ({
30
+ importSources: Array<string>;
31
+ genConditionalClasses: boolean;
32
+ unstable_moduleResolution: void | ModuleResolution;
33
+ })
34
+ > & {
35
+ importSources: Array<string>;
36
+ genConditionalClasses: boolean;
37
+ unstable_moduleResolution: void | ModuleResolution;
38
+ };
39
+ declare class StateManager {
40
+ readonly _state: PluginPass;
41
+ readonly stylexImport: Set<string>;
42
+ readonly stylexCreateImport: Set<string>;
43
+ readonly stylexIncludeImport: Set<string>;
44
+ readonly stylexFirstThatWorksImport: Set<string>;
45
+ readonly stylexKeyframesImport: Set<string>;
46
+ readonly stylexCreateVarsImport: Set<string>;
47
+ readonly stylexOverrideVarsImport: Set<string>;
48
+ readonly styleMap: Map<string, CompiledNamespaces>;
49
+ readonly styleVars: Map<string, NodePath>;
50
+ readonly styleVarsToKeep: Set<[string, null | string]>;
51
+ inStyleXCreate: boolean;
52
+ constructor(state: PluginPass);
53
+ get options(): StyleXOptions;
54
+ get canReferenceTheme(): boolean;
55
+ get metadata(): { [key: string]: any };
56
+ get stylexSheetName(): string | void;
57
+ get isDev(): boolean;
58
+ get isTest(): boolean;
59
+ get filename(): string | void;
60
+ get cssVars(): any;
61
+ get fileNameForHashing(): null | string;
62
+ importPathResolver(importPath: string): ImportPathResolution;
63
+ addStyle(style: [string, { ltr: string; rtl?: string | null }, number]): void;
64
+ markComposedNamespace(memberExpression: [string, null | string]): void;
65
+ }
66
+ export default StateManager;
@@ -0,0 +1,70 @@
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 { PluginPass } from '../../flow_modules/@babel/core';
11
+ import type { NodePath } from '../../flow_modules/@babel/traverse';
12
+ import type {
13
+ CompiledNamespaces,
14
+ StyleXOptions as RuntimeOptions,
15
+ } from '@stylexjs/shared';
16
+ export type ImportPathResolution =
17
+ | false
18
+ | ['themeNameRef' | 'filePath', string];
19
+
20
+ type ModuleResolution =
21
+ | {
22
+ type: 'commonJS',
23
+ rootDir: string,
24
+ themeFileExtension?: string,
25
+ }
26
+ | {
27
+ type: 'haste',
28
+ themeFileExtension?: string,
29
+ }
30
+ | {
31
+ type: 'experimental_crossFileParsing',
32
+ rootDir: string,
33
+ themeFileExtension?: string,
34
+ };
35
+
36
+ type StyleXOptions = {
37
+ ...RuntimeOptions,
38
+ importSources: Array<string>,
39
+ genConditionalClasses: boolean,
40
+ unstable_moduleResolution: void | ModuleResolution,
41
+ ...
42
+ };
43
+
44
+ declare export default class StateManager {
45
+ +_state: PluginPass;
46
+ +stylexImport: Set<string>;
47
+ +stylexCreateImport: Set<string>;
48
+ +stylexIncludeImport: Set<string>;
49
+ +stylexFirstThatWorksImport: Set<string>;
50
+ +stylexKeyframesImport: Set<string>;
51
+ +stylexCreateVarsImport: Set<string>;
52
+ +stylexOverrideVarsImport: Set<string>;
53
+ +styleMap: Map<string, CompiledNamespaces>;
54
+ +styleVars: Map<string, NodePath<>>;
55
+ +styleVarsToKeep: Set<[string, null | string]>;
56
+ inStyleXCreate: boolean;
57
+ constructor(state: PluginPass): void;
58
+ get options(): StyleXOptions;
59
+ get canReferenceTheme(): boolean;
60
+ get metadata(): { [key: string]: any };
61
+ get stylexSheetName(): string | void;
62
+ get isDev(): boolean;
63
+ get isTest(): boolean;
64
+ get filename(): string | void;
65
+ get cssVars(): any;
66
+ get fileNameForHashing(): null | string;
67
+ importPathResolver(importPath: string): ImportPathResolution;
68
+ addStyle(style: [string, { ltr: string, rtl?: string | null }, number]): void;
69
+ markComposedNamespace(memberExpression: [string, null | string]): void;
70
+ }
@@ -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 * as t from '@babel/types';
11
+ import type { NodePath } from '@babel/traverse';
12
+ import StateManager from '../utils/state-manager';
13
+ export declare function readImportDeclarations(
14
+ path: NodePath<t.ImportDeclaration>,
15
+ state: StateManager,
16
+ ): void;
17
+ export declare function readRequires(
18
+ path: NodePath<t.VariableDeclarator>,
19
+ state: StateManager,
20
+ ): void;
@@ -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
+
14
+ // Read imports of react and remember the name of the local varsiables for later
15
+ declare export function readImportDeclarations(
16
+ path: NodePath<t.ImportDeclaration>,
17
+ state: StateManager,
18
+ ): void;
19
+
20
+ // Read require calls and remember the names of the variables for later
21
+ declare export function readRequires(
22
+ path: NodePath<t.VariableDeclarator>,
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 * as t from '@babel/types';
11
+ import type { NodePath } from '@babel/traverse';
12
+ import StateManager from '../utils/state-manager';
13
+ declare function transformStyleXCreateVars(
14
+ callExpressionPath: NodePath<t.CallExpression>,
15
+ state: StateManager,
16
+ ): void;
17
+ export default transformStyleXCreateVars;
@@ -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 * 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.createVars` calls and transforms them.
14
+ //. 1. It finds the first argument to `stylex.createVars` and validates it.
15
+ /// 2. It envalues the style object to get a JS object. This also handles local constants automatically.
16
+ /// 4. It uses the `stylexCreateVars` 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 transformStyleXCreateVars(
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 * 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 envalues 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 * as t from '@babel/types';
11
+ import type { NodePath } from '@babel/traverse';
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 * 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.keyframes` calls and transforms them.
14
+ //. 1. It finds the first argument to `stylex.keyframes` and validates it.
15
+ /// 2. It envalues 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 * as t from '@babel/types';
11
+ import type { NodePath } from '@babel/traverse';
12
+ import StateManager from '../utils/state-manager';
13
+ declare function transformStyleXOverrideVars(
14
+ callExpressionPath: NodePath<t.CallExpression>,
15
+ state: StateManager,
16
+ ): void;
17
+ export default transformStyleXOverrideVars;
@@ -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 * 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.unstable_overrideVars` calls and transforms them.
14
+ //. 1. It finds the first two arguments to `stylex.unstable_overrideVars` and validates those.
15
+ /// 2. This handles local constants automatically.
16
+ /// 4. It uses the `stylexOverrideVars` 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 transformStyleXOverrideVars(
21
+ callExpressionPath: NodePath<t.CallExpression>,
22
+ state: StateManager,
23
+ ): void;