@stylexjs/babel-plugin 0.11.1 → 0.12.0
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 +2 -1
- package/lib/index.js +55 -30
- package/lib/utils/evaluate-path.d.ts +5 -0
- package/lib/utils/evaluate-path.js.flow +11 -0
- package/lib/utils/state-manager.d.ts +2 -0
- package/lib/utils/state-manager.js.flow +1 -0
- package/lib/visitors/stylex-define-consts.d.ts +30 -0
- package/lib/visitors/stylex-define-consts.js.flow +30 -0
- package/package.json +7 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Solves the issue: https://github.com/facebook/stylex/issues/889
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
4
|
*
|
|
@@ -43,4 +44,4 @@ export type StyleXTransformObj = Readonly<{
|
|
|
43
44
|
processStylexRules: typeof processStylexRules;
|
|
44
45
|
}>;
|
|
45
46
|
declare const $$EXPORT_DEFAULT_DECLARATION$$: StyleXTransformObj;
|
|
46
|
-
export
|
|
47
|
+
export = $$EXPORT_DEFAULT_DECLARATION$$;
|
package/lib/index.js
CHANGED
|
@@ -735,6 +735,7 @@ class StateManager {
|
|
|
735
735
|
const enableDebugClassNames = logAndDefault(boolean(), options.enableDebugClassNames ?? true, true, 'options.enableDebugClassNames');
|
|
736
736
|
const enableDebugDataProp = logAndDefault(boolean(), options.enableDebugDataProp ?? true, true, 'options.enableDebugDataProp');
|
|
737
737
|
const enableDevClassNames = logAndDefault(boolean(), options.enableDevClassNames ?? false, false, 'options.enableDevClassNames');
|
|
738
|
+
const enableMinifiedKeys = logAndDefault(boolean(), options.enableMinifiedKeys ?? true, true, 'options.enableMinifiedKeys');
|
|
738
739
|
const test = logAndDefault(boolean(), options.test ?? false, false, 'options.test');
|
|
739
740
|
const configRuntimeInjection = logAndDefault(checkRuntimeInjection, options.runtimeInjection ?? dev, dev, 'options.runtimeInjection');
|
|
740
741
|
const runtimeInjection = configRuntimeInjection === true ? DEFAULT_INJECT_PATH : configRuntimeInjection === false ? undefined : configRuntimeInjection;
|
|
@@ -763,6 +764,7 @@ class StateManager {
|
|
|
763
764
|
enableDebugClassNames,
|
|
764
765
|
enableDebugDataProp,
|
|
765
766
|
enableDevClassNames,
|
|
767
|
+
enableMinifiedKeys,
|
|
766
768
|
genConditionalClasses,
|
|
767
769
|
importSources,
|
|
768
770
|
rewriteAliases: typeof options.rewriteAliases === 'boolean' ? options.rewriteAliases : false,
|
|
@@ -1240,7 +1242,8 @@ function addSourceMapData(obj, babelPath, state) {
|
|
|
1240
1242
|
const currentFile = babelPath.hub.file;
|
|
1241
1243
|
const sourceMap = currentFile.codeMap;
|
|
1242
1244
|
const styleNodePath = babelPath.get('arguments.0.properties').find(prop => {
|
|
1243
|
-
|
|
1245
|
+
const k = prop.node.key;
|
|
1246
|
+
return t__namespace.isIdentifier(k) && k.name === key || t__namespace.isStringLiteral(k) && k.value === key || t__namespace.isNumericLiteral(k) && String(k.value) === key;
|
|
1244
1247
|
});
|
|
1245
1248
|
if (styleNodePath) {
|
|
1246
1249
|
const generatedLineNumber = styleNodePath.node.loc?.start.line;
|
|
@@ -1403,8 +1406,12 @@ function evaluateThemeRef(fileName, exportName, state) {
|
|
|
1403
1406
|
exportName,
|
|
1404
1407
|
key
|
|
1405
1408
|
});
|
|
1406
|
-
const
|
|
1407
|
-
|
|
1409
|
+
const {
|
|
1410
|
+
debug,
|
|
1411
|
+
enableDebugClassNames
|
|
1412
|
+
} = state.traversalState.options;
|
|
1413
|
+
const varSafeKey = (key[0] >= '0' && key[0] <= '9' ? `_${key}` : key).replace(/[^a-zA-Z0-9]/g, '_');
|
|
1414
|
+
const varName = debug && enableDebugClassNames ? varSafeKey + '-' + state.traversalState.options.classNamePrefix + shared.utils.hash(strToHash) : state.traversalState.options.classNamePrefix + shared.utils.hash(strToHash);
|
|
1408
1415
|
if (key === '__themeName__') {
|
|
1409
1416
|
return varName;
|
|
1410
1417
|
}
|
|
@@ -1676,7 +1683,7 @@ function _evaluate(path, state) {
|
|
|
1676
1683
|
deopt: resultDeopt,
|
|
1677
1684
|
reason: deoptReason,
|
|
1678
1685
|
value
|
|
1679
|
-
} = evaluate(keyPath, state.traversalState, state.functions);
|
|
1686
|
+
} = evaluate(keyPath, state.traversalState, state.functions, state.seen);
|
|
1680
1687
|
if (!confident) {
|
|
1681
1688
|
resultDeopt && deopt(resultDeopt, state, deoptReason ?? 'unknown error');
|
|
1682
1689
|
return;
|
|
@@ -1688,7 +1695,7 @@ function _evaluate(path, state) {
|
|
|
1688
1695
|
key = keyPath.node.value;
|
|
1689
1696
|
}
|
|
1690
1697
|
const valuePath = prop.get('value');
|
|
1691
|
-
let value = evaluate(valuePath, state.traversalState, state.functions);
|
|
1698
|
+
let value = evaluate(valuePath, state.traversalState, state.functions, state.seen);
|
|
1692
1699
|
if (!value.confident) {
|
|
1693
1700
|
value.deopt && deopt(value.deopt, state, value.reason ?? 'unknown error');
|
|
1694
1701
|
return;
|
|
@@ -1911,12 +1918,13 @@ function evaluate(path, traversalState) {
|
|
|
1911
1918
|
identifiers: {},
|
|
1912
1919
|
memberExpressions: {}
|
|
1913
1920
|
};
|
|
1921
|
+
let seen = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Map();
|
|
1914
1922
|
const addedImports = importsForState.get(traversalState) ?? new Set();
|
|
1915
1923
|
importsForState.set(traversalState, addedImports);
|
|
1916
1924
|
const state = {
|
|
1917
1925
|
confident: true,
|
|
1918
1926
|
deoptPath: null,
|
|
1919
|
-
seen
|
|
1927
|
+
seen,
|
|
1920
1928
|
addedImports,
|
|
1921
1929
|
functions,
|
|
1922
1930
|
traversalState
|
|
@@ -2768,7 +2776,7 @@ function requireMessages () {
|
|
|
2768
2776
|
Object.defineProperty(messages, "__esModule", {
|
|
2769
2777
|
value: true
|
|
2770
2778
|
});
|
|
2771
|
-
messages.UNKNOWN_PROP_KEY = messages.UNKNOWN_NAMESPACE = messages.UNEXPECTED_ARGUMENT = messages.UNBOUND_STYLEX_CALL_VALUE = messages.ONLY_TOP_LEVEL = messages.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = messages.NO_PROJECT_ROOT_DIRECTORY = messages.NO_PARENT_PATH = messages.NO_CONDITIONAL_SHORTHAND = messages.NON_STATIC_VALUE = messages.NON_STATIC_KEYFRAME_VALUE = messages.NON_OBJECT_KEYFRAME = messages.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = messages.NON_OBJECT_FOR_STYLEX_CALL = messages.NON_EXPORT_NAMED_DECLARATION = messages.NON_CONTIGUOUS_VARS = messages.LOCAL_ONLY = messages.LINT_UNCLOSED_FUNCTION = messages.INVALID_SPREAD = messages.INVALID_PSEUDO_OR_AT_RULE = messages.INVALID_PSEUDO = messages.ILLEGAL_PROP_VALUE = messages.ILLEGAL_PROP_ARRAY_VALUE = messages.ILLEGAL_NESTED_PSEUDO = messages.ILLEGAL_NAMESPACE_VALUE = messages.ILLEGAL_NAMESPACE_TYPE = messages.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = messages.ILLEGAL_ARGUMENT_LENGTH = messages.EXPECTED_FUNCTION_CALL = messages.ESCAPED_STYLEX_VALUE = messages.DUPLICATE_CONDITIONAL = messages.ANONYMOUS_THEME = void 0;
|
|
2779
|
+
messages.UNKNOWN_PROP_KEY = messages.UNKNOWN_NAMESPACE = messages.UNEXPECTED_ARGUMENT = messages.UNBOUND_STYLEX_CALL_VALUE = messages.ONLY_TOP_LEVEL = messages.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = messages.NO_PROJECT_ROOT_DIRECTORY = messages.NO_PARENT_PATH = messages.NO_OBJECT_SPREADS = messages.NO_CONDITIONAL_SHORTHAND = messages.NON_STATIC_VALUE = messages.NON_STATIC_KEYFRAME_VALUE = messages.NON_OBJECT_KEYFRAME = messages.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = messages.NON_OBJECT_FOR_STYLEX_CALL = messages.NON_EXPORT_NAMED_DECLARATION = messages.NON_CONTIGUOUS_VARS = messages.LOCAL_ONLY = messages.LINT_UNCLOSED_FUNCTION = messages.INVALID_SPREAD = messages.INVALID_PSEUDO_OR_AT_RULE = messages.INVALID_PSEUDO = messages.ILLEGAL_PROP_VALUE = messages.ILLEGAL_PROP_ARRAY_VALUE = messages.ILLEGAL_NESTED_PSEUDO = messages.ILLEGAL_NAMESPACE_VALUE = messages.ILLEGAL_NAMESPACE_TYPE = messages.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = messages.ILLEGAL_ARGUMENT_LENGTH = messages.EXPECTED_FUNCTION_CALL = messages.ESCAPED_STYLEX_VALUE = messages.DUPLICATE_CONDITIONAL = messages.ANONYMOUS_THEME = void 0;
|
|
2772
2780
|
messages.ILLEGAL_ARGUMENT_LENGTH = 'stylex.create() should have 1 argument.';
|
|
2773
2781
|
messages.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = 'stylex.keyframes() should have 1 argument.';
|
|
2774
2782
|
messages.NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.';
|
|
@@ -2801,6 +2809,7 @@ function requireMessages () {
|
|
|
2801
2809
|
messages.ANONYMOUS_THEME = 'stylex.createTheme() must be bound to a named constant.';
|
|
2802
2810
|
messages.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.';
|
|
2803
2811
|
messages.NON_CONTIGUOUS_VARS = 'All variables passed to `stylex.firstThatWorks` must be contiguous.';
|
|
2812
|
+
messages.NO_OBJECT_SPREADS = 'Object spreads are not allowed in stylex.create call.';
|
|
2804
2813
|
return messages;
|
|
2805
2814
|
}
|
|
2806
2815
|
|
|
@@ -3759,11 +3768,22 @@ function transformStyleXCreate(path, state) {
|
|
|
3759
3768
|
const plainObject = value;
|
|
3760
3769
|
const injectedInheritStyles = {};
|
|
3761
3770
|
if (fns != null) {
|
|
3762
|
-
const dynamicFnsNames = Object.values(fns)?.map(entry => Object.
|
|
3763
|
-
|
|
3764
|
-
|
|
3771
|
+
const dynamicFnsNames = Object.values(fns)?.map(entry => Object.entries(entry[1]).map(_ref => {
|
|
3772
|
+
let [variableName, obj] = _ref;
|
|
3773
|
+
return {
|
|
3774
|
+
variableName,
|
|
3775
|
+
path: obj.path
|
|
3776
|
+
};
|
|
3777
|
+
})).flat();
|
|
3778
|
+
dynamicFnsNames.forEach(_ref2 => {
|
|
3779
|
+
let {
|
|
3780
|
+
variableName,
|
|
3781
|
+
path
|
|
3782
|
+
} = _ref2;
|
|
3783
|
+
const isPseudoElement = path.some(p => p.startsWith('::'));
|
|
3784
|
+
injectedInheritStyles[variableName] = {
|
|
3765
3785
|
priority: 0,
|
|
3766
|
-
ltr: `@property ${
|
|
3786
|
+
ltr: `@property ${variableName} { syntax: "*";${isPseudoElement ? '' : ' inherits: false;'}}`,
|
|
3767
3787
|
rtl: null
|
|
3768
3788
|
};
|
|
3769
3789
|
});
|
|
@@ -3812,8 +3832,8 @@ function transformStyleXCreate(path, state) {
|
|
|
3812
3832
|
for (const [className, classPaths] of Object.entries(classPathsPerNamespace[key])) {
|
|
3813
3833
|
origClassPaths[className] = classPaths.join('_');
|
|
3814
3834
|
}
|
|
3815
|
-
let dynamicStyles = Object.entries(inlineStyles).map(
|
|
3816
|
-
let [_key, v] =
|
|
3835
|
+
let dynamicStyles = Object.entries(inlineStyles).map(_ref3 => {
|
|
3836
|
+
let [_key, v] = _ref3;
|
|
3817
3837
|
return {
|
|
3818
3838
|
expression: v.originalExpression,
|
|
3819
3839
|
key: v.path.slice(0, v.path.findIndex(p => !p.startsWith(':') && !p.startsWith('@')) + 1).join('_'),
|
|
@@ -3832,10 +3852,10 @@ function transformStyleXCreate(path, state) {
|
|
|
3832
3852
|
const objProp = prop;
|
|
3833
3853
|
const propKey = objProp.key.type === 'Identifier' && !objProp.computed ? objProp.key.name : objProp.key.type === 'StringLiteral' ? objProp.key.value : null;
|
|
3834
3854
|
if (propKey != null) {
|
|
3835
|
-
const dynamicMatch = dynamicStyles.filter(
|
|
3855
|
+
const dynamicMatch = dynamicStyles.filter(_ref4 => {
|
|
3836
3856
|
let {
|
|
3837
3857
|
key
|
|
3838
|
-
} =
|
|
3858
|
+
} = _ref4;
|
|
3839
3859
|
return key === propKey;
|
|
3840
3860
|
});
|
|
3841
3861
|
if (dynamicMatch.length > 0) {
|
|
@@ -3844,26 +3864,26 @@ function transformStyleXCreate(path, state) {
|
|
|
3844
3864
|
const classList = value.value.split(' ');
|
|
3845
3865
|
if (classList.length === 1) {
|
|
3846
3866
|
const cls = classList[0];
|
|
3847
|
-
const expr = dynamicMatch.find(
|
|
3867
|
+
const expr = dynamicMatch.find(_ref5 => {
|
|
3848
3868
|
let {
|
|
3849
3869
|
path
|
|
3850
|
-
} =
|
|
3870
|
+
} = _ref5;
|
|
3851
3871
|
return origClassPaths[cls] === path;
|
|
3852
3872
|
})?.expression;
|
|
3853
3873
|
if (expr != null) {
|
|
3854
3874
|
objProp.value = t__namespace.conditionalExpression(t__namespace.binaryExpression('==', expr, t__namespace.nullLiteral()), t__namespace.nullLiteral(), value);
|
|
3855
3875
|
}
|
|
3856
|
-
} else if (classList.some(cls => dynamicMatch.find(
|
|
3876
|
+
} else if (classList.some(cls => dynamicMatch.find(_ref6 => {
|
|
3857
3877
|
let {
|
|
3858
3878
|
path
|
|
3859
|
-
} =
|
|
3879
|
+
} = _ref6;
|
|
3860
3880
|
return origClassPaths[cls] === path;
|
|
3861
3881
|
}))) {
|
|
3862
3882
|
const exprArray = classList.map((cls, index) => {
|
|
3863
|
-
const expr = dynamicMatch.find(
|
|
3883
|
+
const expr = dynamicMatch.find(_ref7 => {
|
|
3864
3884
|
let {
|
|
3865
3885
|
path
|
|
3866
|
-
} =
|
|
3886
|
+
} = _ref7;
|
|
3867
3887
|
return origClassPaths[cls] === path;
|
|
3868
3888
|
})?.expression;
|
|
3869
3889
|
const suffix = index === classList.length - 1 ? '' : ' ';
|
|
@@ -3882,8 +3902,8 @@ function transformStyleXCreate(path, state) {
|
|
|
3882
3902
|
}
|
|
3883
3903
|
return objProp;
|
|
3884
3904
|
});
|
|
3885
|
-
prop.value = t__namespace.arrowFunctionExpression(params, t__namespace.arrayExpression([value, t__namespace.objectExpression(Object.entries(inlineStyles).map(
|
|
3886
|
-
let [key, value] =
|
|
3905
|
+
prop.value = t__namespace.arrowFunctionExpression(params, t__namespace.arrayExpression([value, t__namespace.objectExpression(Object.entries(inlineStyles).map(_ref8 => {
|
|
3906
|
+
let [key, value] = _ref8;
|
|
3887
3907
|
return t__namespace.objectProperty(t__namespace.stringLiteral(key), value.expression);
|
|
3888
3908
|
}))]));
|
|
3889
3909
|
}
|
|
@@ -3892,11 +3912,11 @@ function transformStyleXCreate(path, state) {
|
|
|
3892
3912
|
return prop;
|
|
3893
3913
|
});
|
|
3894
3914
|
}
|
|
3895
|
-
const listOfStyles = Object.entries(injectedStyles).map(
|
|
3915
|
+
const listOfStyles = Object.entries(injectedStyles).map(_ref9 => {
|
|
3896
3916
|
let [key, {
|
|
3897
3917
|
priority,
|
|
3898
3918
|
...rest
|
|
3899
|
-
}] =
|
|
3919
|
+
}] = _ref9;
|
|
3900
3920
|
return [key, rest, priority];
|
|
3901
3921
|
});
|
|
3902
3922
|
state.registerStyles(listOfStyles, path);
|
|
@@ -3918,9 +3938,14 @@ function validateStyleXCreate(path) {
|
|
|
3918
3938
|
if (path.node.arguments.length !== 1) {
|
|
3919
3939
|
throw path.buildCodeFrameError(shared.messages.ILLEGAL_ARGUMENT_LENGTH, SyntaxError);
|
|
3920
3940
|
}
|
|
3921
|
-
|
|
3941
|
+
const arg = path.node.arguments[0];
|
|
3942
|
+
if (arg.type !== 'ObjectExpression') {
|
|
3922
3943
|
throw path.buildCodeFrameError(shared.messages.NON_OBJECT_FOR_STYLEX_CALL, SyntaxError);
|
|
3923
3944
|
}
|
|
3945
|
+
const hasSpread = arg.properties.some(prop => t__namespace.isSpreadElement(prop));
|
|
3946
|
+
if (hasSpread) {
|
|
3947
|
+
throw path.buildCodeFrameError(shared.messages.NO_OBJECT_SPREADS, SyntaxError);
|
|
3948
|
+
}
|
|
3924
3949
|
}
|
|
3925
3950
|
function findNearestStatementAncestor(path) {
|
|
3926
3951
|
if (path.isStatement()) {
|
|
@@ -3932,15 +3957,15 @@ function findNearestStatementAncestor(path) {
|
|
|
3932
3957
|
return findNearestStatementAncestor(path.parentPath);
|
|
3933
3958
|
}
|
|
3934
3959
|
function legacyExpandShorthands(dynamicStyles) {
|
|
3935
|
-
const expandedKeysToKeyPaths = dynamicStyles.flatMap((
|
|
3960
|
+
const expandedKeysToKeyPaths = dynamicStyles.flatMap((_ref10, i) => {
|
|
3936
3961
|
let {
|
|
3937
3962
|
key
|
|
3938
|
-
} =
|
|
3963
|
+
} = _ref10;
|
|
3939
3964
|
return flatMapExpandedShorthands([key, 'p' + i], {
|
|
3940
3965
|
styleResolution: 'legacy-expand-shorthands'
|
|
3941
3966
|
});
|
|
3942
|
-
}).map(
|
|
3943
|
-
let [key, value] =
|
|
3967
|
+
}).map(_ref11 => {
|
|
3968
|
+
let [key, value] = _ref11;
|
|
3944
3969
|
if (typeof value !== 'string') {
|
|
3945
3970
|
return null;
|
|
3946
3971
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { NodePath } from '@babel/traverse';
|
|
11
|
+
import * as t from '@babel/types';
|
|
11
12
|
import StateManager from './state-manager';
|
|
12
13
|
export type FunctionConfig = {
|
|
13
14
|
identifiers: { [fnName: string]: any };
|
|
@@ -20,10 +21,14 @@ export type FunctionConfig = {
|
|
|
20
21
|
};
|
|
21
22
|
};
|
|
22
23
|
};
|
|
24
|
+
type Result =
|
|
25
|
+
| { resolved: true; value: any }
|
|
26
|
+
| { resolved: false; reason: string };
|
|
23
27
|
export declare function evaluate(
|
|
24
28
|
path: NodePath,
|
|
25
29
|
traversalState: StateManager,
|
|
26
30
|
functions: FunctionConfig,
|
|
31
|
+
seen: Map<t.Node, Result>,
|
|
27
32
|
): Readonly<{
|
|
28
33
|
confident: boolean;
|
|
29
34
|
value: any;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { NodePath } from '../../flow_modules/@babel/traverse';
|
|
11
|
+
import * as t from '../../flow_modules/@babel/types';
|
|
11
12
|
import StateManager from './state-manager';
|
|
12
13
|
export type FunctionConfig = {
|
|
13
14
|
identifiers: {
|
|
@@ -23,10 +24,20 @@ export type FunctionConfig = {
|
|
|
23
24
|
},
|
|
24
25
|
};
|
|
25
26
|
|
|
27
|
+
type Result =
|
|
28
|
+
| {
|
|
29
|
+
resolved: true,
|
|
30
|
+
value: any,
|
|
31
|
+
}
|
|
32
|
+
| {
|
|
33
|
+
resolved: false,
|
|
34
|
+
reason: string,
|
|
35
|
+
};
|
|
26
36
|
declare export function evaluate(
|
|
27
37
|
path: NodePath<>,
|
|
28
38
|
traversalState: StateManager,
|
|
29
39
|
functions: FunctionConfig,
|
|
40
|
+
seen: Map<t.Node, Result>,
|
|
30
41
|
): $ReadOnly<{
|
|
31
42
|
confident: boolean,
|
|
32
43
|
value: any,
|
|
@@ -45,6 +45,7 @@ export type StyleXOptions = Readonly<
|
|
|
45
45
|
enableDebugClassNames?: boolean;
|
|
46
46
|
enableDebugDataProp?: boolean;
|
|
47
47
|
enableDevClassNames?: boolean;
|
|
48
|
+
enableMinifiedKeys?: boolean;
|
|
48
49
|
genConditionalClasses: boolean;
|
|
49
50
|
importSources: ReadonlyArray<
|
|
50
51
|
string | Readonly<{ from: string; as: string }>
|
|
@@ -65,6 +66,7 @@ export type StyleXOptions = Readonly<
|
|
|
65
66
|
enableDebugClassNames?: boolean;
|
|
66
67
|
enableDebugDataProp?: boolean;
|
|
67
68
|
enableDevClassNames?: boolean;
|
|
69
|
+
enableMinifiedKeys?: boolean;
|
|
68
70
|
genConditionalClasses: boolean;
|
|
69
71
|
importSources: ReadonlyArray<
|
|
70
72
|
string | Readonly<{ from: string; as: string }>
|
|
@@ -46,6 +46,7 @@ export type StyleXOptions = $ReadOnly<{
|
|
|
46
46
|
enableDebugClassNames?: boolean,
|
|
47
47
|
enableDebugDataProp?: boolean,
|
|
48
48
|
enableDevClassNames?: boolean,
|
|
49
|
+
enableMinifiedKeys?: boolean,
|
|
49
50
|
genConditionalClasses: boolean,
|
|
50
51
|
importSources: $ReadOnlyArray<
|
|
51
52
|
string | $ReadOnly<{ from: string, as: string }>,
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
/**
|
|
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
|
+
declare function transformStyleXDefineConsts(
|
|
27
|
+
callExpressionPath: NodePath<t.CallExpression>,
|
|
28
|
+
state: StateManager,
|
|
29
|
+
): void;
|
|
30
|
+
export default transformStyleXDefineConsts;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
/**
|
|
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
|
+
*/
|
|
27
|
+
declare export default function transformStyleXDefineConsts(
|
|
28
|
+
callExpressionPath: NodePath<t.CallExpression>,
|
|
29
|
+
state: StateManager,
|
|
30
|
+
): void;
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/babel-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "StyleX babel plugin.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
-
"repository":
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/facebook/stylex.git"
|
|
9
|
+
},
|
|
7
10
|
"license": "MIT",
|
|
8
11
|
"scripts": {
|
|
9
12
|
"prebuild": "gen-types -i src/ -o lib/",
|
|
@@ -18,8 +21,8 @@
|
|
|
18
21
|
"@babel/traverse": "^7.26.8",
|
|
19
22
|
"@babel/types": "^7.26.8",
|
|
20
23
|
"@dual-bundle/import-meta-resolve": "^4.1.0",
|
|
21
|
-
"@stylexjs/shared": "0.
|
|
22
|
-
"@stylexjs/stylex": "0.
|
|
24
|
+
"@stylexjs/shared": "0.12.0",
|
|
25
|
+
"@stylexjs/stylex": "0.12.0"
|
|
23
26
|
},
|
|
24
27
|
"devDependencies": {
|
|
25
28
|
"@rollup/plugin-alias": "^5.1.1",
|