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
24 changes: 13 additions & 11 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,19 +694,21 @@ namespace ts {

// let ${name} = ${classExpression} where name is either declaredName if the class doesn't contain self-reference
// or decoratedClassAlias if the class contain self-reference.
const transformedClassExpression = createVariableStatement(
/*modifiers*/ undefined,
createLetDeclarationList([
createVariableDeclaration(
classAlias || declaredName,
/*type*/ undefined,
classExpression
)
]),
/*location*/ location
);
setCommentRange(transformedClassExpression, node);
statements.push(
setOriginalNode(
createVariableStatement(
/*modifiers*/ undefined,
createLetDeclarationList([
createVariableDeclaration(
classAlias || declaredName,
/*type*/ undefined,
classExpression
)
]),
/*location*/ location
),
/*node*/ transformedClassExpression,
/*original*/ node
)
);
Expand Down
47 changes: 47 additions & 0 deletions tests/baselines/reference/commentOnDecoratedClassDeclaration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//// [commentOnDecoratedClassDeclaration.ts]
declare function decorator(x: string): any;

/**
* Leading trivia
*/
@decorator("hello")
class Remote { }

/**
* Floating Comment
*/

@decorator("hi")
class AnotherRomote {
constructor() {}
}

//// [commentOnDecoratedClassDeclaration.js]
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;
};
/**
* Leading trivia
*/
var Remote = (function () {
function Remote() {
}
return Remote;
}());
Remote = __decorate([
decorator("hello")
], Remote);
/**
* Floating Comment
*/
var AnotherRomote = (function () {
function AnotherRomote() {
}
return AnotherRomote;
}());
AnotherRomote = __decorate([
decorator("hi")
], AnotherRomote);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=== tests/cases/compiler/commentOnDecoratedClassDeclaration.ts ===
declare function decorator(x: string): any;
>decorator : Symbol(decorator, Decl(commentOnDecoratedClassDeclaration.ts, 0, 0))
>x : Symbol(x, Decl(commentOnDecoratedClassDeclaration.ts, 0, 27))

/**
* Leading trivia
*/
@decorator("hello")
>decorator : Symbol(decorator, Decl(commentOnDecoratedClassDeclaration.ts, 0, 0))

class Remote { }
>Remote : Symbol(Remote, Decl(commentOnDecoratedClassDeclaration.ts, 0, 43))

/**
* Floating Comment
*/

@decorator("hi")
>decorator : Symbol(decorator, Decl(commentOnDecoratedClassDeclaration.ts, 0, 0))

class AnotherRomote {
>AnotherRomote : Symbol(AnotherRomote, Decl(commentOnDecoratedClassDeclaration.ts, 6, 16))

constructor() {}
}
30 changes: 30 additions & 0 deletions tests/baselines/reference/commentOnDecoratedClassDeclaration.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
=== tests/cases/compiler/commentOnDecoratedClassDeclaration.ts ===
declare function decorator(x: string): any;
>decorator : (x: string) => any
>x : string

/**
* Leading trivia
*/
@decorator("hello")
>decorator("hello") : any
>decorator : (x: string) => any
>"hello" : string

class Remote { }
>Remote : Remote

/**
* Floating Comment
*/

@decorator("hi")
>decorator("hi") : any
>decorator : (x: string) => any
>"hi" : string

class AnotherRomote {
>AnotherRomote : AnotherRomote

constructor() {}
}
17 changes: 17 additions & 0 deletions tests/cases/compiler/commentOnDecoratedClassDeclaration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @experimentalDecorators: true
declare function decorator(x: string): any;

/**
* Leading trivia
*/
@decorator("hello")
class Remote { }

/**
* Floating Comment
*/

@decorator("hi")
class AnotherRomote {
constructor() {}
}