A robust command-line tool for converting Polymer 3 components to Lit (LitElement).
- ✅ Automatic conversion of Polymer 3 components to Lit
- ✅ Template conversion from Polymer's HTML templates to Lit's template literals
- ✅ Property binding conversion including one-way (
[[]]) and two-way ({{}}) bindings - ✅ Event handler conversion from
on-*attributes to@event listeners - ✅ Style handling with support for custom styles and style includes
- ✅ DOM manipulation conversion (
this.$tothis.renderRoot.querySelector) - ✅ Batch processing support for entire directories
- ✅ Configurable output with Lit 1.x or 2.x support
- ✅ Error handling with graceful fallbacks
- ✅ Debug and verbose modes for troubleshooting
cd frontend
npm install
npx tscConvert a single Polymer component:
node frontend/convert.js my-component.js -outConvert all components in a directory:
node frontend/convert.js ./src -out| Option | Description |
|---|---|
-1 |
Use Lit 1.x imports (lit-element) instead of Lit 2.x (lit) |
-chain |
Enable optional chaining (?.) in output |
-out |
Add .out.js suffix to output files |
-v, --verbose |
Show detailed conversion information |
-d, --debug |
Show debug output (includes verbose) |
-h, --help |
Show help message |
// Polymer
static get template() {
return html`<div>[[property]]</div>`;
}
// Lit
render() {
return html`<div>${this.property}</div>`;
}- Property bindings:
[[prop]]→${this.prop} - Two-way bindings:
{{prop}}→${this.prop}+ event handler - Event handlers:
on-click="handler"→@click=${this.handler} - DOM access:
this.$.id→this.renderRoot.querySelector("#id")
The frontend tool is in the frontend folder.
cd frontend
npm install
npx tscConvert a single file with output suffix:
node convert.js my-component.js -outThis will convert my-component.js into a Lit element and save it as my-component.js.out.js
Convert with verbose output:
node convert.js my-component.js -out -vGet help:
node convert.js --helpThe Java tool is in the java folder
To test this tool, do the setup dance once
cd java
mvn package
Then run it and give it a PolymerTemplate Java file
mvn exec:exec -Dfile=/my/project/src/main/java/my/package/MyTemplate.java