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

Skip to content

Conversation

@e111077
Copy link
Contributor

@e111077 e111077 commented Feb 28, 2025

DO NOT SUBMIT WIP

By default uses oxc-parser to generate an estree of a TS file, but can also accept a TS AST. Then finds all the tagged template literals in there, and then uses heuristics or comments to determine whether they are lit-html templates.

From there it parses the template's html and produces parse5-inspired AST and attaches them to the ESTree (or TS AST)'s template literal and each bound expression.

This differs from a parse5 ast node like so:

// input html`<d${literal`iv`} .asdf=${123}>${tmpl}</d${literal`iv`}>`
// truncated parse5 output
{
  nodeName: 'd${literal`iv`}',
  attrs: [
    {
        name: '.asdf',
        value: '${123}'
    },
    childNodes: [
      {
        nodeName: '#text',
        value: '${tmpl}'
      }
    ]
  ]
}

into this:

{
  type: 'DocumentFragment',
  children: [
    {
      type: 'Element',
      // stringified tag name: 'd${...}'
      tagName: [ // tagname is actually an array not a string
        {
          type: 'LitTagLiteral', // lit-parser-specific node
          value: 'd'
        },
        {
          type: 'LitHtmlExpression', // lit-parser-specific node
          nodeName: '#lit-html-expression',
          expression: {
            type: 'TaggedTemplateExpression', // estree node
            tag: {
              type: 'Identifier', // estree node
              name: 'literal'
            },
            quasi: {
              type: 'TemplateLiteral' // estree node
            }
          }
        }
      ],
      attributes: [
        {
          type: 'Property', // lit-parser-specific node
          name: {
            // stringified tag name: '.asdf',
            raw: [
              {
                type: 'LitTagLiteral', // lit-parser-specific node
                value: '.asdf'
              }
            ]
          },
          value: [
            {
              nodeName: '#lit-html-expression',
              type: 'LitHtmlExpression', // lit-parser-specific node
              node: {
                type: 'Literal', // estree node
                value: 123
              }
            }
          ]
        }
      ],
      childNodes: [
        {
          nodeName: '#lit-html-expression',
          type: 'LitHtmlExpression', // lit-parser-specific node
          node: {
            type: 'Identifier', // estree node
            name: 'tmpl'
          }
        }
      ]
    }
  ]
}

It also adds and hooks into the documentFragment property on the estree's TaggedTemplateExpression and adds an isLit: true on it so that you can filter for it.

Additionally every expression bound into a lit-html template will have a litHtmlExpression property that will point to the associated LitHtmlExpression which also includes the ${} wrapper around the expression.

fork of #4267

@changeset-bot
Copy link

changeset-bot bot commented Feb 28, 2025

⚠️ No Changeset found

Latest commit: 8b5ab10

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

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

Click here to learn what changesets are, and how to add one.

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

@e111077 e111077 changed the title [analyzer] lit template analyzer [analyzer] lit template analyzer fork Feb 28, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Feb 28, 2025

📊 Tachometer Benchmark Results

Summary

nop-update

  • this-change, tip-of-tree, previous-release: unsure 🔍 -4% - +6% (-0.46ms - +0.72ms)
    this-change vs tip-of-tree

