Skip to content

Commit 7785e84

Browse files
Merge pull request microsoft#6193 from Microsoft/fixUpFromPRs-2015-12-21
Nit fix ups for PRs
2 parents ee50adb + b262c04 commit 7785e84

5 files changed

Lines changed: 101 additions & 15 deletions

File tree

src/compiler/emitter.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4280,25 +4280,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
42804280

42814281
// TODO (yuisu) : we should not have special cases to condition emitting comments
42824282
// but have one place to fix check for these conditions.
4283-
if (node.kind !== SyntaxKind.MethodDeclaration &&
4284-
node.kind !== SyntaxKind.MethodSignature &&
4285-
node.parent &&
4286-
node.parent.kind !== SyntaxKind.PropertyAssignment &&
4287-
node.parent.kind !== SyntaxKind.CallExpression &&
4288-
node.parent.kind !== SyntaxKind.ArrayLiteralExpression) {
4289-
// 1. Methods will emit the comments as part of emitting method declaration
4290-
4283+
const { kind, parent } = node;
4284+
if (kind !== SyntaxKind.MethodDeclaration &&
4285+
kind !== SyntaxKind.MethodSignature &&
4286+
parent &&
4287+
parent.kind !== SyntaxKind.PropertyAssignment &&
4288+
parent.kind !== SyntaxKind.CallExpression &&
4289+
parent.kind !== SyntaxKind.ArrayLiteralExpression) {
4290+
// 1. Methods will emit comments at their assignment declaration sites.
4291+
//
42914292
// 2. If the function is a property of object literal, emitting leading-comments
4292-
// is done by emitNodeWithoutSourceMap which then call this function.
4293-
// In particular, we would like to avoid emit comments twice in following case:
4294-
// For example:
4293+
// is done by emitNodeWithoutSourceMap which then call this function.
4294+
// In particular, we would like to avoid emit comments twice in following case:
4295+
//
42954296
// var obj = {
42964297
// id:
42974298
// /*comment*/ () => void
42984299
// }
4299-
4300+
//
43004301
// 3. If the function is an argument in call expression, emitting of comments will be
4301-
// taken care of in emit list of arguments inside of emitCallexpression
4302+
// taken care of in emit list of arguments inside of 'emitCallExpression'.
4303+
//
4304+
// 4. If the function is in an array literal, 'emitLinePreservingList' will take care
4305+
// of leading comments.
43024306
emitLeadingComments(node);
43034307
}
43044308

@@ -4325,12 +4329,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
43254329
}
43264330

43274331
emitSignatureAndBody(node);
4328-
if (modulekind !== ModuleKind.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile && node.name) {
4332+
if (modulekind !== ModuleKind.ES6 && kind === SyntaxKind.FunctionDeclaration && parent === currentSourceFile && node.name) {
43294333
emitExportMemberAssignments((<FunctionDeclaration>node).name);
43304334
}
43314335

43324336
emitEnd(node);
4333-
if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) {
4337+
if (kind !== SyntaxKind.MethodDeclaration && kind !== SyntaxKind.MethodSignature) {
43344338
emitTrailingComments(node);
43354339
}
43364340
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [decoratorOnClassMethodOverload2.ts]
2+
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
3+
4+
class C {
5+
method()
6+
@dec
7+
method() { }
8+
}
9+
10+
//// [decoratorOnClassMethodOverload2.js]
11+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
12+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
14+
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;
15+
return c > 3 && r && Object.defineProperty(target, key, r), r;
16+
};
17+
var C = (function () {
18+
function C() {
19+
}
20+
C.prototype.method = function () { };
21+
__decorate([
22+
dec
23+
], C.prototype, "method", null);
24+
return C;
25+
}());
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload2.ts ===
2+
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
3+
>dec : Symbol(dec, Decl(decoratorOnClassMethodOverload2.ts, 0, 0))
4+
>T : Symbol(T, Decl(decoratorOnClassMethodOverload2.ts, 0, 21))
5+
>target : Symbol(target, Decl(decoratorOnClassMethodOverload2.ts, 0, 24))
6+
>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethodOverload2.ts, 0, 36))
7+
>descriptor : Symbol(descriptor, Decl(decoratorOnClassMethodOverload2.ts, 0, 57))
8+
>TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, --, --))
9+
>T : Symbol(T, Decl(decoratorOnClassMethodOverload2.ts, 0, 21))
10+
>TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, --, --))
11+
>T : Symbol(T, Decl(decoratorOnClassMethodOverload2.ts, 0, 21))
12+
13+
class C {
14+
>C : Symbol(C, Decl(decoratorOnClassMethodOverload2.ts, 0, 126))
15+
16+
method()
17+
>method : Symbol(method, Decl(decoratorOnClassMethodOverload2.ts, 2, 9), Decl(decoratorOnClassMethodOverload2.ts, 3, 12))
18+
19+
@dec
20+
>dec : Symbol(dec, Decl(decoratorOnClassMethodOverload2.ts, 0, 0))
21+
22+
method() { }
23+
>method : Symbol(method, Decl(decoratorOnClassMethodOverload2.ts, 2, 9), Decl(decoratorOnClassMethodOverload2.ts, 3, 12))
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload2.ts ===
2+
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
3+
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
4+
>T : T
5+
>target : any
6+
>propertyKey : string
7+
>descriptor : TypedPropertyDescriptor<T>
8+
>TypedPropertyDescriptor : TypedPropertyDescriptor<T>
9+
>T : T
10+
>TypedPropertyDescriptor : TypedPropertyDescriptor<T>
11+
>T : T
12+
13+
class C {
14+
>C : C
15+
16+
method()
17+
>method : () => any
18+
19+
@dec
20+
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
21+
22+
method() { }
23+
>method : () => any
24+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @target: ES5
2+
// @experimentaldecorators: true
3+
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
4+
5+
class C {
6+
method()
7+
@dec
8+
method() { }
9+
}

0 commit comments

Comments
 (0)