Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mangle type names when they conflict with values #1077

Closed
wants to merge 4 commits into from
Closed

Mangle type names when they conflict with values #1077

wants to merge 4 commits into from

Conversation

evmar
Copy link
Contributor

@evmar evmar commented Sep 17, 2019

This series of commits changes our emit for code like

interface X { ... }
const X = 3;

Previously, we'd just quietly drop the X because of the conflict.
With this change, we instead emit the type with a mangled name:

/** @record */
function X$$TSType() { ... }
const X = 3;

Then when some code wants to use that type, it needs to know whether that type has a mangled JS name. To do so I add a header to any tsickle-emitted d.ts. This actually let me remove a hack related to standard library types too.

Add:
- augmented browser global
- externs
- an enum (which is also a type/value).
@evmar evmar changed the title Type / value Mangle type names when they conflict with values Sep 18, 2019
Given input where a type and value conflict, like
  interface X { ... }
  const X = 3;
this makes us emit the interface as
  function X$$TSType() { }
etc.

This is not used anywhere yet; it purely adds the additional emit.
An upcoming change makes tsickle need to know whether a given module
was processed by tsickle or not.  This change makes tsickle emit a
constant string at the head of each d.ts file that it can look for.

For example, when tsickle compiles library a.ts, it emits a.d.ts.
Then when compiling b.ts that imports from a, it still knows (from
the tag in a.d.ts) that the JS emitted for a has been processed.

This change adds the header but does not make use of it.
When there's a type/value conflict, we emit a mangled name for the type.
This change makes tsickle emit references to those mangled names when
the types are used.

Importantly, we need to be careful to only use mangled names in the case
where we're certain that the JS underneath was emitted via tsickle
already.  To do so we check the header that we added to the d.ts emit.
@evmar
Copy link
Contributor Author

evmar commented Oct 2, 2019

I'm gonna sit on this. I think we will need to do something like it eventually, but I fixed the larger clutz issue separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants