Skip to main content

stylex_constants/constants/
messages.rs

1// Functions that generate messages with parameters
2pub fn illegal_argument_length(fn_name: &str, arg_length: usize) -> String {
3  let plural = if arg_length == 1 { "" } else { "s" };
4  format!(
5    "{}() should have {} argument{}.",
6    fn_name, arg_length, plural
7  )
8}
9
10pub fn non_static_value(fn_name: &str) -> String {
11  format!(
12    "Only static values are allowed inside of a {}() call.",
13    fn_name
14  )
15}
16
17pub fn non_style_object(fn_name: &str) -> String {
18  format!("{}() can only accept an object.", fn_name)
19}
20
21pub fn non_export_named_declaration(fn_name: &str) -> String {
22  format!(
23    "The return value of {}() must be bound to a named export.",
24    fn_name
25  )
26}
27
28pub fn unbound_call_value(fn_name: &str) -> String {
29  format!("{}() calls must be bound to a bare variable.", fn_name)
30}
31
32pub fn cannot_generate_hash(fn_name: &str) -> String {
33  format!(
34    "Unable to generate hash for {}(). Check that the file has a valid extension and that unstable_moduleResolution is configured.",
35    fn_name
36  )
37}
38
39// Static constants
40pub static DUPLICATE_CONDITIONAL: &str =
41  "The same pseudo selector or at-rule cannot be used more than once.";
42
43pub static ESCAPED_STYLEX_VALUE: &str = "Escaping a create() value is not allowed.";
44
45pub static ILLEGAL_NESTED_PSEUDO: &str = "Pseudo objects can't be nested more than one level deep.";
46
47pub static ILLEGAL_PROP_VALUE: &str = "A style value can only contain an array, string or number.";
48
49pub static ILLEGAL_PROP_ARRAY_VALUE: &str =
50  "A style array value can only contain strings or numbers.";
51
52pub static ILLEGAL_NAMESPACE_VALUE: &str = "A StyleX namespace must be an object.";
53
54pub static INVALID_PSEUDO: &str = "Invalid pseudo selector, not on the whitelist.";
55
56pub static INVALID_PSEUDO_OR_AT_RULE: &str = "Invalid pseudo or at-rule.";
57
58pub static LINT_UNCLOSED_FUNCTION: &str = "Rule contains an unclosed function";
59
60pub static LOCAL_ONLY: &str = "The return value of create() should not be exported.";
61
62pub static NON_OBJECT_KEYFRAME: &str = "Every frame within a keyframes() call must be an object.";
63
64pub static NON_CONTIGUOUS_VARS: &str =
65  "All variables passed to firstThatWorks() must be contiguous.";
66
67pub static NO_OBJECT_SPREADS: &str = "Object spreads are not allowed in create() calls.";
68
69pub static ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS: &str = "Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.";
70
71pub static ONLY_TOP_LEVEL: &str = "create() is only allowed at the root of a program.";
72
73pub static UNKNOWN_PROP_KEY: &str = "Unknown property key";
74
75pub static UNPREFIXED_CUSTOM_PROPERTIES: &str = "Unprefixed custom properties";
76
77pub static NON_STATIC_SECOND_ARG_CREATE_THEME_VALUE: &str =
78  "createTheme() can only accept an object as the second argument.";
79
80pub static BUILT_IN_FUNCTION: &str = "Evaluation built-in functions not supported";
81
82pub static THEME_IMPORT_KEY_AS_OBJECT_KEY: &str =
83  "Theme import keys cannot be used as object keys. Please use a valid object key.";
84
85pub static POSITION_TRY_INVALID_PROPERTY: &str = "Invalid property in `positionTry()` call. It may only contain, positionAnchor, positionArea, inset properties (top, left, insetInline etc.), margin properties, size properties (height, inlineSize, etc.), and self-alignment properties (alignSelf, justifySelf, placeSelf)";
86
87pub static VIEW_TRANSITION_CLASS_INVALID_PROPERTY: &str = "Invalid property in `viewTransitionClass()` call. It may only contain group, imagePair, old, and new properties";
88
89pub static INVALID_MEDIA_QUERY_SYNTAX: &str = "Invalid media query syntax.";
90
91pub static SPREAD_NOT_SUPPORTED: &str =
92  "The spread operator (...) is not supported in this context. Declare each property explicitly.";
93
94pub static SPREAD_MUST_BE_OBJECT: &str = "The spread argument must be a static object expression.";
95
96pub static EXPRESSION_IS_NOT_A_STRING: &str =
97  "Expected a string value but received a non-string expression.";
98
99pub static VALUES_MUST_BE_OBJECT: &str = "The values argument must be a plain object.";
100
101pub static INJECTABLE_STYLE_NOT_SUPPORTED: &str =
102  "InjectableStyle is not supported in this context.";
103
104pub static ONLY_OVERRIDE_DEFINE_VARS: &str =
105  "Can only override variables theme created with defineVars().";
106
107pub static MEMBER_NOT_RESOLVED: &str =
108  "Could not resolve the member expression. Ensure the object and property are statically known.";
109
110pub static PROPERTY_NOT_FOUND: &str =
111  "Property not found on the object. Ensure the key exists and is spelled correctly.";
112
113pub static EXPECTED_OBJECT_EXPRESSION: &str = "Expected an object expression.";
114
115pub static VALUE_MUST_BE_STRING: &str = "Expected a string value but received a different type.";
116
117pub static VALUE_MUST_BE_LITERAL: &str =
118  "Expected a static literal value (string, number, or boolean).";
119
120pub static ENTRY_MUST_BE_TUPLE: &str = "Each entry must be a [key, value] tuple.";
121
122pub static ARGUMENT_NOT_EXPRESSION: &str = "Function argument must be a static expression.";
123
124pub static EXPORT_ID_NOT_SET: &str =
125  "Export identifier is not set. The variable must be bound to a named export.";
126
127pub static INVALID_UTF8: &str = "String value contains invalid UTF-8 encoding.";
128
129pub static EXPECTED_CSS_VAR: &str = "Expected a CSS custom property (variable) reference.";
130
131pub static KEY_MUST_EVAL_TO_STRING: &str = "Style property key must evaluate to a string.";
132
133pub static MEMBER_OBJ_NOT_IDENT: &str =
134  "The object in a member expression must be a static identifier.";
135
136pub static AT_RULE_NOT_FOUND: &str =
137  "At-rule not found in the rules map. Ensure the at-rule is declared correctly.";
138
139pub static EXPECTED_COMPILED_STYLES: &str = "Expected compiled style values from the style object.";
140
141pub static VALUE_NOT_EXPRESSION: &str = "Style value must evaluate to a static expression.";
142
143pub static EVAL_RESULT_EXPECTED: &str = "Expected a value from evaluation result.";
144
145pub static VAR_DECL_NAME_NOT_IDENT: &str = "Variable declarator name must be an identifier.";
146
147pub static VAR_DECL_INIT_REQUIRED: &str = "Variable declaration must have an initializer.";
148
149pub static KEY_VALUE_EXPECTED: &str = "Expected a key-value property in the object.";
150
151pub static THEME_VAR_TUPLE: &str =
152  "Theme variable definition must be a [key, value, cssType] tuple.";
153
154pub static OBJECT_KEY_MUST_BE_IDENT: &str = "Object key must be a static identifier.";
155
156pub static COMPILED_KEY_MISSING: &str = "Style object does not contain a compiled key. Ensure the styles were created with stylex.create().";
157
158pub static THEME_VARS_MUST_BE_OBJECT: &str = "Theme variables must be defined as a plain object.";
159
160pub static RULE_SET_EMPTY: &str = "The style rule set is empty. At least one rule is required.";
161
162pub fn expected_call_expression(fn_name: &str) -> String {
163  format!(
164    "{}(): Expected a call expression. Ensure the value is a direct function call.",
165    fn_name
166  )
167}