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 undefined bug for template strings. #45

Merged
merged 1 commit into from
Sep 1, 2017
Merged

Conversation

beefancohen
Copy link
Contributor

@beefancohen beefancohen commented Jun 8, 2017

Fixes #40

cc: @AlmeroSteyn is this the expectation?

@coveralls
Copy link

coveralls commented Jun 8, 2017

Coverage Status

Coverage remained the same at 98.795% when pulling d77e0ad on fix-template-literal into c055fab on master.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Yes, this is correct- template literals always toString directly, and null and undefined toString to "null" and "undefined" respectively.

@AlmeroSteyn
Copy link

@evcohen Thank you!

template literals always toString directly, and null and undefined toString to "null" and "undefined" respectively.

The issue only pertained to undefined which now works perfectly as expected.

But if I apply the fix in my fork and run with null it still returns an empty string instead of "null".

Separate issue?

@@ -20,7 +20,7 @@ export default function extractValueFromTemplateLiteral(value) {
if (type === 'TemplateElement') {
return raw + part.value.raw;
} else if (type === 'Identifier') {
return part.name === 'undefined' ? raw : `${raw}{${part.name}}`;
return part.name === 'undefined' ? `${raw}${part.name}` : `${raw}{${part.name}}`;
Copy link
Member

Choose a reason for hiding this comment

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

This should check for both "undefined" or "null", perhaps?

Choose a reason for hiding this comment

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

I initially tried this myself but for null the part.name is actually undefined and the part.value.raw throws a TypeError so it seems that something is happening higher up already.

@beefancohen beefancohen merged commit e4c0312 into master Sep 1, 2017
@beefancohen
Copy link
Contributor Author

uh oh it looks like this may have been a breaking change. eslint-plugin-jsx-a11y tests are failing on v2.1.0

@ljharb
Copy link
Member

ljharb commented Apr 20, 2019

Which tests? Is it possible the tests were incorrect?

@beefancohen
Copy link
Contributor Author

Yes that looks to be the case. Fixing now

@beefancohen beefancohen deleted the fix-template-literal branch April 21, 2019 17:21
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.

The template literal for undefined not calculated correctly in props.
4 participants