Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 44 additions & 46 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4939,63 +4939,61 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}

function emitSerializedTypeNode(node: TypeNode) {
if (!node) {
return;
}

switch (node.kind) {
case SyntaxKind.VoidKeyword:
write("void 0");
return;
if (node) {

case SyntaxKind.ParenthesizedType:
emitSerializedTypeNode((<ParenthesizedTypeNode>node).type);
return;
switch (node.kind) {
case SyntaxKind.VoidKeyword:
write("void 0");
return;

case SyntaxKind.FunctionType:
case SyntaxKind.ConstructorType:
write("Function");
return;
case SyntaxKind.ParenthesizedType:
emitSerializedTypeNode((<ParenthesizedTypeNode>node).type);
return;

case SyntaxKind.ArrayType:
case SyntaxKind.TupleType:
write("Array");
return;
case SyntaxKind.FunctionType:
case SyntaxKind.ConstructorType:
write("Function");
return;

case SyntaxKind.TypePredicate:
case SyntaxKind.BooleanKeyword:
write("Boolean");
return;
case SyntaxKind.ArrayType:
case SyntaxKind.TupleType:
write("Array");
return;

case SyntaxKind.StringKeyword:
case SyntaxKind.StringLiteral:
write("String");
return;
case SyntaxKind.TypePredicate:
case SyntaxKind.BooleanKeyword:
write("Boolean");
return;

case SyntaxKind.NumberKeyword:
write("Number");
return;
case SyntaxKind.StringKeyword:
case SyntaxKind.StringLiteral:
write("String");
return;

case SyntaxKind.SymbolKeyword:
write("Symbol");
return;
case SyntaxKind.NumberKeyword:
write("Number");
return;

case SyntaxKind.TypeReference:
emitSerializedTypeReferenceNode(<TypeReferenceNode>node);
return;
case SyntaxKind.SymbolKeyword:
write("Symbol");
return;

case SyntaxKind.TypeQuery:
case SyntaxKind.TypeLiteral:
case SyntaxKind.UnionType:
case SyntaxKind.IntersectionType:
case SyntaxKind.AnyKeyword:
break;
case SyntaxKind.TypeReference:
emitSerializedTypeReferenceNode(<TypeReferenceNode>node);
return;

default:
Debug.fail("Cannot serialize unexpected type node.");
break;
}
case SyntaxKind.TypeQuery:
case SyntaxKind.TypeLiteral:
case SyntaxKind.UnionType:
case SyntaxKind.IntersectionType:
case SyntaxKind.AnyKeyword:
break;

default:
Debug.fail("Cannot serialize unexpected type node.");
break;
}
}
write("Object");
}

Expand Down
39 changes: 39 additions & 0 deletions tests/baselines/reference/decoratorMetadataOnInferredType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//// [decoratorMetadataOnInferredType.ts]

declare var console: {
log(msg: string): void;
};

class A {
constructor() { console.log('new A'); }
}

function decorator(target: Object, propertyKey: string) {
}

export class B {
@decorator
x = new A();
}


//// [decoratorMetadataOnInferredType.js]
var A = (function () {
function A() {
console.log('new A');
}
return A;
})();
function decorator(target, propertyKey) {
}
var B = (function () {
function B() {
this.x = new A();
}
__decorate([
decorator,
__metadata('design:type', Object)
], B.prototype, "x");
return B;
})();
exports.B = B;
38 changes: 38 additions & 0 deletions tests/baselines/reference/decoratorMetadataOnInferredType.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
=== tests/cases/compiler/decoratorMetadataOnInferredType.ts ===

declare var console: {
>console : Symbol(console, Decl(decoratorMetadataOnInferredType.ts, 1, 11))

log(msg: string): void;
>log : Symbol(log, Decl(decoratorMetadataOnInferredType.ts, 1, 22))
>msg : Symbol(msg, Decl(decoratorMetadataOnInferredType.ts, 2, 8))

};

class A {
>A : Symbol(A, Decl(decoratorMetadataOnInferredType.ts, 3, 2))

constructor() { console.log('new A'); }
>console.log : Symbol(log, Decl(decoratorMetadataOnInferredType.ts, 1, 22))
>console : Symbol(console, Decl(decoratorMetadataOnInferredType.ts, 1, 11))
>log : Symbol(log, Decl(decoratorMetadataOnInferredType.ts, 1, 22))
}

function decorator(target: Object, propertyKey: string) {
>decorator : Symbol(decorator, Decl(decoratorMetadataOnInferredType.ts, 7, 1))
>target : Symbol(target, Decl(decoratorMetadataOnInferredType.ts, 9, 19))
>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11))
>propertyKey : Symbol(propertyKey, Decl(decoratorMetadataOnInferredType.ts, 9, 34))
}

export class B {
>B : Symbol(B, Decl(decoratorMetadataOnInferredType.ts, 10, 1))

@decorator
>decorator : Symbol(decorator, Decl(decoratorMetadataOnInferredType.ts, 7, 1))

x = new A();
>x : Symbol(x, Decl(decoratorMetadataOnInferredType.ts, 12, 16))
>A : Symbol(A, Decl(decoratorMetadataOnInferredType.ts, 3, 2))
}

41 changes: 41 additions & 0 deletions tests/baselines/reference/decoratorMetadataOnInferredType.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
=== tests/cases/compiler/decoratorMetadataOnInferredType.ts ===

declare var console: {
>console : { log(msg: string): void; }

log(msg: string): void;
>log : (msg: string) => void
>msg : string

};

class A {
>A : A

constructor() { console.log('new A'); }
>console.log('new A') : void
>console.log : (msg: string) => void
>console : { log(msg: string): void; }
>log : (msg: string) => void
>'new A' : string
}

function decorator(target: Object, propertyKey: string) {
>decorator : (target: Object, propertyKey: string) => void
>target : Object
>Object : Object
>propertyKey : string
}

export class B {
>B : B

@decorator
>decorator : (target: Object, propertyKey: string) => void

x = new A();
>x : A
>new A() : A
>A : typeof A
}

21 changes: 21 additions & 0 deletions tests/cases/compiler/decoratorMetadataOnInferredType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @noemithelpers: true
// @experimentaldecorators: true
// @emitdecoratormetadata: true
// @target: es5
// @module: commonjs

declare var console: {
log(msg: string): void;
};

class A {
constructor() { console.log('new A'); }
}

function decorator(target: Object, propertyKey: string) {
}

export class B {
@decorator
x = new A();
}