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

[lit-labs/compiler] Logic for compiling templates containing ChildParts #4047

Merged
merged 9 commits into from
Jul 27, 2023

Conversation

AndrewJakubowicz
Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz commented Jul 26, 2023

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

Note to reviewer: Review this commit by commit – and skip reviewing parse5-utils cause I deleted it after feedback from @43081j.

Context

This PR splits out some initial compiler behavior from the full prototype PR in a reviewable chunk. This PR adds the core functionality that can be built upon in followup changes (and have been de-risked in the prototype).

Features

  • A transformer class, containing two AST traversals. One to locate the templates, and a second one to apply the transformation.
  • Support for compiling ChildParts. Other template parts such as attribute and element parts will be included in a followup.

This is a private only change, and no public entrypoints are being added.

In my opinion, the best place to start the review is at the CompiledTemplatePass.getTransformer() function which contains the high level flow of the transform:

  1. Create a CompiledTemplatePass instance.
  2. Find the templates to compile in the source file.
  3. Rewrite the templates – adding top level CompiledTemplates and replacing html tagged templates with CompiledTemplateResults.

Testing

Tests are contained in the test_files directory. Each *.js or *.ts has a compiled *.golden.js which can be generated via npm run update-goldens, and contains the expected generated output.

The test files included in this change are a subset of the tests in the prototype PR which pass with this change.

Risk

There is minimal risk to merging this PR if GitHub actions succeed. Risk is reduced because lit-labs/compiler is a private package and not published to NPM yet.

Thank you

Note: This implementation has intentionally been simplified to make
reviewing easier. Attribute part handling, uncompiled files, and many
other subtleties have been skipped but will be added in followup.
@changeset-bot
Copy link

changeset-bot bot commented Jul 26, 2023

🦋 Changeset detected

Latest commit: 2c328f5

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

github-actions bot commented Jul 26, 2023

📊 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

Copy link
Collaborator

@rictic rictic left a comment

Choose a reason for hiding this comment

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

Great work, this is looking really good!

packages/labs/compiler/package.json Outdated Show resolved Hide resolved
packages/labs/compiler/src/lib/ast-fragments.ts Outdated Show resolved Hide resolved
packages/labs/compiler/src/lib/ast-fragments.ts Outdated Show resolved Hide resolved
packages/labs/compiler/src/lib/template-transform.ts Outdated Show resolved Hide resolved
packages/labs/compiler/src/lib/template-transform.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@augustjk augustjk left a comment

Choose a reason for hiding this comment

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

Nice! Just a couple minor notes.

packages/labs/compiler/package.json Show resolved Hide resolved
packages/labs/compiler/src/test/golden_compiler_test.ts Outdated Show resolved Hide resolved
@AndrewJakubowicz
Copy link
Contributor Author

Thank you!

@AndrewJakubowicz AndrewJakubowicz merged commit b321299 into main Jul 27, 2023
6 of 7 checks passed
@AndrewJakubowicz AndrewJakubowicz deleted the simple-compile-transform branch July 27, 2023 03:22
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.

4 participants