Skip to content

Commit 6bc28dc

Browse files
committed
[fix] Disable using imported values for stylex.props
1 parent 7d77fb1 commit 6bc28dc

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

packages/@stylexjs/babel-plugin/src/utils/evaluate-path.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,11 @@ function _evaluate(path: NodePath<>, state: State): any {
415415
const importedName =
416416
imported.type === 'Identifier' ? imported.name : imported.value;
417417
const importPath = binding.path.parentPath;
418-
if (importPath && importPath.isImportDeclaration()) {
418+
if (
419+
importPath &&
420+
importPath.isImportDeclaration() &&
421+
!state.functions.disableImports
422+
) {
419423
const absPath = state.traversalState.importPathResolver(
420424
importPath.node.source.value,
421425
);

packages/@stylexjs/babel-plugin/src/visitors/stylex-props.js

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -213,34 +213,29 @@ export default function transformStylexProps(
213213
if (nonNullProps === true) {
214214
styleNonNullProps = true;
215215
} else {
216-
try {
217-
const { confident, value: styleValue } = evaluate(
218-
path,
219-
state,
220-
evaluatePathFnConfig,
221-
);
222-
if (
223-
!confident ||
224-
styleValue == null ||
225-
styleValue.__IS_PROXY === true
226-
) {
227-
nonNullProps = true;
228-
styleNonNullProps = true;
229-
} else {
230-
styleNonNullProps =
231-
nonNullProps === true ? true : [...nonNullProps];
232-
if (nonNullProps !== true) {
233-
nonNullProps = [
234-
...nonNullProps,
235-
...Object.keys(styleValue).filter(
236-
(key) => styleValue[key] !== null,
237-
),
238-
];
239-
}
240-
}
241-
} catch {
216+
const { confident, value: styleValue } = evaluate(
217+
path,
218+
state,
219+
evaluatePathFnConfig,
220+
);
221+
if (
222+
!confident ||
223+
styleValue == null ||
224+
styleValue.__IS_PROXY === true
225+
) {
242226
nonNullProps = true;
243227
styleNonNullProps = true;
228+
} else {
229+
styleNonNullProps =
230+
nonNullProps === true ? true : [...nonNullProps];
231+
if (nonNullProps !== true) {
232+
nonNullProps = [
233+
...nonNullProps,
234+
...Object.keys(styleValue).filter(
235+
(key) => styleValue[key] !== null,
236+
),
237+
];
238+
}
244239
}
245240
}
246241

@@ -361,20 +356,16 @@ function parseNullableStyle(
361356
}
362357
}
363358

364-
try {
365-
const parsedObj = evaluate(path, state, evaluatePathFnConfig);
366-
if (
367-
parsedObj.confident &&
368-
parsedObj.value != null &&
369-
typeof parsedObj.value === 'object'
370-
) {
371-
if (parsedObj.value.__IS_PROXY === true) {
372-
return 'other';
373-
}
374-
return parsedObj.value;
359+
const parsedObj = evaluate(path, state, evaluatePathFnConfig);
360+
if (
361+
parsedObj.confident &&
362+
parsedObj.value != null &&
363+
typeof parsedObj.value === 'object'
364+
) {
365+
if (parsedObj.value.__IS_PROXY === true) {
366+
return 'other';
375367
}
376-
} catch {
377-
return 'other';
368+
return parsedObj.value;
378369
}
379370

380371
return 'other';

0 commit comments

Comments
 (0)