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

Skip to content

Conversation

@AndrewJakubowicz
Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz commented Aug 8, 2023

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

Why

The initial labs compiler public export is only a TypeScript transform. This makes it usable within multiple build tools that accept TypeScript transformers. E.g., within g3, @rollup/plugin-typescript, ttypescript, and maybe one day natively through TypeScript.

This PR adds an example rollup config for testing source maps. The example rollup config uses @rollup/plugin-typescript to compile the sourcemap test file. A new test has been added to ensure the resulting source maps correctly reference the authored example.

How

  • Add source-map which allows easy queries on a source map, and manually setup some source map tests.
  • Add a rollup.source_map_tests.js config which uses the compiler transform to compile a basic typescript file for source map testing.

Risk

This change has minimal risks as it doesn't add or change any logic in the compiler, it's a test only and example only change.

Why not run this transform on lit-html_tests?

Because labs/compiler uses TypeScript 5, while the rest of the monorepo uses TypeScript 4. This will also come in a followup, and can use the example rollup config here as inspiration.

Notes

I noticed in this change that the license does not remain at the top of the generated basic.js file. This will be addressed in a followup.

@changeset-bot
Copy link

changeset-bot bot commented Aug 8, 2023

🦋 Changeset detected

Latest commit: 5b1c2db

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 Aug 8, 2023

📊 Tachometer Benchmark Results

Summary

nop-update

  • this-change, tip-of-tree, previous-release: unsure 🔍 -9% - +5% (-2.30ms - +1.12ms)
    this-change vs tip-of-tree

render

  • this-change: 98.76ms - 102.77ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -6% - +3% (-2.27ms - +1.25ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -3% - +2% (-1.63ms - +1.48ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: faster ✔ 0% - 6% (0.13ms - 3.89ms)
    this-change vs tip-of-tree

update

  • this-change: 1053.40ms - 1080.98ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -4% - +5% (-3.80ms - +4.83ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -4% - +1% (-5.93ms - +1.24ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +0% (-23.81ms - +0.85ms)
    this-change vs tip-of-tree

update-reflect

  • this-change: 1014.74ms - 1034.99ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +0% (-21.02ms - +2.90ms)
    this-change vs tip-of-tree

Results

this-change

render

VersionAvg timevs
98.76ms - 102.77ms-

update

VersionAvg timevs
1053.40ms - 1080.98ms-

update-reflect

VersionAvg timevs
1014.74ms - 1034.99ms-
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
38.28ms - 41.00ms-unsure 🔍
-6% - +3%
-2.27ms - +1.25ms
unsure 🔍
-8% - +2%
-3.10ms - +0.67ms
tip-of-tree
tip-of-tree
39.04ms - 41.26msunsure 🔍
-3% - +6%
-1.25ms - +2.27ms
-unsure 🔍
-6% - +2%
-2.42ms - +1.01ms
previous-release
previous-release
39.55ms - 42.16msunsure 🔍
-2% - +8%
-0.67ms - +3.10ms
unsure 🔍
-3% - +6%
-1.01ms - +2.42ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
96.25ms - 101.65ms-unsure 🔍
-4% - +5%
-3.80ms - +4.83ms
unsure 🔍
-2% - +7%
-1.66ms - +6.36ms
tip-of-tree
tip-of-tree
95.07ms - 101.80msunsure 🔍
-5% - +4%
-4.83ms - +3.80ms
-unsure 🔍
-3% - +7%
-2.64ms - +6.32ms
previous-release
previous-release
93.64ms - 99.56msunsure 🔍
-6% - +2%
-6.36ms - +1.66ms
unsure 🔍
-6% - +3%
-6.32ms - +2.64ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
22.41ms - 25.11ms-unsure 🔍
-9% - +5%
-2.30ms - +1.12ms
unsure 🔍
-10% - +4%
-2.52ms - +1.00ms
tip-of-tree
tip-of-tree
23.30ms - 25.40msunsure 🔍
-5% - +10%
-1.12ms - +2.30ms
-unsure 🔍
-7% - +6%
-1.71ms - +1.37ms
previous-release
previous-release
23.39ms - 25.65msunsure 🔍
-4% - +11%
-1.00ms - +2.52ms
unsure 🔍
-6% - +7%
-1.37ms - +1.71ms
-
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
62.99ms - 64.93ms-unsure 🔍
-3% - +2%
-1.63ms - +1.48ms
unsure 🔍
-2% - +2%
-1.60ms - +1.28ms
tip-of-tree
tip-of-tree
62.82ms - 65.26msunsure 🔍
-2% - +3%
-1.48ms - +1.63ms
-unsure 🔍
-3% - +2%
-1.70ms - +1.53ms
previous-release
previous-release
63.06ms - 65.19msunsure 🔍
-2% - +3%
-1.28ms - +1.60ms
unsure 🔍
-2% - +3%
-1.53ms - +1.70ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
132.08ms - 136.81ms-unsure 🔍
-4% - +1%
-5.93ms - +1.24ms
unsure 🔍
-3% - +2%
-4.06ms - +2.73ms
tip-of-tree
tip-of-tree
134.10ms - 139.49msunsure 🔍
-1% - +4%
-1.24ms - +5.93ms
-unsure 🔍
-1% - +4%
-1.95ms - +5.32ms
previous-release
previous-release
132.67ms - 137.55msunsure 🔍
-2% - +3%
-2.73ms - +4.06ms
unsure 🔍
-4% - +1%
-5.32ms - +1.95ms
-
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
64.47ms - 66.81ms-faster ✔
0% - 6%
0.13ms - 3.89ms
faster ✔
0% - 5%
0.09ms - 3.48ms
tip-of-tree
tip-of-tree
66.18ms - 69.12msslower ❌
0% - 6%
0.13ms - 3.89ms
-unsure 🔍
-3% - +3%
-1.69ms - +2.14ms
previous-release
previous-release
66.20ms - 68.65msslower ❌
0% - 5%
0.09ms - 3.48ms
unsure 🔍
-3% - +2%
-2.14ms - +1.69ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
1022.81ms - 1041.38ms-unsure 🔍
-2% - +0%
-23.81ms - +0.85ms
unsure 🔍
-2% - +0%
-18.89ms - +4.44ms
tip-of-tree
tip-of-tree
1035.46ms - 1051.70msunsure 🔍
-0% - +2%
-0.85ms - +23.81ms
-unsure 🔍
-1% - +1%
-6.51ms - +15.02ms
previous-release
previous-release
1032.25ms - 1046.39msunsure 🔍
-0% - +2%
-4.44ms - +18.89ms
unsure 🔍
-1% - +1%
-15.02ms - +6.51ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
1027.68ms - 1043.86ms-unsure 🔍
-2% - +0%
-21.02ms - +2.90ms
unsure 🔍
-2% - +0%
-21.48ms - +2.88ms
tip-of-tree
tip-of-tree
1036.02ms - 1053.64msunsure 🔍
-0% - +2%
-2.90ms - +21.02ms
-unsure 🔍
-1% - +1%
-12.91ms - +12.43ms
previous-release
previous-release
1035.96ms - 1054.17msunsure 🔍
-0% - +2%
-2.88ms - +21.48ms
unsure 🔍
-1% - +1%
-12.43ms - +12.91ms
-

tachometer-reporter-action v2 for Benchmarks

@AndrewJakubowicz AndrewJakubowicz changed the title [lit-labs/compiler] compiler rollup example and source map tests [lit-labs/compiler] rollup example and source map tests Aug 8, 2023
};

test('basic.ts', async () => {
const smc = await setupTest('basic.js.map');
Copy link
Member

Choose a reason for hiding this comment

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

probably not a big deal with a single file test like this but maybe it's worth putting this in a suiteSetup() and using suiteTeardown() to call smc.destroy()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch. This is a small test so I think I'm inclined to add the smc.destroy() directly to the end of the test.

I tried adding a test.after.each which cleans up the smc, but noted that if the destructor throws outside the test, we get a 0/1 tests passed with an exit code of 0 – which makes it look like everything worked. Went with simpler approach which doesn't have this strange issue.

Copy link
Member

Choose a reason for hiding this comment

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

since all the assertions are synchronous it's probably fine as is, though something about test code execution ordering makes me a bit uncomfortable.

how about something like this?
c516966

this seems to work on my end. is there an actual chance that .destroy() would fail? and should that then report as a test failure?
if so we can add try catch like this https://github.com/google/wireit/blob/df9c9e9d3dc4bd1c92933ef6d4e1919679390478/src/test/analysis.test.ts#L27-L34

@AndrewJakubowicz
Copy link
Contributor Author

Thank you for the excellent suggestions!

@AndrewJakubowicz
Copy link
Contributor Author

AndrewJakubowicz commented Aug 9, 2023

I did some further investigating regarding the license falling below the imports in the generated source_map javascript file. That looks like a rollup/plugin-typescript behavior – as it occurs without the compiler transform.

I'll add a license golden (in a separate PR) to the test_files to show that the compiler transform doesn't do this by default.

Copy link
Member

@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.

suggestion #4077 (comment) is optional.

excellent addition of rollup example and making sure generated source maps are accurate!

@AndrewJakubowicz AndrewJakubowicz merged commit 40879ce into main Aug 10, 2023
@AndrewJakubowicz AndrewJakubowicz deleted the compiler-source-map-tests branch August 10, 2023 17:06
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.

3 participants