Skip to content

Commit

Permalink
Fix printing of comments around decorators and class properties (#3382)
Browse files Browse the repository at this point in the history
  • Loading branch information
azz committed Dec 3, 2017
1 parent d80728b commit 8524ed5
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ function handleMethodNameComments(text, enclosingNode, precedingNode, comment) {
enclosingNode &&
precedingNode.type === "Decorator" &&
(enclosingNode.type === "ClassMethod" ||
enclosingNode.type === "ClassProperty" ||
enclosingNode.type === "TSAbstractClassProperty" ||
enclosingNode.type === "TSAbstractMethodDefinition" ||
enclosingNode.type === "MethodDefinition")
) {
addTrailingComment(precedingNode, comment);
Expand Down
16 changes: 16 additions & 0 deletions tests/decorator_comments/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`comments.js 1`] = `
class Something {
@Annotateme()
// comment
static property: Array<string>;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class Something {
@Annotateme()
// comment
static property: Array<string>;
}
`;
5 changes: 5 additions & 0 deletions tests/decorator_comments/comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Something {
@Annotateme()
// comment
static property: Array<string>;
}
1 change: 1 addition & 0 deletions tests/decorator_comments/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, ["babylon", "typescript"]);
35 changes: 35 additions & 0 deletions tests/typescript_decorators/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ class Foo4 {
async *method() {}
}
class Something {
@foo()
// comment
readonly property: Array<string>
}
class Something {
@foo()
// comment
abstract property: Array<string>
}
class Something {
@foo()
// comment
abstract method(): Array<string>
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class Foo1 {
@foo
Expand All @@ -105,6 +122,24 @@ class Foo4 {
async *method() {}
}
class Something {
@foo()
// comment
readonly property: Array<string>;
}
class Something {
@foo()
// comment
abstract property: Array<string>;
}
class Something {
@foo()
// comment
abstract method(): Array<string>;
}
`;
exports[`inline-decorators.ts 1`] = `
Expand Down
17 changes: 17 additions & 0 deletions tests/typescript_decorators/decorators-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,20 @@ class Foo4 {
async *method() {}
}

class Something {
@foo()
// comment
readonly property: Array<string>
}

class Something {
@foo()
// comment
abstract property: Array<string>
}

class Something {
@foo()
// comment
abstract method(): Array<string>
}

0 comments on commit 8524ed5

Please sign in to comment.