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

fails if undefined value is passed #8

Closed
yoshuawuyts opened this issue Jan 10, 2016 · 4 comments
Closed

fails if undefined value is passed #8

yoshuawuyts opened this issue Jan 10, 2016 · 4 comments

Comments

@yoshuawuyts
Copy link
Member

The following code returns an error:

var foo = undefined
hx`<h1>${foo}</h1>`
Uncaught TypeError: Cannot read property '0' of undefined

I think there are two ways of resolving this:

  1. null and undefined values are treated as blank (e.g. yield <h1></h1>)
  2. null and undefined values are treated as errors that should never be rendered, and an appropriate error message is thrown

I think my preference goes out to option 1, as visual quirks in UI are generally non-critical; though perhaps there are good arguments for option 2 which is probably more correct.

@almost
Copy link
Collaborator

almost commented Jan 16, 2016

I'd definitely vote for 1, that allows much more natural code in some places

@ghost
Copy link

ghost commented Jan 17, 2016

What about turning undefined and null values into the strings undefined and null?

@almost
Copy link
Collaborator

almost commented Jan 17, 2016

That to me seems much less useful. It's a very rare thing that I'd actually want the words "null" or "undefined" in my html output and in those cases I think I'd rather be explicit. But a function that maybe returns some markup or maybe returns nothing? I do that all the time!

@ghost
Copy link

ghost commented Jan 22, 2016

Merged this suggestion into 1.1.0: now null and undefined result in an empty string. Other types get coerced to strings to avoid type errors later on.

This issue was closed.
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

No branches or pull requests

2 participants