@stylexjs/babel-plugin 0.3.0 → 0.4.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.
- package/README.md +2 -4
- package/flow_modules/@babel/core/index.js.flow +6 -6
- package/flow_modules/@babel/helper-module-imports/index.js.flow +182 -0
- package/flow_modules/@babel/traverse/index.js.flow +7 -6
- package/lib/index.d.ts +15 -2
- package/lib/index.js +535 -515
- package/lib/index.js.flow +18 -2
- package/lib/utils/state-manager.d.ts +52 -15
- package/lib/utils/state-manager.js.flow +22 -7
- package/package.json +7 -10
- package/lib/visitors/stylex-override-vars.d.ts +0 -17
- package/lib/visitors/stylex-override-vars.js.flow +0 -23
package/lib/index.js.flow
CHANGED
|
@@ -14,13 +14,16 @@ export type Options = StyleXOptions;
|
|
|
14
14
|
/**
|
|
15
15
|
* Entry point for the StyleX babel plugin.
|
|
16
16
|
*/
|
|
17
|
-
declare
|
|
17
|
+
declare function styleXTransform(): PluginObj<>;
|
|
18
18
|
|
|
19
|
+
declare function stylexPluginWithOptions(
|
|
20
|
+
options: Partial<StyleXOptions>,
|
|
21
|
+
): [typeof styleXTransform, Partial<StyleXOptions>];
|
|
19
22
|
/**
|
|
20
23
|
*
|
|
21
24
|
* @param rules An array of CSS rules that has been generated and collected from all JS files
|
|
22
25
|
* in a project
|
|
23
|
-
* @returns A string that
|
|
26
|
+
* @returns A string that represents the final CSS file.
|
|
24
27
|
*
|
|
25
28
|
* This function take an Array of CSS rules, de-duplicates them, sorts them priority and generates
|
|
26
29
|
* a final CSS file.
|
|
@@ -32,3 +35,16 @@ declare export default function styleXTransform(): PluginObj<>;
|
|
|
32
35
|
* End-users can choose to not use this function and use their own logic instead.
|
|
33
36
|
*/
|
|
34
37
|
export type Rule = [string, { ltr: string, rtl?: null | string }, number];
|
|
38
|
+
declare function processStylexRules(
|
|
39
|
+
rules: Array<Rule>,
|
|
40
|
+
useLayers: boolean,
|
|
41
|
+
): string;
|
|
42
|
+
|
|
43
|
+
export type StyleXTransformObj = $ReadOnly<{
|
|
44
|
+
(): PluginObj<>,
|
|
45
|
+
withOptions: typeof stylexPluginWithOptions,
|
|
46
|
+
processStylexRules: typeof processStylexRules,
|
|
47
|
+
...
|
|
48
|
+
}>;
|
|
49
|
+
|
|
50
|
+
declare export default StyleXTransformObj;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import * as t from '@babel/types';
|
|
10
11
|
import type { PluginPass } from '@babel/core';
|
|
11
12
|
import type { NodePath } from '@babel/traverse';
|
|
12
13
|
import type {
|
|
@@ -24,20 +25,48 @@ type ModuleResolution =
|
|
|
24
25
|
rootDir: string;
|
|
25
26
|
themeFileExtension?: string;
|
|
26
27
|
};
|
|
27
|
-
export type StyleXOptions =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
export type StyleXOptions = Readonly<
|
|
29
|
+
Omit<
|
|
30
|
+
RuntimeOptions,
|
|
31
|
+
keyof ({
|
|
32
|
+
importSources: ReadonlyArray<
|
|
33
|
+
string | Readonly<{ from: string; as: string }>
|
|
34
|
+
>;
|
|
35
|
+
runtimeInjection:
|
|
36
|
+
| boolean
|
|
37
|
+
| (null | undefined | string)
|
|
38
|
+
| Readonly<{ from: string; as: string }>;
|
|
39
|
+
treeshakeCompensation?: boolean;
|
|
40
|
+
genConditionalClasses: boolean;
|
|
41
|
+
unstable_moduleResolution: void | ModuleResolution;
|
|
42
|
+
})
|
|
43
|
+
> & {
|
|
44
|
+
importSources: ReadonlyArray<
|
|
45
|
+
string | Readonly<{ from: string; as: string }>
|
|
46
|
+
>;
|
|
47
|
+
runtimeInjection:
|
|
48
|
+
| boolean
|
|
49
|
+
| (null | undefined | string)
|
|
50
|
+
| Readonly<{ from: string; as: string }>;
|
|
31
51
|
treeshakeCompensation?: boolean;
|
|
32
52
|
genConditionalClasses: boolean;
|
|
33
53
|
unstable_moduleResolution: void | ModuleResolution;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
54
|
+
}
|
|
55
|
+
>;
|
|
56
|
+
type StyleXStateOptions = Readonly<
|
|
57
|
+
Omit<
|
|
58
|
+
StyleXOptions,
|
|
59
|
+
keyof ({
|
|
60
|
+
runtimeInjection:
|
|
61
|
+
| (null | undefined | string)
|
|
62
|
+
| Readonly<{ from: string; as: string }>;
|
|
63
|
+
})
|
|
64
|
+
> & {
|
|
65
|
+
runtimeInjection:
|
|
66
|
+
| (null | undefined | string)
|
|
67
|
+
| Readonly<{ from: string; as: string }>;
|
|
68
|
+
}
|
|
69
|
+
>;
|
|
41
70
|
declare class StateManager {
|
|
42
71
|
readonly _state: PluginPass;
|
|
43
72
|
readonly importPaths: Set<string>;
|
|
@@ -50,16 +79,22 @@ declare class StateManager {
|
|
|
50
79
|
readonly stylexDefineVarsImport: Set<string>;
|
|
51
80
|
readonly stylexCreateThemeImport: Set<string>;
|
|
52
81
|
readonly stylexTypesImport: Set<string>;
|
|
82
|
+
injectImportInserted: null | undefined | t.Identifier;
|
|
53
83
|
readonly styleMap: Map<string, CompiledNamespaces>;
|
|
54
84
|
readonly styleVars: Map<string, NodePath>;
|
|
55
|
-
readonly styleVarsToKeep: Set<[string,
|
|
85
|
+
readonly styleVarsToKeep: Set<[string, true | string, true | Array<string>]>;
|
|
56
86
|
inStyleXCreate: boolean;
|
|
57
87
|
constructor(state: PluginPass);
|
|
58
|
-
get options():
|
|
88
|
+
get options(): StyleXStateOptions;
|
|
59
89
|
get importPathString(): string;
|
|
90
|
+
get importSources(): ReadonlyArray<string>;
|
|
91
|
+
importAs(source: string): null | string;
|
|
60
92
|
get canReferenceTheme(): boolean;
|
|
61
93
|
get metadata(): { [key: string]: any };
|
|
62
|
-
get runtimeInjection():
|
|
94
|
+
get runtimeInjection():
|
|
95
|
+
| null
|
|
96
|
+
| undefined
|
|
97
|
+
| Readonly<{ from: string; as?: string }>;
|
|
63
98
|
get isDev(): boolean;
|
|
64
99
|
get isTest(): boolean;
|
|
65
100
|
get filename(): string | void;
|
|
@@ -68,6 +103,8 @@ declare class StateManager {
|
|
|
68
103
|
get fileNameForHashing(): null | string;
|
|
69
104
|
importPathResolver(importPath: string): ImportPathResolution;
|
|
70
105
|
addStyle(style: [string, { ltr: string; rtl?: string | null }, number]): void;
|
|
71
|
-
markComposedNamespace(
|
|
106
|
+
markComposedNamespace(
|
|
107
|
+
memberExpression: [string, true | string, true | Array<string>],
|
|
108
|
+
): void;
|
|
72
109
|
}
|
|
73
110
|
export default StateManager;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import * as t from '../../flow_modules/@babel/types';
|
|
10
11
|
import type { PluginPass } from '../../flow_modules/@babel/core';
|
|
11
12
|
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
12
13
|
import type {
|
|
@@ -33,14 +34,23 @@ type ModuleResolution =
|
|
|
33
34
|
themeFileExtension?: string,
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
export type StyleXOptions = {
|
|
37
|
+
export type StyleXOptions = $ReadOnly<{
|
|
37
38
|
...RuntimeOptions,
|
|
38
|
-
importSources:
|
|
39
|
+
importSources: $ReadOnlyArray<
|
|
40
|
+
string | $ReadOnly<{ from: string, as: string }>,
|
|
41
|
+
>,
|
|
42
|
+
runtimeInjection: boolean | ?string | $ReadOnly<{ from: string, as: string }>,
|
|
39
43
|
treeshakeCompensation?: boolean,
|
|
40
44
|
genConditionalClasses: boolean,
|
|
41
45
|
unstable_moduleResolution: void | ModuleResolution,
|
|
42
46
|
...
|
|
43
|
-
}
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
type StyleXStateOptions = $ReadOnly<{
|
|
50
|
+
...StyleXOptions,
|
|
51
|
+
runtimeInjection: ?string | $ReadOnly<{ from: string, as: string }>,
|
|
52
|
+
...
|
|
53
|
+
}>;
|
|
44
54
|
|
|
45
55
|
declare export default class StateManager {
|
|
46
56
|
+_state: PluginPass;
|
|
@@ -54,16 +64,19 @@ declare export default class StateManager {
|
|
|
54
64
|
+stylexDefineVarsImport: Set<string>;
|
|
55
65
|
+stylexCreateThemeImport: Set<string>;
|
|
56
66
|
+stylexTypesImport: Set<string>;
|
|
67
|
+
injectImportInserted: ?t.Identifier;
|
|
57
68
|
+styleMap: Map<string, CompiledNamespaces>;
|
|
58
69
|
+styleVars: Map<string, NodePath<>>;
|
|
59
|
-
+styleVarsToKeep: Set<[string,
|
|
70
|
+
+styleVarsToKeep: Set<[string, true | string, true | Array<string>]>;
|
|
60
71
|
inStyleXCreate: boolean;
|
|
61
72
|
constructor(state: PluginPass): void;
|
|
62
|
-
get options():
|
|
73
|
+
get options(): StyleXStateOptions;
|
|
63
74
|
get importPathString(): string;
|
|
75
|
+
get importSources(): $ReadOnlyArray<string>;
|
|
76
|
+
importAs(source: string): null | string;
|
|
64
77
|
get canReferenceTheme(): boolean;
|
|
65
78
|
get metadata(): { [key: string]: any };
|
|
66
|
-
get runtimeInjection():
|
|
79
|
+
get runtimeInjection(): ?$ReadOnly<{ from: string, as?: string }>;
|
|
67
80
|
get isDev(): boolean;
|
|
68
81
|
get isTest(): boolean;
|
|
69
82
|
get filename(): string | void;
|
|
@@ -72,5 +85,7 @@ declare export default class StateManager {
|
|
|
72
85
|
get fileNameForHashing(): null | string;
|
|
73
86
|
importPathResolver(importPath: string): ImportPathResolution;
|
|
74
87
|
addStyle(style: [string, { ltr: string, rtl?: string | null }, number]): void;
|
|
75
|
-
markComposedNamespace(
|
|
88
|
+
markComposedNamespace(
|
|
89
|
+
memberExpression: [string, true | string, true | Array<string>],
|
|
90
|
+
): void;
|
|
76
91
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/babel-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "StyleX babel plugin.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": "https://github.com/facebook/stylex",
|
|
@@ -12,15 +12,12 @@
|
|
|
12
12
|
"test": "jest"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"@babel/core": "^7.
|
|
19
|
-
"@babel/traverse": "^7.
|
|
20
|
-
"@babel/types": "^7.
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"ts-node": "^10.8.1"
|
|
15
|
+
"@babel/helper-module-imports": "^7.22.15",
|
|
16
|
+
"@stylexjs/shared": "0.4.1",
|
|
17
|
+
"@stylexjs/stylex": "0.4.1",
|
|
18
|
+
"@babel/core": "^7.23.6",
|
|
19
|
+
"@babel/traverse": "^7.23.6",
|
|
20
|
+
"@babel/types": "^7.23.6"
|
|
24
21
|
},
|
|
25
22
|
"jest": {
|
|
26
23
|
"verbose": true,
|
|
@@ -1,17 +0,0 @@
|
|
|
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 '../../flow_modules/@babel/types';
|
|
11
|
-
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
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;
|
|
@@ -1,23 +0,0 @@
|
|
|
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.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;
|