SMotaal / polyestr-tsx-lit-transform

A TypeScript TSX-to-template-literal transform that builds into the eco-system of Polyestr.
3 stars 0 forks source link

[Proposal]: Resolve tag names from JSXOpeningElements instead of simply using the name as string #4

Open SMotaal opened 7 years ago

SMotaal commented 7 years ago

Proposal:

Resolve the literal name from the JSXOpeningTags and either pass them as strings or replace them with expressions to capture them from the current scope.

Problem:

The initial transform simple assumed that everything with a transformed JSX fragment is a string part except for JSXExpressions { … }, however, there are certain limitations in JSX for which this design might have actually overlooked:

  import MyElement from './my-element';
  const myElement = html`<${MyElement.tagName}>…`;

Rewriting it to be transformed using the current design would look like:

  import MyElement from './my-element';
  const myElement = html(<{MyElement.tagName}>…);

Which is invalid JSX.

Resolution: