Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to statically evaluate dynamic key of object when using spread syntax #1455

Open
dddlr opened this issue May 18, 2023 · 0 comments
Open
Labels
bug 🐛 Something isn't working

Comments

@dddlr
Copy link
Collaborator

dddlr commented May 18, 2023

Bug in @compiled/babel-plugin. Example code:

import { styled } from '@compiled/react';
import React from 'react';

const UNMOUNTED = 'unmounted';
const EXITED = 'exited';
const ENTERING = 'entering';
const ENTERED = 'entered';
const EXITING = 'exiting';

export type TransitionState =
    | typeof UNMOUNTED
    | typeof EXITED
    | typeof ENTERING
    | typeof ENTERED
    | typeof EXITING;


type ContainerProps = {
  transitionState: TransitionState;
};

const containerStyles: { [id: string]: React.CSSProperties } = {
  exited: { flex: '0 0 0', width: '50px' },
  entered: { flex: '0 0 50px', width: '50px' },
};


export const MyContainer = styled.div<ContainerProps>(
  ({ transitionState }) => transitionState && { ...containerStyles[transitionState] },
);

export const App = (): JSX.Element => (
  <>
    <MyContainer transitionState={EXITED}>hello</MyContainer>
  </>
);

Infinite loop occurs when statically evaluating the MemberExpression containerTransitionStyles[transitionState]. Appears to get stuck here:

const { value, meta: updatedMeta } = evaluateExpression(node, meta);

@dddlr dddlr added the bug 🐛 Something isn't working label May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant