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

Refactor value parsing to use a simpler algorithm #6931

Conversation

romainmenke
Copy link
Member

Which issue, if any, is this issue related to?

None, it's a minor code quality fix that I noticed while working on a different issue.

Is there anything in the PR that needs further explanation?

This isn't a user facing change, so I am omitting a changelog entry.


parseCommaSeparatedListOfComponentValues :

  • list of lists of component values
  • split by comma
  • doesn't include the comma as a component value
  • useful for :
    • media query lists
    • selectors
    • function params (rgb(0, 0, 0))

parseListOfComponentValues :

  • list of component values
  • no splits
  • does include the comma as a TokenNode
  • useful for anything

This distinction is important when writing specialized parsers (like the media query parser) but it isn't relevant when validating component values.

Using parseListOfComponentValues results in simpler, cleaner code.


The diffs appear large because the indent changed.

Actual diff :

- parseCommaSeparatedListOfComponentValues(tokenize({ css: value }))
- 	.flatMap((x) => x)
+ parseListOfComponentValues(tokenize({ css: value }))
	.forEach((componentValue) => {

@changeset-bot
Copy link

changeset-bot bot commented Jun 18, 2023

⚠️ No Changeset found

Latest commit: faccd83

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Member

@ybiquitous ybiquitous 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!

@romainmenke romainmenke merged commit b7ffe72 into main Jun 18, 2023
18 checks passed
@romainmenke romainmenke deleted the use-a-simpler-algorithm-to-parse-value-like-objects--exuberant-chipmunk-553ddd56e9 branch June 18, 2023 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants