Elide import namespace from which only const enums are used#20320
Conversation
|
|
||
| function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) { | ||
| let propType: Type; | ||
| let leftSymbol = getNodeLinks(left) && getNodeLinks(left).resolvedSymbol; |
There was a problem hiding this comment.
this is defined in the block below already.
| function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) { | ||
| let propType: Type; | ||
| let leftSymbol = getNodeLinks(left) && getNodeLinks(left).resolvedSymbol; | ||
| const leftWasReferenced = leftSymbol && getSymbolLinks(leftSymbol).referenced; |
There was a problem hiding this comment.
seems to be only used in the else block as well.
There was a problem hiding this comment.
ah nevermind.. i understand now :)
|
This is causing some unexpected emit changes in RWC. Specifically, a pattern like this: namespace X {
import Internal = Y.Z.Internal;
class C {
private x: Internal.D;
constructor() {
this.x = new Internal.D();
}
}
}where At least I think this is unexpected. Am I correct? |
|
@sandersn What's the issue? Is the |
|
Yes, the import is elided. I’ll anonymize a sample when I get to my computer, but I recall it was just an exported class inside a namespace. |
namespace Microsoft.Y.Z {
// ...
export namespace Internal {
// ...
export class D ...and the structure of the user is /// <reference "y.z.ts" />
namespace Microsoft.Software.Thing.Internal {
// ...
namespace X {
import Internal = Y.Z.Internal // This line is no longer emitted
class C {
private x: Internal.D;
constructor() {
this.x = new Internal.D();
}
}
}
} |
Fixes #18644
This was a bit more involved than expected. For one, we needed to not mark the namespace alias as referenced (as discussed in the issue), but only after we've verified that we're only accessing a const enum from it. For two, it turns out we actually didn't handle the visibility of
export import ... =aliases correctly -once
Z.vin a type position no longer markedZas referenced via point one, we hadn't considered that since it is exported it still needed to be considered referenced if they are values.