Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a185ddc

Browse filesBrowse files
authored
Merge pull request microsoft#13584 from Microsoft/decoratorMetadata
Use the value symbol for decorator purpose only if it is same as type symbol
2 parents c2f5ac4 + 679a7ec commit a185ddc
Copy full SHA for a185ddc

5 files changed

+110-9Lines changed: 110 additions & 9 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+12-9Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20517,18 +20517,21 @@ namespace ts {
2051720517
function getTypeReferenceSerializationKind(typeName: EntityName, location?: Node): TypeReferenceSerializationKind {
2051820518
// Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
2051920519
const valueSymbol = resolveEntityName(typeName, SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
20520-
const globalPromiseSymbol = tryGetGlobalPromiseConstructorSymbol();
20521-
if (globalPromiseSymbol && valueSymbol === globalPromiseSymbol) {
20522-
return TypeReferenceSerializationKind.Promise;
20523-
}
20524-
20525-
const constructorType = valueSymbol ? getTypeOfSymbol(valueSymbol) : undefined;
20526-
if (constructorType && isConstructorType(constructorType)) {
20527-
return TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
20528-
}
2052920520

2053020521
// Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
2053120522
const typeSymbol = resolveEntityName(typeName, SymbolFlags.Type, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
20523+
if (valueSymbol && valueSymbol === typeSymbol) {
20524+
const globalPromiseSymbol = tryGetGlobalPromiseConstructorSymbol();
20525+
if (globalPromiseSymbol && valueSymbol === globalPromiseSymbol) {
20526+
return TypeReferenceSerializationKind.Promise;
20527+
}
20528+
20529+
const constructorType = getTypeOfSymbol(valueSymbol);
20530+
if (constructorType && isConstructorType(constructorType)) {
20531+
return TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
20532+
}
20533+
}
20534+
2053220535
// We might not be able to resolve type symbol so use unknown type in that case (eg error case)
2053320536
if (!typeSymbol) {
2053420537
return TypeReferenceSerializationKind.ObjectType;
Collapse file
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// [tests/cases/compiler/metadataOfEventAlias.ts] ////
2+
3+
//// [event.ts]
4+
5+
export interface Event { title: string };
6+
7+
//// [test.ts]
8+
import { Event } from './event';
9+
function Input(target: any, key: string): void { }
10+
export class SomeClass {
11+
@Input event: Event;
12+
}
13+
14+
//// [event.js]
15+
"use strict";
16+
;
17+
//// [test.js]
18+
"use strict";
19+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
20+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
21+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
22+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
23+
return c > 3 && r && Object.defineProperty(target, key, r), r;
24+
};
25+
var __metadata = (this && this.__metadata) || function (k, v) {
26+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
27+
};
28+
function Input(target, key) { }
29+
var SomeClass = (function () {
30+
function SomeClass() {
31+
}
32+
return SomeClass;
33+
}());
34+
__decorate([
35+
Input,
36+
__metadata("design:type", Object)
37+
], SomeClass.prototype, "event", void 0);
38+
exports.SomeClass = SomeClass;
Collapse file
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/compiler/event.ts ===
2+
3+
export interface Event { title: string };
4+
>Event : Symbol(Event, Decl(event.ts, 0, 0))
5+
>title : Symbol(Event.title, Decl(event.ts, 1, 24))
6+
7+
=== tests/cases/compiler/test.ts ===
8+
import { Event } from './event';
9+
>Event : Symbol(Event, Decl(test.ts, 0, 8))
10+
11+
function Input(target: any, key: string): void { }
12+
>Input : Symbol(Input, Decl(test.ts, 0, 32))
13+
>target : Symbol(target, Decl(test.ts, 1, 15))
14+
>key : Symbol(key, Decl(test.ts, 1, 27))
15+
16+
export class SomeClass {
17+
>SomeClass : Symbol(SomeClass, Decl(test.ts, 1, 50))
18+
19+
@Input event: Event;
20+
>Input : Symbol(Input, Decl(test.ts, 0, 32))
21+
>event : Symbol(SomeClass.event, Decl(test.ts, 2, 24))
22+
>Event : Symbol(Event, Decl(test.ts, 0, 8))
23+
}
Collapse file
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/compiler/event.ts ===
2+
3+
export interface Event { title: string };
4+
>Event : Event
5+
>title : string
6+
7+
=== tests/cases/compiler/test.ts ===
8+
import { Event } from './event';
9+
>Event : any
10+
11+
function Input(target: any, key: string): void { }
12+
>Input : (target: any, key: string) => void
13+
>target : any
14+
>key : string
15+
16+
export class SomeClass {
17+
>SomeClass : SomeClass
18+
19+
@Input event: Event;
20+
>Input : (target: any, key: string) => void
21+
>event : Event
22+
>Event : Event
23+
}
Collapse file
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @experimentalDecorators: true
2+
// @emitDecoratorMetadata: true
3+
// @target: es5
4+
// @includeBuiltFile: lib.d.ts
5+
6+
// @filename: event.ts
7+
export interface Event { title: string };
8+
9+
// @filename: test.ts
10+
import { Event } from './event';
11+
function Input(target: any, key: string): void { }
12+
export class SomeClass {
13+
@Input event: Event;
14+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.