Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@AndrewJakubowicz
Copy link
Contributor

Issue: #189
RFC: lit/rfcs#21
Full prototype PR: #3984

Why

This change exists to restrict compilation down to our html tag function. The compiler will only run over a file if an html import is detected from lit or lit-html.

How

In the pass to locate all the templates, also look for import declarations, and optionally mark the file for compilation if a valid import is found.

Test plan

Added two goldens.

Considerations

This change is better than having no handling, but it is still possible to cause a miscompilation if you import html from lit, and then shadow it with another tag function. There are two options I can think of that remedy this:

  1. Allow the user to customize and override isLitTemplate. It would need a different public API.
  2. Invoke TypeScript TypeChecker analysis & check that the declaration came from a valid import. Maybe it's worth the complexity to do this?

@changeset-bot
Copy link

changeset-bot bot commented Jul 27, 2023

🦋 Changeset detected

Latest commit: f8ae2b2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

📊 Tachometer Benchmark Results

Summary

A summary of the benchmark results will show here once they finish.

Results

The full results of your benchmarks will show here once they finish.

tachometer-reporter-action v2 for Benchmarks

);
}
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we resolve the reference for the template tag function instead? I'm concerned this approach would miscompile:

import {html} from 'lit';
import * as static from 'lit/static.js';

function foo() {
  const html = static.html;
  return html``;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, if we go with the currently implemented approach, does it properly handle code like this:

import {svg as html} from 'lit';

Copy link
Contributor Author

@AndrewJakubowicz AndrewJakubowicz Jul 27, 2023

Choose a reason for hiding this comment

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

Yes – those cases will miscompile. I can add resolving the reference (and add those as test cases).

If we're resolving the reference – we could support aliased identifiers as long as they resolve to html imported from lit?

E.g. we could resolve import {html as h} from 'lit';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also handle:

import * as lit from 'lit';

lit.html`rar`;

@AndrewJakubowicz AndrewJakubowicz marked this pull request as draft July 27, 2023 20:40
@AndrewJakubowicz
Copy link
Contributor Author

Converted to draft – making the checking much more robust.

@AndrewJakubowicz
Copy link
Contributor Author

From the great feedback, this PR has been replaced with #4055

@AndrewJakubowicz AndrewJakubowicz deleted the compile-certain-files-filter branch July 28, 2023 06:29
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.

2 participants