polymer-rename
raw JSON → 4.3.2 verified Fri May 01 auth: no javascript maintenance
polymer-rename v4.3.2 is a build tool that preprocesses Polymer HTML templates so that Closure Compiler's ADVANCED optimizations can safely rename data-binding expressions and event handlers. It parses Polymer templates, extracts bindings like [[prop]] and on-event handlers, and emits synthetic JavaScript for Closure Compiler to analyze, enabling property renaming without breaking template references. This avoids the need to quote or export every property used in bindings, resulting in smaller output and better type checking. Unlike manual exports, polymer-rename automates the integration of Polymer with Closure Compiler. The library last updated for Polymer 2; no active releases since 2020 indicate maintenance status.
Common errors
error Cannot find module 'polymer-rename' ↓
cause Package not installed or incorrect import path.
fix
Run
npm install polymer-rename and ensure import uses the correct name. error TypeError: polymerRename is not a function ↓
cause Attempted to call a non-function default export, possibly because the default import was not used.
fix
Use
import polymerRename from 'polymer-rename' or const polymerRename = require('polymer-rename'). error Unexpected token: { ↓
cause The input HTML contains JavaScript or template literals that are not valid HTML for the parser.
fix
Ensure the input is a pure HTML template without script tags containing complex JS inside template strings.
Warnings
deprecated This package has not been updated since Polymer 2 and may not work with Polymer 3+ style imports or LitElement. ↓
fix Consider migrating to LitElement or using alternative tooling that supports modern Polymer patterns.
gotcha The package expects HTML files that are valid Polymer templates. Non-standard or malformed HTML can cause parse errors. ↓
fix Ensure your HTML templates follow Polymer 2 conventions and are well-formed.
breaking Version 1.x used a different API (object with .rename method). 4.x uses a default function export. ↓
fix Upgrade to 4.x and use default import: `import polymerRename from 'polymer-rename'`.
gotcha The synthetic JS output is not meant to be executed; including it in the final bundle will cause runtime errors. ↓
fix Only pass the synthetic JS to Closure Compiler during compilation, then exclude from final output.
Install
npm install polymer-rename yarn add polymer-rename pnpm add polymer-rename Imports
- default wrong
const polymerRename = require('polymer-rename')correctimport polymerRename from 'polymer-rename' - rename wrong
const rename = require('polymer-rename').renamecorrectimport { rename } from 'polymer-rename' - polymerRename wrong
import * as polymerRename from 'polymer-rename'correctimport polymerRename from 'polymer-rename'
Quickstart
const polymerRename = require('polymer-rename');
const fs = require('fs');
// Read a Polymer HTML file
const html = fs.readFileSync('my-element.html', 'utf8');
// Generate synthetic JS from the template bindings
const result = polymerRename(html);
console.log(result.js); // synthetic JS for Closure Compiler
console.log(result.warnings); // any warnings
// Write the synthetic JS to a file for compilation
fs.writeFileSync('element-bindings.js', result.js);