Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@polymer-vis/decorator-transformer

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polymer-vis/decorator-transformer

A typescript transformer to replace "@property" and "@custom-element" decorators with vanilla javascript for Polymer and LitElement webcomponents.

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

@polymer-vis/decorator-transformer

Replace PolymerElement or LitElement decorators (@customElement, @property) in your typescript codes.

Before

@customElement("x-foo")
class XFoo extends HTMLElement {
  static get properties() {
    return {};
  }

  /** some comment */
  @property
  public a: string;
}

After

class XFoo {
  static get properties() {
    return {
      /*Some comment*/
      prop1: String
    };
  }
}
customElements.define("x-foo", XFoo);

TODO:

  • Fix error when declaration is true if properties is not declared.
  • Fix output formatting.

Usage

npm i -D @polymer-vis/decorator-transformer

Important Note

If declaration for your tsconfig.json is set to true, you MUST include the properties getAccessor in your class:

class SomeElement {
  @property
  prop1: string;

  // this must be include if u are emitting
  // type declaration.
  static get properties() {
    return {};
  }
}

With ttypescript

Update your tsconfig.json with @polymer-vis/decorator-transformer plugin. Then run ttsc to compile your typescript sources.

{
  "compilerOptions": {
    "plugins": [
      { "transform": "@polymer-vis/decorator-transformer", "type": "config" }
    ]
  }
}

With typescript compiler API

import * as ts from "typescript";
import decoratorTransformer from "@polymer-vis/decorator-transformer";

let source = `
@customElement('x-foo')
class XFoo extends HTMLElement {
  static get properties() { return {}; }

  @property
  public a: string;

  @property
  public b: number;

  @property
  public c: boolean;

  @property
  public d: string[];

  @property
  public e: Array<Date>;

  @property
  public f: object;

  public g: string;
}
`;
let result = ts.transpileModule(source, {
  compilerOptions: { module: ts.ModuleKind.CommonJS },
  transformers: { before: [decoratorTransformer()] }
});

console.log(result.outputText);

Credits

The source codes are originally by 43081j at lit-element PR#145. I made some minor improvements to replace @property with the corresponding comment and property declarations (if present).

Keywords

FAQs

Package last updated on 08 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc