mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Merge pull request #13584 from Microsoft/decoratorMetadata
Use the value symbol for decorator purpose only if it is same as type symbol
This commit is contained in:
commit
a185ddc885
@ -20517,18 +20517,21 @@ namespace ts {
|
||||
function getTypeReferenceSerializationKind(typeName: EntityName, location?: Node): TypeReferenceSerializationKind {
|
||||
// Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
|
||||
const valueSymbol = resolveEntityName(typeName, SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
|
||||
const globalPromiseSymbol = tryGetGlobalPromiseConstructorSymbol();
|
||||
if (globalPromiseSymbol && valueSymbol === globalPromiseSymbol) {
|
||||
return TypeReferenceSerializationKind.Promise;
|
||||
}
|
||||
|
||||
const constructorType = valueSymbol ? getTypeOfSymbol(valueSymbol) : undefined;
|
||||
if (constructorType && isConstructorType(constructorType)) {
|
||||
return TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
|
||||
}
|
||||
|
||||
// Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
|
||||
const typeSymbol = resolveEntityName(typeName, SymbolFlags.Type, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
|
||||
if (valueSymbol && valueSymbol === typeSymbol) {
|
||||
const globalPromiseSymbol = tryGetGlobalPromiseConstructorSymbol();
|
||||
if (globalPromiseSymbol && valueSymbol === globalPromiseSymbol) {
|
||||
return TypeReferenceSerializationKind.Promise;
|
||||
}
|
||||
|
||||
const constructorType = getTypeOfSymbol(valueSymbol);
|
||||
if (constructorType && isConstructorType(constructorType)) {
|
||||
return TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
|
||||
}
|
||||
}
|
||||
|
||||
// We might not be able to resolve type symbol so use unknown type in that case (eg error case)
|
||||
if (!typeSymbol) {
|
||||
return TypeReferenceSerializationKind.ObjectType;
|
||||
|
||||
38
tests/baselines/reference/metadataOfEventAlias.js
Normal file
38
tests/baselines/reference/metadataOfEventAlias.js
Normal file
@ -0,0 +1,38 @@
|
||||
//// [tests/cases/compiler/metadataOfEventAlias.ts] ////
|
||||
|
||||
//// [event.ts]
|
||||
|
||||
export interface Event { title: string };
|
||||
|
||||
//// [test.ts]
|
||||
import { Event } from './event';
|
||||
function Input(target: any, key: string): void { }
|
||||
export class SomeClass {
|
||||
@Input event: Event;
|
||||
}
|
||||
|
||||
//// [event.js]
|
||||
"use strict";
|
||||
;
|
||||
//// [test.js]
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
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;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
function Input(target, key) { }
|
||||
var SomeClass = (function () {
|
||||
function SomeClass() {
|
||||
}
|
||||
return SomeClass;
|
||||
}());
|
||||
__decorate([
|
||||
Input,
|
||||
__metadata("design:type", Object)
|
||||
], SomeClass.prototype, "event", void 0);
|
||||
exports.SomeClass = SomeClass;
|
||||
23
tests/baselines/reference/metadataOfEventAlias.symbols
Normal file
23
tests/baselines/reference/metadataOfEventAlias.symbols
Normal file
@ -0,0 +1,23 @@
|
||||
=== tests/cases/compiler/event.ts ===
|
||||
|
||||
export interface Event { title: string };
|
||||
>Event : Symbol(Event, Decl(event.ts, 0, 0))
|
||||
>title : Symbol(Event.title, Decl(event.ts, 1, 24))
|
||||
|
||||
=== tests/cases/compiler/test.ts ===
|
||||
import { Event } from './event';
|
||||
>Event : Symbol(Event, Decl(test.ts, 0, 8))
|
||||
|
||||
function Input(target: any, key: string): void { }
|
||||
>Input : Symbol(Input, Decl(test.ts, 0, 32))
|
||||
>target : Symbol(target, Decl(test.ts, 1, 15))
|
||||
>key : Symbol(key, Decl(test.ts, 1, 27))
|
||||
|
||||
export class SomeClass {
|
||||
>SomeClass : Symbol(SomeClass, Decl(test.ts, 1, 50))
|
||||
|
||||
@Input event: Event;
|
||||
>Input : Symbol(Input, Decl(test.ts, 0, 32))
|
||||
>event : Symbol(SomeClass.event, Decl(test.ts, 2, 24))
|
||||
>Event : Symbol(Event, Decl(test.ts, 0, 8))
|
||||
}
|
||||
23
tests/baselines/reference/metadataOfEventAlias.types
Normal file
23
tests/baselines/reference/metadataOfEventAlias.types
Normal file
@ -0,0 +1,23 @@
|
||||
=== tests/cases/compiler/event.ts ===
|
||||
|
||||
export interface Event { title: string };
|
||||
>Event : Event
|
||||
>title : string
|
||||
|
||||
=== tests/cases/compiler/test.ts ===
|
||||
import { Event } from './event';
|
||||
>Event : any
|
||||
|
||||
function Input(target: any, key: string): void { }
|
||||
>Input : (target: any, key: string) => void
|
||||
>target : any
|
||||
>key : string
|
||||
|
||||
export class SomeClass {
|
||||
>SomeClass : SomeClass
|
||||
|
||||
@Input event: Event;
|
||||
>Input : (target: any, key: string) => void
|
||||
>event : Event
|
||||
>Event : Event
|
||||
}
|
||||
14
tests/cases/compiler/metadataOfEventAlias.ts
Normal file
14
tests/cases/compiler/metadataOfEventAlias.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// @experimentalDecorators: true
|
||||
// @emitDecoratorMetadata: true
|
||||
// @target: es5
|
||||
// @includeBuiltFile: lib.d.ts
|
||||
|
||||
// @filename: event.ts
|
||||
export interface Event { title: string };
|
||||
|
||||
// @filename: test.ts
|
||||
import { Event } from './event';
|
||||
function Input(target: any, key: string): void { }
|
||||
export class SomeClass {
|
||||
@Input event: Event;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user