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

Mark as referenced aliases in Union that will get emitted as part of decorator metadata #13540

Merged
merged 4 commits into from
May 4, 2017

Conversation

sheetalkamat
Copy link
Member

Fixes #13449

if (node) {
switch (node.kind) {
case SyntaxKind.IntersectionType:
case SyntaxKind.UnionType:
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we allow unions and intersections any ways. we do not serialize them correctly anyways.

Copy link
Member Author

Choose a reason for hiding this comment

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

we allow this if the Individual type leads to same identifier. This is to make sure string | null will emit type as string.. E | null results in E and "foo" | "bar" results in string as type

Copy link
Member Author

@sheetalkamat sheetalkamat Jan 23, 2017

Choose a reason for hiding this comment

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

#13034 added support for E | null to emit it as type in metadata as E


type voidUndefinedNullOrNeverTypeNode = Token<SyntaxKind.VoidKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.NullKeyword | SyntaxKind.NeverKeyword>;

function getEntityNameForDecoratoryMetadata(node: TypeNode): EntityName | voidUndefinedNullOrNeverTypeNode {
Copy link
Contributor

Choose a reason for hiding this comment

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

'getEntityNameForDecoratorMetadata'

@@ -16743,6 +16746,65 @@ namespace ts {
}
}

function markDecoratorMedataDataTypeNodeAsReferenced(node: TypeNode): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for consistency markDecoratorMedataDataTypeNodeAsReferenced should be markDecoratorMedataDataTypeNodeAsReference

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add comment on why we need this separate from using markTypeNodeAsReferenced

for (const typeNode of (<UnionOrIntersectionTypeNode>node).types) {
const individualEntityName = getEntityNameForDecoratoryMetadata(typeNode);
if (!individualEntityName) {
// Individual is something like string number
Copy link
Contributor

@yuit yuit Jan 25, 2017

Choose a reason for hiding this comment

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

is this mean that if each constituent of intersection or union type is a string or number, then return undefined?
Can you note where it will get seriazlied?

case SyntaxKind.UndefinedKeyword:
case SyntaxKind.NullKeyword:
case SyntaxKind.NeverKeyword:
return <voidUndefinedNullOrNeverTypeNode>node;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we return the token here? This function is only used by markDecoratorMedataDataTypeNodeAsReferenced, which in turn only cares if its an EntityName.

@@ -1739,6 +1739,8 @@ namespace ts {
}

function serializeUnionOrIntersectionType(node: UnionOrIntersectionTypeNode): SerializedTypeNode {
// Note when updating logic here also update getEntityNameForDecoratoryMetadata
Copy link
Member

Choose a reason for hiding this comment

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

getEntityNameForDecoratorMetadata

OneType|null is again treated as object instead of simplifying it
@sheetalkamat
Copy link
Member Author

Merging this as per @mhegazy 's offline approval.

@sheetalkamat sheetalkamat merged commit 96aca4c into master May 4, 2017
@sheetalkamat sheetalkamat deleted the metadataReferences branch May 4, 2017 22:04
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
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.

None yet

5 participants