Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Fix exports of local aliases of the form exports.B = exports.A. #912

Merged
merged 1 commit into from
Aug 26, 2019

Conversation

rkirov
Copy link
Contributor

@rkirov rkirov commented Aug 23, 2019

It appears that the emit was previously very broken for this case
(syntactically incorrect). This change fixes the emit by detecting
rewrites that mention exports.Foo and rewrite them to the
corresponding clutz emitted namespace.

Note, that the test .d.ts is still partially incorrect, because we
create a type/let pair for just for a let binding. With #896 this will
be fully correct.

String emitName = Constants.INTERNAL_NAMESPACE + ".";
// If the alias is to a local name, but prefixed with exports.Foo,
// we need to rewrite "exports" because it is no longer correct in TS.
if (alternativeAliasName.startsWith("exports")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exports.
with the trailing dot, so you don't match exportsTheWorld etc.

@rkirov
Copy link
Contributor Author

rkirov commented Aug 23, 2019

On a second thought, a better fix would be to simply not add exports.Foo to the alias map, because closure should resolve those locally. Will try that tomorrow.

@rkirov rkirov force-pushed the export_error branch 2 times, most recently from f09cbef to c6c511b Compare August 26, 2019 19:33
@rkirov
Copy link
Contributor Author

rkirov commented Aug 26, 2019

Rewrote this to a much simpler fix. Instead of emitting a self-import, just skip the syntactic alias rewriting step. Turns out the JS compiler output is adequate we were just clobber it previously. PTAL.

It appears that the emit was previously very broken for this case
(syntactically incorrect). This change simply skips the alias rewriting
when "... = exports...." pattern is detected syntactically. For the rest
we still assume the syntactic rewriter is desirable, like the case
`exports.A = externalModule.Foo`.
@rkirov rkirov merged commit 733982c into angular:master Aug 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants