@stylexjs/babel-plugin 0.2.0-beta.21 → 0.2.0-beta.22
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.
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1839 -1144
- package/lib/utils/evaluate-path.d.ts +1 -1
- package/lib/utils/js-to-ast.d.ts +8 -2
- package/lib/utils/js-to-ast.js.flow +7 -1
- package/lib/utils/state-manager.d.ts +5 -4
- package/lib/utils/state-manager.js.flow +3 -2
- package/lib/visitors/imports.d.ts +2 -2
- package/lib/visitors/stylex-create/index.d.ts +2 -2
- package/lib/visitors/stylex-create/parse-stylex-create-arg.d.ts +2 -2
- package/lib/visitors/{stylex-create.d.ts → stylex-create-theme.d.ts} +5 -5
- package/lib/visitors/{stylex-create.js.flow → stylex-create-theme.js.flow} +6 -7
- package/lib/visitors/{stylex-create-vars.d.ts → stylex-define-vars.d.ts} +4 -4
- package/lib/visitors/{stylex-create-vars.js.flow → stylex-define-vars.js.flow} +4 -4
- package/lib/visitors/stylex-keyframes.d.ts +2 -2
- package/lib/visitors/stylex-merge.d.ts +2 -2
- package/lib/visitors/stylex-override-vars.d.ts +4 -4
- package/lib/visitors/stylex-override-vars.js.flow +4 -4
- package/lib/visitors/stylex-props.d.ts +21 -0
- package/lib/visitors/stylex-props.js.flow +25 -0
- package/package.json +2 -2
- package/lib/visitors/stylex-create/parse-style-function.d.ts +0 -18
- package/lib/visitors/stylex-create/parse-style-function.js.flow +0 -23
package/lib/utils/js-to-ast.d.ts
CHANGED
|
@@ -7,10 +7,16 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import * as t from '
|
|
10
|
+
import * as t from '../../flow_modules/@babel/types';
|
|
11
11
|
import { IncludedStyles } from '@stylexjs/shared';
|
|
12
12
|
type NestedStringObject = Readonly<{
|
|
13
|
-
[key: string]:
|
|
13
|
+
[key: string]:
|
|
14
|
+
| string
|
|
15
|
+
| number
|
|
16
|
+
| null
|
|
17
|
+
| boolean
|
|
18
|
+
| NestedStringObject
|
|
19
|
+
| IncludedStyles;
|
|
14
20
|
}>;
|
|
15
21
|
export declare function convertObjectToAST(
|
|
16
22
|
obj: NestedStringObject,
|
|
@@ -11,7 +11,13 @@ import * as t from '../../flow_modules/@babel/types';
|
|
|
11
11
|
import { IncludedStyles } from '@stylexjs/shared';
|
|
12
12
|
|
|
13
13
|
type NestedStringObject = $ReadOnly<{
|
|
14
|
-
[key: string]:
|
|
14
|
+
[key: string]:
|
|
15
|
+
| string
|
|
16
|
+
| number
|
|
17
|
+
| null
|
|
18
|
+
| boolean
|
|
19
|
+
| NestedStringObject
|
|
20
|
+
| IncludedStyles,
|
|
15
21
|
}>;
|
|
16
22
|
|
|
17
23
|
declare export function convertObjectToAST(
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { PluginPass } from '
|
|
11
|
-
import type { NodePath } from '
|
|
10
|
+
import type { PluginPass } from '../../flow_modules/@babel/core';
|
|
11
|
+
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
12
12
|
import type {
|
|
13
13
|
CompiledNamespaces,
|
|
14
14
|
StyleXOptions as RuntimeOptions,
|
|
@@ -39,12 +39,13 @@ type StyleXOptions = Omit<
|
|
|
39
39
|
declare class StateManager {
|
|
40
40
|
readonly _state: PluginPass;
|
|
41
41
|
readonly stylexImport: Set<string>;
|
|
42
|
+
readonly stylexPropsImport: Set<string>;
|
|
42
43
|
readonly stylexCreateImport: Set<string>;
|
|
43
44
|
readonly stylexIncludeImport: Set<string>;
|
|
44
45
|
readonly stylexFirstThatWorksImport: Set<string>;
|
|
45
46
|
readonly stylexKeyframesImport: Set<string>;
|
|
46
|
-
readonly
|
|
47
|
-
readonly
|
|
47
|
+
readonly stylexDefineVarsImport: Set<string>;
|
|
48
|
+
readonly stylexCreateThemeImport: Set<string>;
|
|
48
49
|
readonly stylexTypesImport: Set<string>;
|
|
49
50
|
readonly styleMap: Map<string, CompiledNamespaces>;
|
|
50
51
|
readonly styleVars: Map<string, NodePath>;
|
|
@@ -44,12 +44,13 @@ type StyleXOptions = {
|
|
|
44
44
|
declare export default class StateManager {
|
|
45
45
|
+_state: PluginPass;
|
|
46
46
|
+stylexImport: Set<string>;
|
|
47
|
+
+stylexPropsImport: Set<string>;
|
|
47
48
|
+stylexCreateImport: Set<string>;
|
|
48
49
|
+stylexIncludeImport: Set<string>;
|
|
49
50
|
+stylexFirstThatWorksImport: Set<string>;
|
|
50
51
|
+stylexKeyframesImport: Set<string>;
|
|
51
|
-
+
|
|
52
|
-
+
|
|
52
|
+
+stylexDefineVarsImport: Set<string>;
|
|
53
|
+
+stylexCreateThemeImport: Set<string>;
|
|
53
54
|
+stylexTypesImport: Set<string>;
|
|
54
55
|
+styleMap: Map<string, CompiledNamespaces>;
|
|
55
56
|
+styleVars: Map<string, NodePath<>>;
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import * as t from '
|
|
11
|
-
import type { NodePath } from '
|
|
10
|
+
import * as t from '../../flow_modules/@babel/types';
|
|
11
|
+
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
12
12
|
import StateManager from '../utils/state-manager';
|
|
13
13
|
export declare function readImportDeclarations(
|
|
14
14
|
path: NodePath<t.ImportDeclaration>,
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import * as t from '
|
|
11
|
-
import type { NodePath } from '
|
|
10
|
+
import * as t from '../../../flow_modules/@babel/types';
|
|
11
|
+
import type { NodePath } from '../../../flow_modules/@babel/traverse';
|
|
12
12
|
import StateManager from '../../utils/state-manager';
|
|
13
13
|
declare function transformStyleXCreate(
|
|
14
14
|
path: NodePath<t.CallExpression>,
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* @flow strict
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import type { NodePath } from '
|
|
12
|
-
import * as t from '
|
|
11
|
+
import type { NodePath } from '../../../flow_modules/@babel/traverse';
|
|
12
|
+
import * as t from '../../../flow_modules/@babel/types';
|
|
13
13
|
import StateManager from '../../utils/state-manager';
|
|
14
14
|
import { type FunctionConfig } from '../../utils/evaluate-path';
|
|
15
15
|
export declare function evaluateStyleXCreateArg(
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import * as t from '
|
|
11
|
-
import type { NodePath } from '
|
|
10
|
+
import * as t from '../../flow_modules/@babel/types';
|
|
11
|
+
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
12
12
|
import StateManager from '../utils/state-manager';
|
|
13
|
-
declare function
|
|
14
|
-
|
|
13
|
+
declare function transformStyleXCreateTheme(
|
|
14
|
+
callExpressionPath: NodePath<t.CallExpression>,
|
|
15
15
|
state: StateManager,
|
|
16
16
|
): void;
|
|
17
|
-
export default
|
|
17
|
+
export default transformStyleXCreateTheme;
|
|
@@ -10,15 +10,14 @@
|
|
|
10
10
|
import * as t from '../../flow_modules/@babel/types';
|
|
11
11
|
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
12
12
|
import StateManager from '../utils/state-manager';
|
|
13
|
-
/// This function looks for `stylex.
|
|
14
|
-
//. 1. It finds the first
|
|
15
|
-
/// 2.
|
|
16
|
-
///
|
|
17
|
-
/// 4. It uses the `stylexCreate` from `@stylexjs/shared` to transform the JS
|
|
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
|
|
18
17
|
/// object and to get a list of injected styles.
|
|
19
18
|
/// 5. It converts the resulting Object back into an AST and replaces the call with it.
|
|
20
19
|
/// 6. It also inserts `stylex.inject` calls above the current statement as needed.
|
|
21
|
-
declare export default function
|
|
22
|
-
|
|
20
|
+
declare export default function transformStyleXCreateTheme(
|
|
21
|
+
callExpressionPath: NodePath<t.CallExpression>,
|
|
23
22
|
state: StateManager,
|
|
24
23
|
): void;
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import * as t from '
|
|
11
|
-
import type { NodePath } from '
|
|
10
|
+
import * as t from '../../flow_modules/@babel/types';
|
|
11
|
+
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
12
12
|
import StateManager from '../utils/state-manager';
|
|
13
|
-
declare function
|
|
13
|
+
declare function transformStyleXDefineVars(
|
|
14
14
|
callExpressionPath: NodePath<t.CallExpression>,
|
|
15
15
|
state: StateManager,
|
|
16
16
|
): void;
|
|
17
|
-
export default
|
|
17
|
+
export default transformStyleXDefineVars;
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
import * as t from '../../flow_modules/@babel/types';
|
|
11
11
|
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
12
12
|
import StateManager from '../utils/state-manager';
|
|
13
|
-
/// This function looks for `stylex.
|
|
14
|
-
//. 1. It finds the first argument to `stylex.
|
|
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
15
|
/// 2. It envalues the style object to get a JS object. This also handles local constants automatically.
|
|
16
|
-
/// 4. It uses the `
|
|
16
|
+
/// 4. It uses the `stylexDefineVars` from `@stylexjs/shared` to transform the JS
|
|
17
17
|
/// object and to get a list of injected styles.
|
|
18
18
|
/// 5. It converts the resulting Object back into an AST and replaces the call with it.
|
|
19
19
|
/// 6. It also inserts `stylex.inject` calls above the current statement as needed.
|
|
20
|
-
declare export default function
|
|
20
|
+
declare export default function transformStyleXDefineVars(
|
|
21
21
|
callExpressionPath: NodePath<t.CallExpression>,
|
|
22
22
|
state: StateManager,
|
|
23
23
|
): void;
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import * as t from '
|
|
11
|
-
import type { NodePath } from '
|
|
10
|
+
import * as t from '../../flow_modules/@babel/types';
|
|
11
|
+
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
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
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { NodePath } from '
|
|
11
|
-
import * as t from '
|
|
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
|
export declare function skipStylexMergeChildren(
|
|
14
14
|
path: NodePath<t.CallExpression>,
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import * as t from '
|
|
11
|
-
import type { NodePath } from '
|
|
10
|
+
import * as t from '../../flow_modules/@babel/types';
|
|
11
|
+
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
12
12
|
import StateManager from '../utils/state-manager';
|
|
13
|
-
declare function
|
|
13
|
+
declare function transformStyleXCreateTheme(
|
|
14
14
|
callExpressionPath: NodePath<t.CallExpression>,
|
|
15
15
|
state: StateManager,
|
|
16
16
|
): void;
|
|
17
|
-
export default
|
|
17
|
+
export default transformStyleXCreateTheme;
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
import * as t from '../../flow_modules/@babel/types';
|
|
11
11
|
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
12
12
|
import StateManager from '../utils/state-manager';
|
|
13
|
-
/// This function looks for `stylex.
|
|
14
|
-
//. 1. It finds the first two arguments to `stylex.
|
|
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
15
|
/// 2. This handles local constants automatically.
|
|
16
|
-
/// 4. It uses the `
|
|
16
|
+
/// 4. It uses the `stylexCreateTheme` from `@stylexjs/shared` to transform the JS
|
|
17
17
|
/// object and to get a list of injected styles.
|
|
18
18
|
/// 5. It converts the resulting Object back into an AST and replaces the call with it.
|
|
19
19
|
/// 6. It also inserts `stylex.inject` calls above the current statement as needed.
|
|
20
|
-
declare export default function
|
|
20
|
+
declare export default function transformStyleXCreateTheme(
|
|
21
21
|
callExpressionPath: NodePath<t.CallExpression>,
|
|
22
22
|
state: StateManager,
|
|
23
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 '../../flow_modules/@babel/traverse';
|
|
11
|
+
import * as t from '../../flow_modules/@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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/babel-plugin",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.22",
|
|
4
4
|
"description": "StyleX babel plugin.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": "https://github.com/facebook/stylex",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"test": "jest"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@stylexjs/shared": "0.2.0-beta.
|
|
15
|
+
"@stylexjs/shared": "0.2.0-beta.22"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"@babel/core": "^7.19.6",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*
|
|
8
|
-
* @flow strict
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { NodePath } from '@babel/traverse';
|
|
12
|
-
import StateManager from '../../utils/state-manager';
|
|
13
|
-
import { type FunctionConfig } from '../../utils/evaluate-path';
|
|
14
|
-
export declare function evaluateStyleFunction(
|
|
15
|
-
path: NodePath,
|
|
16
|
-
traversalState: StateManager,
|
|
17
|
-
functions: FunctionConfig,
|
|
18
|
-
): { confident: boolean; value: any; deopt?: null | NodePath };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*
|
|
8
|
-
* @flow strict
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { NodePath } from '../../../flow_modules/@babel/traverse';
|
|
12
|
-
import StateManager from '../../utils/state-manager';
|
|
13
|
-
import { type FunctionConfig } from '../../utils/evaluate-path';
|
|
14
|
-
// This
|
|
15
|
-
declare export function evaluateStyleFunction(
|
|
16
|
-
path: NodePath<>,
|
|
17
|
-
traversalState: StateManager,
|
|
18
|
-
functions: FunctionConfig,
|
|
19
|
-
): {
|
|
20
|
-
confident: boolean,
|
|
21
|
-
value: any,
|
|
22
|
-
deopt?: null | NodePath<>,
|
|
23
|
-
};
|