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

Use brand types to clear up confusion about entity name expressions #10013

Merged
9 commits merged into from
Aug 11, 2016

Conversation

ghost
Copy link

@ghost ghost commented Jul 28, 2016

Fixes #4325.
This introduces the type EntityNameExpression to replace Expression used in a context where it must be an entity name (an identifier, or a property access where the LHS is an entity name).
This also helped to discover a bug where we treated exported property accesses as entity names even if the LHS wasn't propery.

@ghost ghost assigned sandersn Jul 28, 2016
@ghost ghost force-pushed the resolve_entity_name branch from e6ca44e to f763280 Compare July 28, 2016 20:09
@@ -4947,15 +4959,14 @@ namespace ts {
const typeReferenceName = getTypeReferenceName(node);
symbol = resolveTypeReferenceName(node, typeReferenceName);
type = getTypeReferenceType(node, symbol);

links.resolvedSymbol = symbol;
links.resolvedType = type;
Copy link
Author

Choose a reason for hiding this comment

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

There were duplicate lines just below these.

@ghost ghost force-pushed the resolve_entity_name branch from 9ed6146 to f9fd496 Compare July 29, 2016 15:12
node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(<ExportAssignment>node);
}

export function exportAssignmentIsAlias(node: ExportAssignment): boolean {
Copy link
Member

@sandersn sandersn Aug 2, 2016

Choose a reason for hiding this comment

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

exportAssignmentIsAlias [](start = 20, length = 23)

it seems weird that there are 3 functions whose bodies are all just isEntityNameExpression(node.expression). If you express them as a single function, does any common name look at all good? #Closed

…he expression of each `ExpressionWithTypeArguments` is an `EntityNameExpression`.
* Climbs up parents to an ExpressionWithTypeArguments, and returns its expression,
* but returns undefined if that expression is not an EntityNameExpression.
*/
function climbToEntityNameOfExpressionWithTypeArguments(node: Node): EntityNameExpression | undefined {
Copy link
Member

@sandersn sandersn Aug 2, 2016

Choose a reason for hiding this comment

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

climbToEntityNameOfExpressionWithTypeArguments [](start = 17, length = 46)

getEntityNameParent[OfExpressionWithTypeArguments]? (get...Parent is the usual pattern used rather than climbTo...)

Copy link
Author

Choose a reason for hiding this comment

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

This one would also be simpler with recursion.

Copy link
Author

Choose a reason for hiding this comment

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

We're getting the child of an ancestor (e.g. an aunt) which is an ExpressionWithTypeArguments. So it's more like getExpressionOfExpressionWithTypeArgumentsParent...

Copy link
Member

Choose a reason for hiding this comment

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

good point, I missed that. Maybe move the .expression access to the caller? This is more like how it works with the rest of your new code post-commit 4 anyway.


In reply to: 73203379 [](ancestors = 73203379)

Copy link
Author

Choose a reason for hiding this comment

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

Don't want to move .expression to the caller because climbToEntityNameOfExpressionWithTypeArguments is responsible for ensuring that .expression is a EntityNameExpression. Maybe it could just be named getEntityNameForExtendingInterface?

@sandersn
Copy link
Member

sandersn commented Aug 2, 2016

👍 once @vladima takes a look at the possible recursions, and once you decide whether to change the name for climbToEntity...

* but returns undefined if that expression is not an EntityNameExpression.
*/
function climbToEntityNameOfExpressionWithTypeArguments(node: Node): EntityNameExpression | undefined {
for (; ; ) {
Copy link
Member

Choose a reason for hiding this comment

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

Why? Use while (true)

@ghost ghost merged commit e900952 into master Aug 11, 2016
@ghost ghost deleted the resolve_entity_name branch August 11, 2016 16:59
@mhegazy
Copy link
Contributor

mhegazy commented Aug 17, 2016

I do not think this is not going to work for things that do not share the same symbol.. e.g.

class C {
    static B: number;
}
namespace C {
    export interface B { c: number }
}

export = C.B;

@ghost ghost mentioned this pull request Aug 18, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants