samccone / twinkie

A polymer(1)&&(2) template parser + interface printer
Apache License 2.0
5 stars 5 forks source link

Add a new app for transpiling a template #19

Closed gdmfilippov closed 3 years ago

gdmfilippov commented 3 years ago

This change adds a new app together with a bunch of classes/methods for advanced template checking. It uses typescript compiler API to extract type/property information and to analyze polymer classes. The app is work, however many tests are missed. If we agree on this idea and implementation, I will add missed tests. For example, the following elements:

<template is="dom-repeat" items="{{_permissions}}" as="permission">
  <gr-permission
    name="[[_computePermissionName(section.id, permission, capabilities)]]"
    permission="{{permission}}"
    labels="[[labels]]"
    section="[[section.id]]"
    editing="[[editing]]"
    groups="[[groups]]"
    on-added-permission-removed="_handleAddedPermissionRemoved"
  >
  </gr-permission>
</template>

are transpiled to:

{
  const index = 0;
  const itemsIndexAs = 0;
  useVars(index, itemsIndexAs); //Avoid 'not-used' error for variables
  for(const permission of this._permissions!)
  {
    {
      const el: HTMLElementTagNameMap['gr-permission'] = null!;
      useVars(el);
      el.name = this._computePermissionName(__f(this.section)!.id, permission, this.capabilities);
      el.permission = permission;
      el.labels = this.labels;
      el.section = __f(this.section)!.id; // __f is a special function to handle union types correctly
      el.editing = this.editing;
      el.groups = this.groups;
      el.addEventListener('added-permission-removed', e => this._handleAddedPermissionRemoved.bind(this, wrapInPolymerDomRepeatEvent(e, permission))());
    }
  }
}
samccone commented 3 years ago

@gdmfilippov please let me know when this is ready for another review,

gdmfilippov commented 3 years ago

@gdmfilippov please let me know when this is ready for another review,

It is ready for another review :) I resolved all comments