Skip to content

Commit 2c942f8

Browse files
committed
[fix] Disable using imported values for stylex.props
1 parent 28a5739 commit 2c942f8

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export type FunctionConfig = {
6363
},
6464
},
6565
},
66+
disableImports?: boolean,
6667
};
6768

6869
type State = {
@@ -414,7 +415,11 @@ function _evaluate(path: NodePath<>, state: State): any {
414415
const importedName =
415416
imported.type === 'Identifier' ? imported.name : imported.value;
416417
const importPath = binding.path.parentPath;
417-
if (importPath && importPath.isImportDeclaration()) {
418+
if (
419+
importPath &&
420+
importPath.isImportDeclaration() &&
421+
!state.functions.disableImports
422+
) {
418423
const absPath = state.traversalState.importPathResolver(
419424
importPath.node.source.value,
420425
);
@@ -906,7 +911,11 @@ const importsForState = new WeakMap<StateManager, Set<string>>();
906911
export function evaluate(
907912
path: NodePath<>,
908913
traversalState: StateManager,
909-
functions: FunctionConfig = { identifiers: {}, memberExpressions: {} },
914+
functions: FunctionConfig = {
915+
identifiers: {},
916+
memberExpressions: {},
917+
disableImports: false,
918+
},
910919
seen: Map<t.Node, Result> = new Map(),
911920
): $ReadOnly<{
912921
confident: boolean,

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

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default function transformStylexProps(
8585
const evaluatePathFnConfig: FunctionConfig = {
8686
identifiers,
8787
memberExpressions,
88+
disableImports: true,
8889
};
8990

9091
const resolvedArgs: ResolvedArgs = [];
@@ -212,34 +213,29 @@ export default function transformStylexProps(
212213
if (nonNullProps === true) {
213214
styleNonNullProps = true;
214215
} else {
215-
try {
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-
) {
226-
nonNullProps = true;
227-
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-
}
239-
}
240-
} 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+
) {
241226
nonNullProps = true;
242227
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+
}
243239
}
244240
}
245241

@@ -360,20 +356,16 @@ function parseNullableStyle(
360356
}
361357
}
362358

363-
try {
364-
const parsedObj = evaluate(path, state, evaluatePathFnConfig);
365-
if (
366-
parsedObj.confident &&
367-
parsedObj.value != null &&
368-
typeof parsedObj.value === 'object'
369-
) {
370-
if (parsedObj.value.__IS_PROXY === true) {
371-
return 'other';
372-
}
373-
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';
374367
}
375-
} catch {
376-
return 'other';
368+
return parsedObj.value;
377369
}
378370

379371
return 'other';

0 commit comments

Comments
 (0)