render

  • this-change: 40.65ms - 46.51ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -3% - +6% (-0.67ms - +1.21ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +1% (-0.82ms - +0.47ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -9% - +50% (-3.37ms - +24.27ms)
    this-change vs tip-of-tree

update

  • this-change: 452.10ms - 457.41ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -8% - +3% (-3.02ms - +1.21ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +1% (-1.46ms - +0.94ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +0% (-8.57ms - +1.94ms)
    this-change vs tip-of-tree

update-reflect

  • this-change: 435.99ms - 440.73ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -1% - +1% (-3.77ms - +4.47ms)
    this-change vs tip-of-tree

Results

this-change

render

VersionAvg timevs
40.65ms - 46.51ms-

update

VersionAvg timevs
452.10ms - 457.41ms-

update-reflect

VersionAvg timevs
435.99ms - 440.73ms-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
19.20ms - 20.55ms-unsure 🔍
-3% - +6%
-0.67ms - +1.21ms
unsure 🔍
-6% - +4%
-1.19ms - +0.73ms
tip-of-tree
tip-of-tree
18.95ms - 20.27msunsure 🔍
-6% - +3%
-1.21ms - +0.67ms
-unsure 🔍
-7% - +2%
-1.45ms - +0.45ms
previous-release
previous-release
19.42ms - 20.80msunsure 🔍
-4% - +6%
-0.73ms - +1.19ms
unsure 🔍
-2% - +7%
-0.45ms - +1.45ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
34.45ms - 37.70ms-unsure 🔍
-8% - +3%
-3.02ms - +1.21ms
unsure 🔍
-8% - +4%
-2.97ms - +1.48ms
tip-of-tree
tip-of-tree
35.63ms - 38.33msunsure 🔍
-3% - +8%
-1.21ms - +3.02ms
-unsure 🔍
-5% - +6%
-1.87ms - +2.19ms
previous-release
previous-release
35.31ms - 38.33msunsure 🔍
-4% - +8%
-1.48ms - +2.97ms
unsure 🔍
-6% - +5%
-2.19ms - +1.87ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
11.08ms - 11.93ms-unsure 🔍
-4% - +6%
-0.46ms - +0.72ms
unsure 🔍
-5% - +6%
-0.54ms - +0.63ms
tip-of-tree
tip-of-tree
10.96ms - 11.79msunsure 🔍
-6% - +4%
-0.72ms - +0.46ms
-unsure 🔍
-6% - +4%
-0.67ms - +0.49ms
previous-release
previous-release
11.06ms - 11.86msunsure 🔍
-5% - +5%
-0.63ms - +0.54ms
unsure 🔍
-4% - +6%
-0.49ms - +0.67ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
34.68ms - 35.52ms-unsure 🔍
-2% - +1%
-0.82ms - +0.47ms
unsure 🔍
-3% - +0%
-1.13ms - +0.14ms
tip-of-tree
tip-of-tree
34.79ms - 35.77msunsure 🔍
-1% - +2%
-0.47ms - +0.82ms
-unsure 🔍
-3% - +1%
-1.00ms - +0.36ms
previous-release
previous-release
35.12ms - 36.07msunsure 🔍
-0% - +3%
-0.14ms - +1.13ms
unsure 🔍
-1% - +3%
-0.36ms - +1.00ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
70.20ms - 71.91ms-unsure 🔍
-2% - +1%
-1.46ms - +0.94ms
unsure 🔍
-1% - +3%
-0.39ms - +1.92ms
tip-of-tree
tip-of-tree
70.48ms - 72.15msunsure 🔍
-1% - +2%
-0.94ms - +1.46ms
-unsure 🔍
-0% - +3%
-0.12ms - +2.17ms
previous-release
previous-release
69.51ms - 71.07msunsure 🔍
-3% - +1%
-1.92ms - +0.39ms
unsure 🔍
-3% - +0%
-2.17ms - +0.12ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
51.03ms - 71.62ms-unsure 🔍
-9% - +50%
-3.37ms - +24.27ms
unsure 🔍
-22% - +27%
-13.13ms - +16.01ms
tip-of-tree
tip-of-tree
41.65ms - 60.09msunsure 🔍
-38% - +3%
-24.27ms - +3.37ms
-unsure 🔍
-36% - +6%
-22.84ms - +4.82ms
previous-release
previous-release
49.58ms - 70.20msunsure 🔍
-26% - +21%
-16.01ms - +13.13ms
unsure 🔍
-12% - +47%
-4.82ms - +22.84ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
454.73ms - 461.83ms-unsure 🔍
-2% - +0%
-8.57ms - +1.94ms
unsure 🔍
-1% - +1%
-5.46ms - +4.93ms
tip-of-tree
tip-of-tree
457.72ms - 465.47msunsure 🔍
-0% - +2%
-1.94ms - +8.57ms
-unsure 🔍
-1% - +2%
-2.37ms - +8.47ms
previous-release
previous-release
454.75ms - 462.34msunsure 🔍
-1% - +1%
-4.93ms - +5.46ms
unsure 🔍
-2% - +1%
-8.47ms - +2.37ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
463.72ms - 469.59ms-unsure 🔍
-1% - +1%
-3.77ms - +4.47ms
unsure 🔍
-1% - +1%
-4.81ms - +4.26ms
tip-of-tree
tip-of-tree
463.41ms - 469.20msunsure 🔍
-1% - +1%
-4.47ms - +3.77ms
-unsure 🔍
-1% - +1%
-5.14ms - +3.88ms
previous-release
previous-release
463.47ms - 470.39msunsure 🔍
-1% - +1%
-4.26ms - +4.81ms
unsure 🔍
-1% - +1%
-3.88ms - +5.14ms
-

tachometer-reporter-action v2 for Benchmarks

@github-actions
Copy link
Contributor

The size of lit-html.js and lit-core.min.js are as expected.

@e111077 e111077 force-pushed the techytacos--lit-template-analyzer branch 3 times, most recently from ca4e91b to e45c385 Compare March 5, 2025 09:24
@e111077 e111077 changed the title [analyzer] lit template analyzer fork [analyzer] lit template parser Mar 5, 2025
@e111077 e111077 force-pushed the techytacos--lit-template-analyzer branch 5 times, most recently from 1e2c6f1 to e308dad Compare March 7, 2025 08:44
@e111077 e111077 changed the title [analyzer] lit template parser [parser] lit template parser Mar 7, 2025
@e111077 e111077 force-pushed the techytacos--lit-template-analyzer branch 6 times, most recently from e2fcc3e to 40651ee Compare March 13, 2025 23:14
@e111077 e111077 force-pushed the techytacos--lit-template-analyzer branch from 40651ee to 42fcb6d Compare April 11, 2025 07:16
@e111077 e111077 force-pushed the techytacos--lit-template-analyzer branch from 42fcb6d to 8b5ab10 Compare August 21, 2025 18:56
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.

1 participant