Skip to content

Fix style properties that are not identifiers #8

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

Merged
merged 2 commits into from
Feb 10, 2023

Conversation

DaniGuardiola
Copy link
Contributor

@DaniGuardiola DaniGuardiola commented Feb 9, 2023

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

After the addition of stylePropertyNameCase, the JSX output contained style objects that didn't wrap hyphenated properties with quotes. This is invalid JavaScript/JSX.

This PR makes it check for hyphens inside the property name, and exports a Literal instead of an Identifier. This seems to also fix the same issue for CSS variables, which also seem to be problematic in this regard.

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Feb 9, 2023
@wooorm
Copy link
Member

wooorm commented Feb 9, 2023

Ah nice catch! But while we're at it, I think we should do a proper check. How about using https://github.com/syntax-tree/estree-util-is-identifier-name#namename?

@DaniGuardiola
Copy link
Contributor Author

@wooorm yeah I thought about a proper check but wanted to start small, and I'm also not very familiar with these util packages yet :) done!

Copy link
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @DaniGuardiola!

@remcohaszing
Copy link
Member

Using estree-util-is-identifier-name is fine, but why not just always use a string literal? I prefer unquoted properties when writing code, but for generated code it doesn't really matter IMO.

@wooorm wooorm changed the title Fixed style properties with hyphen Fix style properties that are not identifiers Feb 10, 2023
@wooorm wooorm merged commit 11ddc98 into syntax-tree:main Feb 10, 2023
@wooorm wooorm added 🐛 type/bug This is a problem 👶 semver/patch This is a backwards-compatible fix labels Feb 10, 2023
@github-actions

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label Feb 10, 2023
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Feb 10, 2023
@wooorm
Copy link
Member

wooorm commented Feb 10, 2023

Thanks, released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done 👶 semver/patch This is a backwards-compatible fix 🐛 type/bug This is a problem
Development

Successfully merging this pull request may close these issues.

4 participants