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(utils): handle 0 as a reference value #325

Merged
merged 1 commit into from
Oct 2, 2019
Merged

fix(utils): handle 0 as a reference value #325

merged 1 commit into from
Oct 2, 2019

Conversation

dbanksdesign
Copy link
Member

Issue #, if available: #324

Description of changes: Adding proper checking for alias/reference resolution so that 0 is a valid value. Now we check for undefined rather than "truthiness", because 0 is "false".

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

}

return ref;

Choose a reason for hiding this comment

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

It looks like in the previous version a bad ref would result in this function returning "obj" (ref = obj on line 156, return ref here). Now it doesn't return anything if there's a bad ref. Don't know if this is good or bad, just wondering if it might have the potential to break something else.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh good point I forgot to mention that part. So I don't know why we were returning the whole object, if you look at line 91 we were testing for truthiness, which if we passed an object back would always be true. Then in line 131 we set to_ret = ref which would be that object as well and return it. This is inside a string.replace function, and returning an object does nothing to the string. So this was always "working", but not how we thought it was...

Copy link
Member Author

Choose a reason for hiding this comment

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

And hopefully all our glorious unit tests would catch anything major, but seems everything is in order.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This file is so hard to understand - I'm concerned about the out-of-scope variable (updated_object) used within. I'm pretty sure I added the code that sets ref = obj as part of the work to provide better error output (although blame does not seem to think so), but I'm not clear how it interfaces with the updated_object variable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok so updated_object is created immediate upon calling resolveObject. It is a deep clone of the object being resolved, to prevent any changes that are made during this process from trickling back outside the resolveObject scope. I think everything is ok as is...

Copy link
Collaborator

@chazzmoney chazzmoney left a comment

Choose a reason for hiding this comment

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

👍🏽

@chazzmoney
Copy link
Collaborator

LGTM! :shipit:

@dbanksdesign dbanksdesign merged commit 189d61b into master Oct 2, 2019
MDemetrio pushed a commit to MDemetrio/style-dictionary that referenced this pull request Nov 8, 2019
fixes amzn#324

Adding proper checking for alias/reference resolution so that 0 is a valid value. Now we check for undefined rather than "truthiness", because 0 is "false".
@dbanksdesign dbanksdesign deleted the fix-324 branch May 15, 2020 21:03
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.

3 participants