Skip to content

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

Merged
sheetalkamat merged 4 commits into
masterfrom
metadataReferences
May 4, 2017
Merged

Mark as referenced aliases in Union that will get emitted as part of decorator metadata#13540
sheetalkamat merged 4 commits into
masterfrom
metadataReferences

Conversation

@sheetalkamat
Copy link
Copy Markdown
Member

Fixes #13449

Comment thread src/compiler/checker.ts
if (node) {
switch (node.kind) {
case SyntaxKind.IntersectionType:
case SyntaxKind.UnionType:
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread src/compiler/checker.ts Outdated

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

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

Choose a reason for hiding this comment

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

'getEntityNameForDecoratorMetadata'

Comment thread src/compiler/checker.ts
}
}

function markDecoratorMedataDataTypeNodeAsReferenced(node: TypeNode): void {
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread src/compiler/checker.ts Outdated
for (const typeNode of (<UnionOrIntersectionTypeNode>node).types) {
const individualEntityName = getEntityNameForDecoratoryMetadata(typeNode);
if (!individualEntityName) {
// Individual is something like string number
Copy link
Copy Markdown
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?

Comment thread src/compiler/checker.ts Outdated
case SyntaxKind.UndefinedKeyword:
case SyntaxKind.NullKeyword:
case SyntaxKind.NeverKeyword:
return <voidUndefinedNullOrNeverTypeNode>node;
Copy link
Copy Markdown
Contributor

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.

Comment thread src/compiler/transformers/ts.ts Outdated
}

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

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
Copy Markdown
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.

5 participants