Skip to content

Symbols as keys#272

Merged
gvergnaud merged 3 commits intogvergnaud:mainfrom
Ayc0:symbol
Aug 8, 2024
Merged

Symbols as keys#272
gvergnaud merged 3 commits intogvergnaud:mainfrom
Ayc0:symbol

Conversation

@Ayc0
Copy link
Contributor

@Ayc0 Ayc0 commented Aug 8, 2024

I noticed that isMatching wasn't working with symbols:

image

But the exact same code works with strings:

image

So I updated the matchPattern function to also iterate through symbols in addition to keys (Object.keys() skips symbols, but we can use Object.getOwnPropertySymbols() for those)

I also added a test that is failing without my changes, but passes after:

Before After
image image

Comment on lines +13 to +15
} else {
throw new Error('Expected obj to match the foo pattern!');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test only wasn't enough as it was passing before (as it was stripping all symbols)

So I added the other if for the negative check

@gvergnaud
Copy link
Owner

Awesome, thank you!

@gvergnaud gvergnaud merged commit e74557d into gvergnaud:main Aug 8, 2024
@Ayc0 Ayc0 deleted the symbol branch August 8, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants