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

Readme Template Example Fails to Run #227

Open
jlukic opened this issue Feb 17, 2023 · 0 comments
Open

Readme Template Example Fails to Run #227

jlukic opened this issue Feb 17, 2023 · 0 comments

Comments

@jlukic
Copy link

jlukic commented Feb 17, 2023

Using the documentations readme example

<template name=developer>
  <!-- `{nickname}` will bind to `context` property `nickname` -->
  <h1>{nickname}</h1>
</template>
const
  template = Template `developer`
, context  = { nickname: 'That Beast' }

template.bind (context)

Is failing in current build in Chrome 110

snugsi.js:1 Uncaught TypeError: Failed to execute 'selectNodeContents' on 'Range': parameter 1 is not of type 'Node'.

I believe this is because the parameters returned to the Template Literal is actually an array so the typeof == 'string' condition never occurs.

= typeof template === 'string'

If you inspect with a breakpoint you can see the parameter actually looks like this

['developer', raw: Array(1)]

This is because it is also being passed the raw strings
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#raw_strings

As pointed out in #222 this can also be solved by changing the syntax to

const
  template = Template(`developer`)

However this would require updating the readme if you want to require the parens.

Alternatively the logic could be updated to ducktype like

if (t.raw) {
  t = document.querySelector("template[name=" + t[0] + "]")
}
@jlukic jlukic changed the title Template Literal Error Readme Template Example Fails to Run Feb 17, 2023
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

1 participant