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

fix: eslint allow using vars as key in dynamic styles #393

Conversation

QingqiShi
Copy link
Contributor

What changed / motivation ?

Fixed the following cases casuing "Computed key cannot be resolved.eslint(@stylexjs/valid-styles)" lint error.

    import stylex from'stylex';
    import { componentVars } from './bug.stylex';
    stylex.create({
      host: {
        [componentVars.color]: 'blue',
      },
    })
    import stylex from'stylex';
    import { tokens } from 'tokens.stylex';
    stylex.create({
      root: (position) => ({
        [tokens.position]: `${position}px`,
      })
    })

Linked PR/Issues

Fixes #337

Additional Context

For dynamic styles (not style.value.type === 'ObjectExpression') we are missing the check for stylex defined variables for object keys, resulting in the "cannot be resolved" error, the fix was to add an early check for the style key being a defined variable and returning early.

TBH I don't quite understand why the first case was broken as reported in #337, how is that not an object expression? But anyways the fix seem to fix it.

Pre-flight checklist

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 28, 2024
@nmn nmn merged commit 2c10077 into facebook:main Jan 28, 2024
@QingqiShi QingqiShi deleted the 01-28-fix_eslint_allow_using_vars_as_key_in_dynamic_styles branch January 28, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[eslint-plugin] 'Computed key cannot be resolved' when overwriting var
3 participants