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

Default template engine should throw for literal property binding. #203

Open
theengineear opened this issue Nov 10, 2024 · 3 comments
Open

Comments

@theengineear
Copy link
Collaborator

I think I’ve only ever seen a literal property binding by mistake, so I’m tempted to keep this strict. However, I wanted to farm for dissent a little bit. Currently…

NOT OK

html`<div .foo="bar"></div>`;

OK

html`<div foo="bar"></div>`;

or…

html`<div foo="${'bar'}"></div>`;

^^ But this last one is considered an anti-pattern and should not be used.

@theengineear
Copy link
Collaborator Author

IMO, we should not allow .foo="bar" — this binding can be expressed within the html syntax. And, if it’s really needed (e.g., the custom element doesn’t do attribute syncing), you can use .foo="${'bar'}" as a last resort.

@theengineear
Copy link
Collaborator Author

🤔 — I actually think we should do what we’re currently doing… just totally ignore that. You can do this today:

document.body.innerHTML = `
  <div .foo="bar">
    I have an attribute named dot-foo with a value bar!
  </div>
`;

I want to try very hard not to mess with default behavior… I wonder if that means we ought to actually not fail in the case of:

html`<div .foo="bar" .another="${whatever}"></div>`;

… not totally sure what the “best” choice here is!

@theengineear
Copy link
Collaborator Author

theengineear commented Nov 10, 2024

While the spec allows for attributes with a preceding . — we are already going to further-restrict attribute names. Therefore — this ought to be naturally rejected by the following logic:

  1. Properties must have binding (i.e., cannot be literals).
  2. Therefore something like .foo="bar" is considered an attribute.
  3. Attribute names may not start with a ..
  4. Therefore — we will throw for templates like this.

@theengineear theengineear reopened this Dec 28, 2024
@theengineear theengineear changed the title Discussion: Should default template engine allow literal property binding. Default template engine should throw for literal property binding. Dec 28, 2024
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